Skip to content
This repository was archived by the owner on Oct 23, 2024. It is now read-only.

Commit 525cabb

Browse files
authored
Add eslint in packing process (#936)
* Update README * Add eslint in packing process
1 parent 387db8d commit 525cabb

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ The ${webrtc-javascript-sdk-sample-conference-dist} is built from owt-javascript
3434
If "--archive ${name}" option is appended to the pack command, a "Release-${name}.tgz" file will be generated in root folder. For other options, run the scripts with "--help" option.
3535

3636
## Quick Start
37-
In the repository root, run the following commands to start the media server on a single machine:
37+
In dist folder, run the following commands to start the media server on a single machine:
3838
1. `./bin/init-all.sh --deps`
3939
2. `./bin/start-all.sh`
4040
3. Open https://localhost:3004 to visit the web sample page. Due to the test certificate, you may need confirm this unsafe access.

scripts/pack.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ optParser.addOption('b', 'binary', 'boolean', 'Pack binary');
2828
optParser.addOption('np', 'no-pseudo', 'boolean', 'Whether use pseudo library');
2929
optParser.addOption('wf', 'with-ffmpeg', 'boolean', 'Whether pack ffmpeg library');
3030
optParser.addOption('h', 'help', 'boolean', 'Show help');
31+
optParser.addOption('li', 'lint', 'boolean', 'Whether lint code with eslint');
3132

3233
const options = optParser.parseArgs(process.argv);
3334

@@ -58,6 +59,25 @@ if (options.help || Object.keys(options).length === 0) {
5859
process.exit(0);
5960
}
6061

62+
if (options.lint) {
63+
// Check lint deps
64+
const lintDeps = ['eslint'];
65+
console.log('Checking lint dependencies...');
66+
const npmRoot = execSync(`npm root -g`).toString().trim();
67+
const missingLintDeps = lintDeps.filter((dep) => {
68+
return !fs.existsSync(path.join(npmRoot, dep));
69+
});
70+
71+
if (missingLintDeps.length === 0) {
72+
console.log('Lint dependencies OK.');
73+
} else {
74+
for (const dep of missingLintDeps) {
75+
console.log('Installing eslint');
76+
execSync(`npm install eslint --global --save-dev`);
77+
}
78+
}
79+
}
80+
6181
var npmInstallOption = '';
6282
if (process.getuid && process.getuid() === 0) {
6383
// Running as root
@@ -240,6 +260,14 @@ function packCommon(target) {
240260
// Copy common files
241261
for (const file of common.files) {
242262
const filePath = path.join(packSrc, file);
263+
const extname = path.extname(filePath);
264+
if (options.lint && extname === '.js') {
265+
try {
266+
execSync(`eslint -c ${rootDir}/source/.eslintrc.json ${filePath}`);
267+
} catch(error) {
268+
console.error(error.stdout.toString());
269+
}
270+
}
243271
execSync(`cp -a ${filePath} ${packDist}`);
244272
}
245273
}

source/.eslintrc.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es2021": true
5+
},
6+
"extends": "eslint:recommended",
7+
"parserOptions": {
8+
"ecmaVersion": 12,
9+
"sourceType": "module"
10+
},
11+
"rules": {
12+
}
13+
}

0 commit comments

Comments
 (0)