-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathnpm-scripts.js
89 lines (69 loc) · 1.7 KB
/
npm-scripts.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const process = require('process');
const fs = require('fs');
const { execSync } = require('child_process');
const { version } = require('./package.json');
const task = process.argv.slice(2).join(' ');
// eslint-disable-next-line no-console
console.log(`npm-scripts.js [INFO] running task "${task}"`);
switch (task)
{
case 'typescript:build':
{
execute('rm -rf lib');
execute('tsc');
taskReplaceVersion();
break;
}
case 'typescript:watch':
{
const TscWatchClient = require('tsc-watch/client');
execute('rm -rf lib');
const watch = new TscWatchClient();
watch.on('success', taskReplaceVersion);
watch.start('--pretty');
break;
}
case 'lint':
{
execute('MEDIASOUP_NODE_LANGUAGE=typescript eslint -c .eslintrc.js --ext=ts src/');
execute('MEDIASOUP_NODE_LANGUAGE=javascript eslint -c .eslintrc.js --ext=js --ignore-pattern \'!.eslintrc.js\' .eslintrc.js npm-scripts.js test/');
break;
}
case 'test':
{
taskReplaceVersion();
execute('jest');
break;
}
case 'coverage':
{
taskReplaceVersion();
execute('jest --coverage');
execute('open-cli coverage/lcov-report/index.html');
break;
}
default:
{
throw new TypeError(`unknown task "${task}"`);
}
}
function taskReplaceVersion()
{
const file = 'lib/index.js';
const text = fs.readFileSync(file, { encoding: 'utf8' });
const result = text.replace(/__MEDIASOUP_CLIENT_VERSION__/g, version);
fs.writeFileSync(file, result, { encoding: 'utf8' });
}
function execute(command)
{
// eslint-disable-next-line no-console
console.log(`npm-scripts.js [INFO] executing command: ${command}`);
try
{
execSync(command, { stdio: [ 'ignore', process.stdout, process.stderr ] });
}
catch (error)
{
process.exit(1);
}
}