node-addon-api 4.1.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env node
2
+
3
+ const spawn = require('child_process').spawnSync;
4
+
5
+ const filesToCheck = '*.js';
6
+ const FORMAT_START = process.env.FORMAT_START || 'main';
7
+
8
+ function main (args) {
9
+ let fix = false;
10
+ while (args.length > 0) {
11
+ switch (args[0]) {
12
+ case '-f':
13
+ case '--fix':
14
+ fix = true;
15
+ break;
16
+ default:
17
+ }
18
+ args.shift();
19
+ }
20
+
21
+ // Check js files that change on unstaged file
22
+ const fileUnStaged = spawn(
23
+ 'git',
24
+ ['diff', '--name-only', FORMAT_START, filesToCheck],
25
+ {
26
+ encoding: 'utf-8'
27
+ }
28
+ );
29
+
30
+ // Check js files that change on staged file
31
+ const fileStaged = spawn(
32
+ 'git',
33
+ ['diff', '--name-only', '--cached', FORMAT_START, filesToCheck],
34
+ {
35
+ encoding: 'utf-8'
36
+ }
37
+ );
38
+
39
+ const options = [
40
+ ...fileStaged.stdout.split('\n').filter((f) => f !== ''),
41
+ ...fileUnStaged.stdout.split('\n').filter((f) => f !== '')
42
+ ];
43
+
44
+ if (fix) {
45
+ options.push('--fix');
46
+ }
47
+ const result = spawn('node_modules/.bin/eslint', [...options], {
48
+ encoding: 'utf-8'
49
+ });
50
+
51
+ if (result.status === 1) {
52
+ console.error('Eslint error:', result.stdout);
53
+ const fixCmd = 'npm run lint:fix';
54
+ console.error(`ERROR: please run "${fixCmd}" to format changes in your commit
55
+ Note that when running the command locally, please keep your local
56
+ main branch and working branch up to date with nodejs/node-addon-api
57
+ to exclude un-related complains.
58
+ Or you can run "env FORMAT_START=upstream/main ${fixCmd}".
59
+ Also fix JS files by yourself if necessary.`);
60
+ return 1;
61
+ }
62
+
63
+ if (result.stderr) {
64
+ console.error('Error running eslint:', result.stderr);
65
+ return 2;
66
+ }
67
+ }
68
+
69
+ if (require.main === module) {
70
+ process.exitCode = main(process.argv.slice(2));
71
+ }