Skip to content

Commit 5ceeb7f

Browse files
committed
Add the new snippet injector in grunt task
1 parent a66636f commit 5ceeb7f

File tree

5 files changed

+82
-42
lines changed

5 files changed

+82
-42
lines changed
File renamed without changes.

apps/tests/console-tests.ts

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,43 @@
11
export var test_DummyTestForSnippetOnly0 = function () {
2-
// <snippet module="console" title="console">
3-
// # Console
4-
// ### Logging
5-
// Logging to the console does not require the "console" module since the console variable is global. It can be used anywhere within your code.
6-
// You can log your message in several different categories.
7-
// ``` JavaScript
8-
//// Verbously logs a message.
2+
// >> console-log
93
console.log("Hello, world!");
104
console.info("I am NativeScript");
115
console.warn("Low memory");
126
console.error("Uncaught Application Exception");
13-
// ```
14-
// </snippet>
7+
// << console-log
158
}
169

1710
export var test_DummyTestForSnippetOnly1 = function () {
18-
// <snippet module="console" title="console">
19-
// ### Time
20-
// ``` JavaScript
21-
//// Begins counting a time span for a given name (key).
11+
// >> console-time
2212
console.time("LoadTime");
23-
//// Do something...
24-
//// Ends a previously started time span through the time method.
13+
// << console-time
14+
// >> console-timeEnd
2515
console.timeEnd("LoadTime");
26-
// ```
27-
// </snippet>
16+
// << console-timeEnd
2817
}
2918

3019
export var test_DummyTestForSnippetOnly2 = function () {
31-
// <snippet module="console" title="console">
32-
// ### Assert
33-
// ``` JavaScript
34-
//// Asserts a boolean condition and prints a message in case the assert fails.
20+
// >> console-assert
3521
console.assert(2 === 2, "2 equals 2");
36-
// ```
37-
// </snippet>
22+
// << console-assert
3823
}
3924

4025
export var test_DummyTestForSnippetOnly3 = function () {
41-
// <snippet module="console" title="console">
42-
// ### Dir
43-
// ``` JavaScript
44-
//// Prints the state of the specified object to the console.
26+
// >> console-dir
4527
var obj = {name: "John", age: 34};
4628
console.dir(obj);
47-
// ```
48-
// </snippet>
29+
// << console-dir
4930
}
5031

5132
export var test_DummyTestForSnippetOnly4 = function () {
52-
// <snippet module="console" title="console">
53-
// ### Dump
54-
// ``` JavaScript
55-
//// Prints the state of the specified object to the console.
33+
// >> console-dump
5634
var obj = { name: "John", age: 34 };
5735
console.dump(obj);
58-
// ```
59-
// </snippet>
36+
// << console-dump
6037
}
6138

6239
export var test_DummyTestForSnippetOnly5 = function () {
63-
// <snippet module="console" title="console">
64-
// ### Trace
65-
// ``` JavaScript
66-
//// Prints the current stack trace in the console.
40+
// >> console-trace
6741
console.trace();
68-
// ```
69-
// </snippet>
42+
// << console-traceß
7043
}

apps/tests/console.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
nav-title: "console How-To"
3+
title: "How-To"
4+
description: "Examples for using console"
5+
---
6+
# Console
7+
### Logging
8+
Logging to the console does not require the "console" module since the console variable is global. It can be used anywhere within your code.
9+
You can log your message in several different categories.
10+
<snippet id='console-log'/>
11+
12+
### Time
13+
Begins counting a time span for a given name (key).
14+
<snippet id='console-time'/>
15+
16+
Ends a previously started time span through the time method.
17+
<snippet id='console-timeEnd'/>
18+
19+
### Assert
20+
Asserts a boolean condition and prints a message in case the assert fails.
21+
<snippet id='console-assert'/>
22+
23+
### Dir
24+
Prints the state of the specified object to the console.
25+
<snippet id='console-dir'/>
26+
27+
### Dump
28+
Prints the state of the specified object to the console.
29+
<snippet id='console-dump'/>
30+
31+
### Trace
32+
Prints the current stack trace in the console.
33+
<snippet id='console-trace'/>

gruntfile.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,14 @@ module.exports = function(grunt) {
139139
var localCfg = {
140140
srcDir: ".",
141141
srcAppsDir: "./apps",
142+
srcAppsTests: "./apps/tests",
142143
packageJsonFilePath: "./package.json",
143144
outDir: "./bin/dist",
145+
outArticlesDir: "./bin/dist/articles",
144146
outModulesDir: tsconfig.compilerOptions.outDir || "./bin/dist/modules",
145147
outAppsDir: "./bin/dist/apps",
146148
outTsAppsDir: "./bin/dist/ts-apps",
147-
outApiRefDir: "./bin/dist/api-ref"
149+
outApiRefDir: "./bin/dist/apiref"
148150
};
149151

150152
var nodeTestEnv = JSON.parse(JSON.stringify(process.env));
@@ -214,6 +216,12 @@ module.exports = function(grunt) {
214216
},
215217
readyAppFiles: {
216218
src: [localCfg.outModulesDir + "/apps/**"]
219+
},
220+
articles: {
221+
src: [ localCfg.outArticlesDir ]
222+
},
223+
"apiref": {
224+
src: [ localCfg.outApiRefDir ]
217225
}
218226
},
219227
copy: {
@@ -228,6 +236,12 @@ module.exports = function(grunt) {
228236
dest: localCfg.outModulesDir,
229237
cwd: localCfg.srcDir
230238
},
239+
articleMDs: {
240+
expand: true,
241+
src: [ "**/*.md" ],
242+
dest: localCfg.outArticlesDir,
243+
cwd: localCfg.srcAppsTests
244+
},
231245
license: {
232246
expand: true,
233247
src: [
@@ -413,6 +427,9 @@ module.exports = function(grunt) {
413427
},
414428
mochaNode: {
415429
cmd: "grunt simplemocha:node"
430+
},
431+
injectArticles: {
432+
cmd: "./node_modules/.bin/mdinject --root=<%= localCfg.srcAppsTests %> --docsroot=<%= localCfg.outArticlesDir %>"
416433
}
417434
},
418435
multidest: {
@@ -707,4 +724,20 @@ module.exports = function(grunt) {
707724
"ts:build-inplace",
708725
"generate-tns-core-modules-dev-dts"
709726
]);
727+
728+
grunt.registerTask("apiref", [
729+
"clean:apiref",
730+
"typedoc:build"
731+
]);
732+
733+
grunt.registerTask("articles", [
734+
"clean:articles",
735+
"copy:articleMDs",
736+
"exec:injectArticles"
737+
]);
738+
739+
grunt.registerTask("docs", [
740+
"apiref",
741+
"articles"
742+
]);
710743
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"grunt-ts": "5.3.2",
3737
"grunt-typedoc": "0.2.3",
3838
"grunt-untar": "0.0.1",
39+
"markdown-snippet-injector": "^0.1.1",
3940
"mocha": "2.2.5",
4041
"shelljs": "0.5.3",
4142
"grunt-tslint": "3.0.3",

0 commit comments

Comments
 (0)