[Service] Integrate DeviceHome and SignalingServer
[platform/framework/web/wrtjs.git] / device_home / node_modules / jake / jakefile.js
1 let fs = require('fs')
2 let path = require('path');
3 let proc = require('child_process');
4
5 const PROJECT_DIR = process.cwd();
6 process.env.PROJECT_DIR = PROJECT_DIR;
7
8 namespace('doc', function () {
9   task('generate', ['doc:clobber'], function () {
10     var cmd = '../node-jsdoc-toolkit/app/run.js -n -r=100 ' +
11         '-t=../node-jsdoc-toolkit/templates/codeview -d=./doc/ ./lib';
12     jake.logger.log('Generating docs ...');
13     jake.exec([cmd], function () {
14       jake.logger.log('Done.');
15       complete();
16     });
17   }, {async: true});
18
19   task('clobber', function () {
20     var cmd = 'rm -fr ./doc/*';
21     jake.exec([cmd], function () {
22       jake.logger.log('Clobbered old docs.');
23       complete();
24     });
25   }, {async: true});
26
27 });
28
29 desc('Generate docs for Jake');
30 task('doc', ['doc:generate']);
31
32 npmPublishTask('jake', function () {
33   this.packageFiles.include([
34     'Makefile',
35     'jakefile.js',
36     'README.md',
37     'package.json',
38     'usage.txt',
39     'lib/**',
40     'bin/**',
41     'test/**'
42     ]);
43   this.packageFiles.exclude([
44     'test/tmp'
45   ]);
46 });
47
48 jake.Task['publish:package'].directory = PROJECT_DIR;
49
50 namespace('test', function () {
51
52   let integrationTest = task('integration', ['publish:package'], async function () {
53     let pkg = JSON.parse(fs.readFileSync(`${PROJECT_DIR}/package.json`).toString());
54     let version = pkg.version;
55
56     proc.execSync('rm -rf ./node_modules');
57     // Install from the actual package, run tests from the packaged binary
58     proc.execSync(`mkdir -p node_modules/.bin && mv ${PROJECT_DIR}/pkg/jake-v` +
59         `${version} node_modules/jake && ln -s ${process.cwd()}` +
60       '/node_modules/jake/bin/cli.js ./node_modules/.bin/jake');
61
62     let testArgs = [];
63     if (process.env.filter) {
64       testArgs.push(process.env.filter);
65     }
66     else {
67       testArgs.push('*.js');
68     }
69     let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
70       stdio: 'inherit'
71     });
72     return new Promise((resolve, reject) => {
73       spawned.on('exit', () => {
74         if (!(process.env.noclobber || process.env.noClobber)) {
75           proc.execSync('rm -rf tmp_publish && rm -rf package.json' +
76               ' && rm -rf package-lock.json && rm -rf node_modules');
77           // Rather than invoking 'clobber' task
78           jake.rmRf(`${PROJECT_DIR}/pkg`);
79         }
80         resolve();
81       });
82     });
83
84   });
85
86   integrationTest.directory = `${PROJECT_DIR}/test/integration`;
87
88   let unitTest = task('unit', async function () {
89     let testArgs = [];
90     if (process.env.filter) {
91       testArgs.push(process.env.filter);
92     }
93     else {
94       testArgs.push('*.js');
95     }
96     let spawned = proc.spawn(`${PROJECT_DIR}/node_modules/.bin/mocha`, testArgs, {
97       stdio: 'inherit'
98     });
99   });
100
101   unitTest.directory = `${PROJECT_DIR}/test/unit`;
102 });
103
104 desc('Runs all tests');
105 task('test', ['test:unit', 'test:integration']);