@naturalcycles/dev-lib 14.2.0 → 15.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.
- package/dist/bin/dev-lib.d.ts +1 -0
- package/dist/bin/dev-lib.js +136 -0
- package/dist/bin/up.js +2 -8
- package/dist/bin/upnc.js +2 -3
- package/dist/build.util.d.ts +11 -0
- package/dist/build.util.js +103 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/{cmd/init-from-dev-lib.command.js → init-from-dev-lib.command.js} +2 -2
- package/dist/lint.util.d.ts +17 -0
- package/dist/lint.util.js +255 -0
- package/dist/{cnst/paths.cnst.js → paths.js} +1 -1
- package/dist/test.util.d.ts +10 -0
- package/dist/{util/jest.util.js → test.util.js} +31 -30
- package/dist/yarn.util.d.ts +2 -0
- package/dist/yarn.util.js +20 -0
- package/package.json +15 -47
- package/readme.md +33 -29
- package/dist/bin/bt.d.ts +0 -2
- package/dist/bin/bt.js +0 -12
- package/dist/bin/btl.d.ts +0 -2
- package/dist/bin/btl.js +0 -14
- package/dist/bin/build-copy.d.ts +0 -2
- package/dist/bin/build-copy.js +0 -6
- package/dist/bin/build-prod-esm-cjs.d.ts +0 -2
- package/dist/bin/build-prod-esm-cjs.js +0 -6
- package/dist/bin/build-prod.d.ts +0 -2
- package/dist/bin/build-prod.js +0 -6
- package/dist/bin/build.d.ts +0 -2
- package/dist/bin/build.js +0 -10
- package/dist/bin/commitlint-def.d.ts +0 -2
- package/dist/bin/commitlint-def.js +0 -34
- package/dist/bin/eslint-all.d.ts +0 -2
- package/dist/bin/eslint-all.js +0 -6
- package/dist/bin/init-from-dev-lib.d.ts +0 -2
- package/dist/bin/init-from-dev-lib.js +0 -6
- package/dist/bin/lint-all.d.ts +0 -2
- package/dist/bin/lint-all.js +0 -6
- package/dist/bin/lint-staged-def.d.ts +0 -2
- package/dist/bin/lint-staged-def.js +0 -28
- package/dist/bin/prettier-all.d.ts +0 -2
- package/dist/bin/prettier-all.js +0 -8
- package/dist/bin/stylelint-all.d.ts +0 -2
- package/dist/bin/stylelint-all.js +0 -8
- package/dist/bin/test-ci.d.ts +0 -2
- package/dist/bin/test-ci.js +0 -9
- package/dist/bin/test-integration-ci.d.ts +0 -2
- package/dist/bin/test-integration-ci.js +0 -9
- package/dist/bin/test-integration.d.ts +0 -2
- package/dist/bin/test-integration.js +0 -8
- package/dist/bin/test-leaks.d.ts +0 -2
- package/dist/bin/test-leaks.js +0 -8
- package/dist/bin/test-manual.d.ts +0 -2
- package/dist/bin/test-manual.js +0 -8
- package/dist/bin/test.d.ts +0 -2
- package/dist/bin/test.js +0 -8
- package/dist/bin/tsc-prod.d.ts +0 -2
- package/dist/bin/tsc-prod.js +0 -6
- package/dist/bin/tsc-scripts.d.ts +0 -2
- package/dist/bin/tsc-scripts.js +0 -6
- package/dist/bin/update-from-dev-lib.d.ts +0 -2
- package/dist/bin/update-from-dev-lib.js +0 -13
- package/dist/cmd/build-copy.command.d.ts +0 -1
- package/dist/cmd/build-copy.command.js +0 -22
- package/dist/cmd/build-prod-esm-cjs.command.d.ts +0 -1
- package/dist/cmd/build-prod-esm-cjs.command.js +0 -41
- package/dist/cmd/build-prod.command.d.ts +0 -1
- package/dist/cmd/build-prod.command.js +0 -12
- package/dist/cmd/eslint-all.command.d.ts +0 -4
- package/dist/cmd/eslint-all.command.js +0 -59
- package/dist/cmd/lint-all.command.d.ts +0 -4
- package/dist/cmd/lint-all.command.js +0 -97
- package/dist/cmd/tsc-prod.command.d.ts +0 -1
- package/dist/cmd/tsc-prod.command.js +0 -13
- package/dist/util/jest.util.d.ts +0 -17
- package/dist/util/lint.util.d.ts +0 -4
- package/dist/util/lint.util.js +0 -39
- package/dist/util/prettier.util.d.ts +0 -1
- package/dist/util/prettier.util.js +0 -23
- package/dist/util/stylelint.util.d.ts +0 -2
- package/dist/util/stylelint.util.js +0 -34
- package/dist/util/test.util.d.ts +0 -4
- package/dist/util/test.util.js +0 -11
- package/dist/util/tsc.util.d.ts +0 -9
- package/dist/util/tsc.util.js +0 -67
- /package/dist/{cmd/init-from-dev-lib.command.d.ts → init-from-dev-lib.command.d.ts} +0 -0
- /package/dist/{cnst/paths.cnst.d.ts → paths.d.ts} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
const node_os_1 = tslib_1.__importDefault(require("node:os"));
|
|
5
|
+
const prompts_1 = require("@inquirer/prompts");
|
|
6
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
7
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
|
+
const build_util_1 = require("../build.util");
|
|
9
|
+
const lint_util_1 = require("../lint.util");
|
|
10
|
+
const test_util_1 = require("../test.util");
|
|
11
|
+
const yarn_util_1 = require("../yarn.util");
|
|
12
|
+
const commands = [
|
|
13
|
+
new prompts_1.Separator(), // build
|
|
14
|
+
{
|
|
15
|
+
name: 'build',
|
|
16
|
+
fn: build_util_1.buildProd,
|
|
17
|
+
desc: 'Clean ./dist, run "build-copy" then tsc with emit, using tsconfig.prod.json',
|
|
18
|
+
cliOnly: true,
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: 'build-esm-cjs',
|
|
22
|
+
fn: build_util_1.buildEsmCjs,
|
|
23
|
+
desc: 'Clean ./dist and ./dist-esm, then run "tsc" in CJS and ESM modes.',
|
|
24
|
+
cliOnly: true,
|
|
25
|
+
},
|
|
26
|
+
{ name: 'bt', fn: bt, desc: 'Build & Test: run "build" and then "test".' },
|
|
27
|
+
{ name: 'lbt', fn: lbt, desc: 'Lint/Build/Test: run "lint", then "build", then "test".' },
|
|
28
|
+
new prompts_1.Separator(), // test
|
|
29
|
+
{ name: 'test', fn: test_util_1.runJest, desc: 'Run jest for *.test.ts files.' },
|
|
30
|
+
{
|
|
31
|
+
name: 'test-integration',
|
|
32
|
+
fn: () => (0, test_util_1.runJest)({ integration: true }),
|
|
33
|
+
desc: 'Run jest for *.integration.test.ts files.',
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: 'test-leaks',
|
|
37
|
+
fn: () => (0, test_util_1.runJest)({ leaks: true }),
|
|
38
|
+
desc: 'Run jest --detectLeaks for *.test.ts files.',
|
|
39
|
+
},
|
|
40
|
+
new prompts_1.Separator(), // lint
|
|
41
|
+
{
|
|
42
|
+
name: 'lint',
|
|
43
|
+
fn: lint_util_1.lintAllCommand,
|
|
44
|
+
desc: 'Run all linters: eslint, prettier, stylelint, ktlint, actionlint.',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: 'lint-staged',
|
|
48
|
+
fn: lint_util_1.lintStagedCommand,
|
|
49
|
+
desc: 'Run "lint-staged", which runs linter on git staged files.',
|
|
50
|
+
},
|
|
51
|
+
{ name: 'eslint', fn: lint_util_1.eslintAll, desc: 'Run eslint on all files.' },
|
|
52
|
+
{
|
|
53
|
+
name: 'eslint --no-fix',
|
|
54
|
+
fn: async () => await (0, lint_util_1.eslintAll)({ fix: false }),
|
|
55
|
+
desc: 'Run eslint on all files with "auto-fix" disabled. Useful for debugging.',
|
|
56
|
+
interactiveOnly: true,
|
|
57
|
+
},
|
|
58
|
+
{ name: 'prettier', fn: lint_util_1.runPrettier, desc: 'Run prettier on all files.' },
|
|
59
|
+
{ name: 'stylelint', fn: lint_util_1.stylelintAll, desc: 'Run stylelint on all files.' },
|
|
60
|
+
{ name: 'commitlint', fn: lint_util_1.runCommitlintCommand, desc: 'Run commitlint.', cliOnly: true },
|
|
61
|
+
new prompts_1.Separator(), // yarn
|
|
62
|
+
{ name: 'up', fn: yarn_util_1.up, desc: 'Shortcut for "yarn upgrade". Also runs yarn-deduplicate.' },
|
|
63
|
+
{
|
|
64
|
+
name: 'upnc',
|
|
65
|
+
fn: yarn_util_1.upnc,
|
|
66
|
+
desc: 'Shortcut for "yarn upgrade --pattern @naturalcycles". Also runs yarn-deduplicate.',
|
|
67
|
+
},
|
|
68
|
+
new prompts_1.Separator(), // interactive-only
|
|
69
|
+
{
|
|
70
|
+
name: 'exit',
|
|
71
|
+
fn: () => console.log('see you!'),
|
|
72
|
+
desc: 'Do nothing and exit.',
|
|
73
|
+
interactiveOnly: true,
|
|
74
|
+
},
|
|
75
|
+
// currently disabled
|
|
76
|
+
// build-copy is excluded
|
|
77
|
+
// init: initFromDevLibCommand, // todo: reimplement!
|
|
78
|
+
// 'update-from-dev-lib': () => {
|
|
79
|
+
// // todo: reimplement, name it `sync` maybe?
|
|
80
|
+
// kpySync({
|
|
81
|
+
// baseDir: cfgOverwriteDir,
|
|
82
|
+
// outputDir: './',
|
|
83
|
+
// dotfiles: true,
|
|
84
|
+
// verbose: true,
|
|
85
|
+
// })
|
|
86
|
+
// },
|
|
87
|
+
];
|
|
88
|
+
const commandMap = (0, js_lib_1._by)(commands.filter(c => !(c instanceof prompts_1.Separator)), c => c.name);
|
|
89
|
+
const { CI } = process.env;
|
|
90
|
+
(0, nodejs_lib_1.runScript)(async () => {
|
|
91
|
+
logEnvironment();
|
|
92
|
+
let cmd = process.argv.find(s => commandMap[s] && !commandMap[s].interactiveOnly);
|
|
93
|
+
if (!cmd) {
|
|
94
|
+
// interactive mode
|
|
95
|
+
(0, js_lib_1._assert)(!CI, 'interactive dev-lib should not be run in CI');
|
|
96
|
+
cmd = await (0, prompts_1.select)({
|
|
97
|
+
message: 'Select command',
|
|
98
|
+
pageSize: 30,
|
|
99
|
+
choices: commands
|
|
100
|
+
.filter(c => c instanceof prompts_1.Separator || !c.cliOnly)
|
|
101
|
+
.map(c => {
|
|
102
|
+
if (c instanceof prompts_1.Separator)
|
|
103
|
+
return c;
|
|
104
|
+
return {
|
|
105
|
+
value: c.name,
|
|
106
|
+
description: c.desc,
|
|
107
|
+
};
|
|
108
|
+
}),
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
await commandMap[cmd].fn();
|
|
112
|
+
});
|
|
113
|
+
async function lbt() {
|
|
114
|
+
await (0, lint_util_1.lintAllCommand)();
|
|
115
|
+
await bt();
|
|
116
|
+
}
|
|
117
|
+
async function bt() {
|
|
118
|
+
await (0, build_util_1.runTSCInFolders)(['.', 'scripts'], ['--noEmit']);
|
|
119
|
+
(0, test_util_1.runJest)();
|
|
120
|
+
}
|
|
121
|
+
function logEnvironment() {
|
|
122
|
+
const { CPU_LIMIT, NODE_OPTIONS = 'not defined' } = process.env;
|
|
123
|
+
const { node } = process.versions;
|
|
124
|
+
const cpuLimit = Number(CPU_LIMIT) || undefined;
|
|
125
|
+
const availableParallelism = node_os_1.default.availableParallelism?.();
|
|
126
|
+
const cpus = node_os_1.default.cpus().length;
|
|
127
|
+
console.log((0, nodejs_lib_1.dimGrey)(Object.entries({
|
|
128
|
+
node,
|
|
129
|
+
NODE_OPTIONS,
|
|
130
|
+
cpus,
|
|
131
|
+
availableParallelism,
|
|
132
|
+
cpuLimit,
|
|
133
|
+
})
|
|
134
|
+
.map(([k, v]) => `${k}: ${v}`)
|
|
135
|
+
.join(', ')));
|
|
136
|
+
}
|
package/dist/bin/up.js
CHANGED
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
6
4
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
+
const yarn_util_1 = require("../yarn.util");
|
|
7
6
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
8
|
-
(0,
|
|
9
|
-
(0, nodejs_lib_1.execVoidCommandSync)('yarn-deduplicate');
|
|
10
|
-
(0, nodejs_lib_1.execVoidCommandSync)('yarn');
|
|
11
|
-
if (node_fs_1.default.existsSync(`node_modules/patch-package`)) {
|
|
12
|
-
(0, nodejs_lib_1.execVoidCommandSync)('patch-package');
|
|
13
|
-
}
|
|
7
|
+
(0, yarn_util_1.up)();
|
|
14
8
|
});
|
package/dist/bin/upnc.js
CHANGED
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
+
const yarn_util_1 = require("../yarn.util");
|
|
5
6
|
(0, nodejs_lib_1.runScript)(async () => {
|
|
6
|
-
(0,
|
|
7
|
-
(0, nodejs_lib_1.execVoidCommandSync)('yarn-deduplicate');
|
|
8
|
-
(0, nodejs_lib_1.execVoidCommandSync)('yarn');
|
|
7
|
+
(0, yarn_util_1.upnc)();
|
|
9
8
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function buildEsmCjs(): Promise<void>;
|
|
2
|
+
export declare function buildProd(): Promise<void>;
|
|
3
|
+
/**
|
|
4
|
+
* Use '.' to indicate root.
|
|
5
|
+
*/
|
|
6
|
+
export declare function runTSCInFolders(tsconfigPaths: string[], args?: string[], parallel?: boolean): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Pass '.' to run in root.
|
|
9
|
+
*/
|
|
10
|
+
export declare function runTSCInFolder(tsconfigPath: string, args?: string[]): Promise<void>;
|
|
11
|
+
export declare function runTSCProd(): Promise<void>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.buildEsmCjs = buildEsmCjs;
|
|
4
|
+
exports.buildProd = buildProd;
|
|
5
|
+
exports.runTSCInFolders = runTSCInFolders;
|
|
6
|
+
exports.runTSCInFolder = runTSCInFolder;
|
|
7
|
+
exports.runTSCProd = runTSCProd;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
10
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
11
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
12
|
+
async function buildEsmCjs() {
|
|
13
|
+
// You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
|
|
14
|
+
const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
|
|
15
|
+
const TSCONF_ESM_PATH = `./tsconfig.esm.prod.json`;
|
|
16
|
+
const TSCONF_PROD_PATH = `./tsconfig.prod.json`;
|
|
17
|
+
const cjsExists = nodejs_lib_1.fs2.pathExists(TSCONF_CJS_PATH);
|
|
18
|
+
const esmExists = nodejs_lib_1.fs2.pathExists(TSCONF_ESM_PATH);
|
|
19
|
+
// it doesn't delete the dir itself, to prevent IDE jumping
|
|
20
|
+
nodejs_lib_1.fs2.emptyDir('./dist');
|
|
21
|
+
nodejs_lib_1.fs2.emptyDir('./dist-esm');
|
|
22
|
+
const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PROD_PATH;
|
|
23
|
+
const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PROD_PATH;
|
|
24
|
+
await Promise.all([
|
|
25
|
+
(0, nodejs_lib_1.execVoidCommand)('tsc', [
|
|
26
|
+
'-P',
|
|
27
|
+
cjsPath,
|
|
28
|
+
'--outDir',
|
|
29
|
+
'./dist',
|
|
30
|
+
'--module',
|
|
31
|
+
'nodenext',
|
|
32
|
+
'--moduleResolution',
|
|
33
|
+
'nodenext',
|
|
34
|
+
]),
|
|
35
|
+
(0, nodejs_lib_1.execVoidCommand)('tsc', [
|
|
36
|
+
'-P',
|
|
37
|
+
esmPath,
|
|
38
|
+
'--outDir',
|
|
39
|
+
'./dist-esm',
|
|
40
|
+
'--module',
|
|
41
|
+
'esnext',
|
|
42
|
+
'--moduleResolution',
|
|
43
|
+
'bundler',
|
|
44
|
+
'--declaration',
|
|
45
|
+
'false',
|
|
46
|
+
]),
|
|
47
|
+
]);
|
|
48
|
+
}
|
|
49
|
+
async function buildProd() {
|
|
50
|
+
nodejs_lib_1.fs2.emptyDir('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
|
|
51
|
+
buildCopy();
|
|
52
|
+
await runTSCProd();
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Use '.' to indicate root.
|
|
56
|
+
*/
|
|
57
|
+
async function runTSCInFolders(tsconfigPaths, args = [], parallel = true) {
|
|
58
|
+
if (parallel) {
|
|
59
|
+
await Promise.all(tsconfigPaths.map(p => runTSCInFolder(p, args)));
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
for (const p of tsconfigPaths) {
|
|
63
|
+
await runTSCInFolder(p, args);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Pass '.' to run in root.
|
|
69
|
+
*/
|
|
70
|
+
async function runTSCInFolder(tsconfigPath, args = []) {
|
|
71
|
+
if (!node_fs_1.default.existsSync(tsconfigPath)) {
|
|
72
|
+
console.log(`Skipping to run tsc for ${tsconfigPath}, as it doesn't exist`);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const started = Date.now();
|
|
76
|
+
await (0, nodejs_lib_1.execVoidCommand)(`tsc`, ['-P', tsconfigPath, ...args]);
|
|
77
|
+
console.log(`${(0, nodejs_lib_1.boldGrey)(`tsc ${tsconfigPath}`)} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
78
|
+
}
|
|
79
|
+
async function runTSCProd() {
|
|
80
|
+
const tsconfigPath = [`./tsconfig.prod.json`].find(p => node_fs_1.default.existsSync(p)) || 'tsconfig.json';
|
|
81
|
+
const args = ['-P', tsconfigPath];
|
|
82
|
+
const started = Date.now();
|
|
83
|
+
await (0, nodejs_lib_1.execVoidCommand)(`tsc`, args);
|
|
84
|
+
console.log(`${(0, nodejs_lib_1.boldGrey)('tsc prod')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
85
|
+
}
|
|
86
|
+
function buildCopy() {
|
|
87
|
+
const baseDir = 'src';
|
|
88
|
+
const inputPatterns = [
|
|
89
|
+
'**',
|
|
90
|
+
'!**/*.ts',
|
|
91
|
+
'!**/__snapshots__',
|
|
92
|
+
'!**/__exclude',
|
|
93
|
+
'!test',
|
|
94
|
+
'!**/*.test.js',
|
|
95
|
+
];
|
|
96
|
+
const outputDir = 'dist';
|
|
97
|
+
(0, nodejs_lib_1.kpySync)({
|
|
98
|
+
baseDir,
|
|
99
|
+
inputPatterns,
|
|
100
|
+
outputDir,
|
|
101
|
+
dotfiles: true,
|
|
102
|
+
});
|
|
103
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { buildProd } from './build.util';
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
exports.buildProd = void 0;
|
|
4
|
+
var build_util_1 = require("./build.util");
|
|
5
|
+
Object.defineProperty(exports, "buildProd", { enumerable: true, get: function () { return build_util_1.buildProd; } });
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.initFromDevLibCommand = initFromDevLibCommand;
|
|
4
4
|
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
5
|
-
const
|
|
5
|
+
const paths_1 = require("./paths");
|
|
6
6
|
function initFromDevLibCommand() {
|
|
7
7
|
(0, nodejs_lib_1.kpySync)({
|
|
8
|
-
baseDir:
|
|
8
|
+
baseDir: paths_1.cfgOverwriteDir,
|
|
9
9
|
outputDir: './',
|
|
10
10
|
dotfiles: true,
|
|
11
11
|
verbose: true,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Run all linters.
|
|
3
|
+
*/
|
|
4
|
+
export declare function lintAllCommand(): Promise<void>;
|
|
5
|
+
interface EslintAllOptions {
|
|
6
|
+
ext?: string;
|
|
7
|
+
fix?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
|
|
11
|
+
*/
|
|
12
|
+
export declare function eslintAll(opt?: EslintAllOptions): Promise<void>;
|
|
13
|
+
export declare function runPrettier(): void;
|
|
14
|
+
export declare function stylelintAll(): void;
|
|
15
|
+
export declare function lintStagedCommand(): Promise<void>;
|
|
16
|
+
export declare function runCommitlintCommand(): void;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lintAllCommand = lintAllCommand;
|
|
4
|
+
exports.eslintAll = eslintAll;
|
|
5
|
+
exports.runPrettier = runPrettier;
|
|
6
|
+
exports.stylelintAll = stylelintAll;
|
|
7
|
+
exports.lintStagedCommand = lintStagedCommand;
|
|
8
|
+
exports.runCommitlintCommand = runCommitlintCommand;
|
|
9
|
+
const tslib_1 = require("tslib");
|
|
10
|
+
const node_child_process_1 = tslib_1.__importDefault(require("node:child_process"));
|
|
11
|
+
const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
|
|
12
|
+
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
13
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
14
|
+
const yargs_1 = tslib_1.__importDefault(require("yargs"));
|
|
15
|
+
const paths_1 = require("./paths");
|
|
16
|
+
const { prettierDirs, prettierExtensionsAll, stylelintExtensions, lintExclude, } = require('../cfg/_cnst');
|
|
17
|
+
/**
|
|
18
|
+
* Run all linters.
|
|
19
|
+
*/
|
|
20
|
+
async function lintAllCommand() {
|
|
21
|
+
const started = Date.now();
|
|
22
|
+
const { commitOnChanges, failOnChanges } = yargs_1.default.options({
|
|
23
|
+
commitOnChanges: {
|
|
24
|
+
type: 'boolean',
|
|
25
|
+
default: false,
|
|
26
|
+
},
|
|
27
|
+
failOnChanges: {
|
|
28
|
+
type: 'boolean',
|
|
29
|
+
default: false,
|
|
30
|
+
},
|
|
31
|
+
}).argv;
|
|
32
|
+
const needToTrackChanges = commitOnChanges || failOnChanges;
|
|
33
|
+
const gitStatusAtStart = gitStatus();
|
|
34
|
+
if (needToTrackChanges && gitStatusAtStart) {
|
|
35
|
+
console.log('lint-all: git shows changes before run:');
|
|
36
|
+
console.log(gitStatusAtStart);
|
|
37
|
+
}
|
|
38
|
+
// We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
|
|
39
|
+
await eslintAll();
|
|
40
|
+
if (node_fs_1.default.existsSync(`node_modules/stylelint`) &&
|
|
41
|
+
node_fs_1.default.existsSync(`node_modules/stylelint-config-standard-scss`)) {
|
|
42
|
+
stylelintAll();
|
|
43
|
+
}
|
|
44
|
+
runPrettier();
|
|
45
|
+
runActionLint();
|
|
46
|
+
await runKTLint();
|
|
47
|
+
console.log(`${(0, nodejs_lib_1.boldGrey)('lint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
48
|
+
if (needToTrackChanges) {
|
|
49
|
+
const gitStatusAfter = gitStatus();
|
|
50
|
+
const hasChanges = gitStatusAfter !== gitStatusAtStart;
|
|
51
|
+
if (!hasChanges)
|
|
52
|
+
return;
|
|
53
|
+
const msg = 'style(ci): ' + (0, js_lib_1._truncate)((0, nodejs_lib_1.commitMessageToTitleMessage)((0, nodejs_lib_1.getLastGitCommitMsg)()), 60);
|
|
54
|
+
// pull, commit, push changes
|
|
55
|
+
(0, nodejs_lib_1.gitPull)();
|
|
56
|
+
(0, nodejs_lib_1.gitCommitAll)(msg);
|
|
57
|
+
(0, nodejs_lib_1.gitPush)();
|
|
58
|
+
// fail on changes
|
|
59
|
+
if (failOnChanges) {
|
|
60
|
+
console.log(gitStatusAfter);
|
|
61
|
+
console.log('lint-all failOnChanges: exiting with status 1');
|
|
62
|
+
process.exitCode = 1;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
|
|
68
|
+
*/
|
|
69
|
+
async function eslintAll(opt) {
|
|
70
|
+
const started = Date.now();
|
|
71
|
+
const { argv } = yargs_1.default.options({
|
|
72
|
+
ext: {
|
|
73
|
+
type: 'string',
|
|
74
|
+
default: 'ts,tsx,vue',
|
|
75
|
+
},
|
|
76
|
+
fix: {
|
|
77
|
+
type: 'boolean',
|
|
78
|
+
default: true,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
const { ext, fix } = {
|
|
82
|
+
...argv,
|
|
83
|
+
...opt,
|
|
84
|
+
};
|
|
85
|
+
const extensions = ext.split(',');
|
|
86
|
+
const eslintConfigPathRoot = ['./eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
87
|
+
const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
88
|
+
const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
89
|
+
const eslintConfigPathPlaywright = ['./playwright/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
|
|
90
|
+
const tsconfigPathScripts = [`./scripts/tsconfig.json`].find(p => node_fs_1.default.existsSync(p)) || `${paths_1.scriptsDir}/tsconfig.json`;
|
|
91
|
+
const tsconfigPathE2e = `./e2e/tsconfig.json`;
|
|
92
|
+
const tsconfigPathPlaywright = `./playwright/tsconfig.json`;
|
|
93
|
+
// todo: run on other dirs too, e.g pages, components, layouts
|
|
94
|
+
if (fix) {
|
|
95
|
+
await Promise.all([
|
|
96
|
+
// /src
|
|
97
|
+
runESLint(`./src`, eslintConfigPathRoot, undefined, extensions, fix),
|
|
98
|
+
// /scripts
|
|
99
|
+
runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix),
|
|
100
|
+
// /e2e
|
|
101
|
+
runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix),
|
|
102
|
+
// /playwright // todo: remove after migration to e2e folder is completed
|
|
103
|
+
runESLint(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix),
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// with no-fix - let's run serially
|
|
108
|
+
// /src
|
|
109
|
+
await runESLint(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
|
|
110
|
+
// /scripts
|
|
111
|
+
await runESLint(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
|
|
112
|
+
// /e2e
|
|
113
|
+
await runESLint(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
|
|
114
|
+
// /e2e
|
|
115
|
+
await runESLint(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix);
|
|
116
|
+
}
|
|
117
|
+
console.log(`${(0, nodejs_lib_1.boldGrey)('eslint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
118
|
+
}
|
|
119
|
+
async function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
|
|
120
|
+
if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
|
|
121
|
+
return; // faster to bail-out like this
|
|
122
|
+
await (0, nodejs_lib_1.execVoidCommand)('eslint', [
|
|
123
|
+
`--config`,
|
|
124
|
+
eslintConfigPath,
|
|
125
|
+
`${dir}/**/*.{${extensions.join(',')}}`,
|
|
126
|
+
...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
|
|
127
|
+
`--no-error-on-unmatched-pattern`,
|
|
128
|
+
`--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
|
|
129
|
+
fix ? `--fix` : '',
|
|
130
|
+
].filter(Boolean));
|
|
131
|
+
}
|
|
132
|
+
const prettierPaths = [
|
|
133
|
+
// Everything inside these folders
|
|
134
|
+
`./{${prettierDirs}}/**/*.{${prettierExtensionsAll}}`,
|
|
135
|
+
// Root
|
|
136
|
+
`./*.{${prettierExtensionsAll}}`,
|
|
137
|
+
// Exclude
|
|
138
|
+
...lintExclude.map((s) => `!${s}`),
|
|
139
|
+
];
|
|
140
|
+
function runPrettier() {
|
|
141
|
+
const prettierConfigPath = [`./prettier.config.js`].find(f => node_fs_1.default.existsSync(f));
|
|
142
|
+
if (!prettierConfigPath)
|
|
143
|
+
return;
|
|
144
|
+
// prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
|
|
145
|
+
(0, nodejs_lib_1.execVoidCommandSync)('prettier', [
|
|
146
|
+
`--write`,
|
|
147
|
+
`--log-level=warn`,
|
|
148
|
+
`--config`,
|
|
149
|
+
prettierConfigPath,
|
|
150
|
+
...prettierPaths,
|
|
151
|
+
]);
|
|
152
|
+
}
|
|
153
|
+
const stylelintPaths = [
|
|
154
|
+
// Everything inside these folders
|
|
155
|
+
`./{${prettierDirs}}/**/*.{${stylelintExtensions}}`,
|
|
156
|
+
// Exclude
|
|
157
|
+
...lintExclude.map((s) => `!${s}`),
|
|
158
|
+
];
|
|
159
|
+
function stylelintAll() {
|
|
160
|
+
const { fix } = yargs_1.default.options({
|
|
161
|
+
fix: {
|
|
162
|
+
type: 'boolean',
|
|
163
|
+
default: true,
|
|
164
|
+
},
|
|
165
|
+
}).argv;
|
|
166
|
+
const config = [`./stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
|
|
167
|
+
if (!config)
|
|
168
|
+
return;
|
|
169
|
+
(0, nodejs_lib_1.execVoidCommandSync)('stylelint', [fix ? `--fix` : '', `--allow-empty-input`, `--config`, config, ...stylelintPaths].filter(Boolean));
|
|
170
|
+
}
|
|
171
|
+
async function lintStagedCommand() {
|
|
172
|
+
// const cwd = process.cwd()
|
|
173
|
+
const localConfig = `./lint-staged.config.js`;
|
|
174
|
+
const sharedConfig = `${paths_1.cfgDir}/lint-staged.config.js`;
|
|
175
|
+
const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
|
|
176
|
+
// if (!config) {
|
|
177
|
+
// console.log(`lint-staged is skipped, because no ${localConfig} is found`)
|
|
178
|
+
// return
|
|
179
|
+
// }
|
|
180
|
+
// await execWithArgs(`lint-staged`, [`--config`, config])
|
|
181
|
+
// const lintStaged = require('lint-staged')
|
|
182
|
+
// lint-staged is ESM since 12.0
|
|
183
|
+
// const lintStaged = await import('lint-staged')
|
|
184
|
+
// eslint-disable-next-line no-eval
|
|
185
|
+
const { default: lintStaged } = await eval(`import('lint-staged')`);
|
|
186
|
+
const success = await lintStaged({
|
|
187
|
+
configPath: config,
|
|
188
|
+
});
|
|
189
|
+
if (!success)
|
|
190
|
+
process.exit(3);
|
|
191
|
+
}
|
|
192
|
+
function runCommitlintCommand() {
|
|
193
|
+
const editMsg = process.argv.at(-1) || '.git/COMMIT_EDITMSG';
|
|
194
|
+
// console.log(editMsg)
|
|
195
|
+
const cwd = process.cwd();
|
|
196
|
+
const localConfig = `${cwd}/commitlint.config.js`;
|
|
197
|
+
const sharedConfig = `${paths_1.cfgDir}/commitlint.config.js`;
|
|
198
|
+
const config = node_fs_1.default.existsSync(localConfig) ? localConfig : sharedConfig;
|
|
199
|
+
const env = {
|
|
200
|
+
...process.env, // important to pass it through, to preserve $PATH
|
|
201
|
+
GIT_BRANCH: (0, nodejs_lib_1.gitCurrentBranchName)(),
|
|
202
|
+
};
|
|
203
|
+
// await execWithArgs(`commitlint`, [`--edit`, editMsg, `--config`, config], { env })
|
|
204
|
+
execSync(`node ./node_modules/.bin/commitlint --edit ${editMsg} --config ${config}`, {
|
|
205
|
+
env,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
async function runKTLint() {
|
|
209
|
+
if (node_fs_1.default.existsSync(`node_modules/@naturalcycles/ktlint`)) {
|
|
210
|
+
const ktlintLib = require('@naturalcycles/ktlint');
|
|
211
|
+
await ktlintLib.ktlintAll();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function runActionLint() {
|
|
215
|
+
// Only run if there is a folder of `.github/workflows`, otherwise actionlint will fail
|
|
216
|
+
if (!node_fs_1.default.existsSync('.github/workflows'))
|
|
217
|
+
return;
|
|
218
|
+
if (canRunBinary('actionlint')) {
|
|
219
|
+
const started = Date.now();
|
|
220
|
+
(0, nodejs_lib_1.execVoidCommandSync)(`actionlint`);
|
|
221
|
+
console.log(`${(0, nodejs_lib_1.boldGrey)('actionlint')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
console.log(`actionlint is not installed and won't be run.\nThis is how to install it: https://github.com/rhysd/actionlint/blob/main/docs/install.md`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
function canRunBinary(name) {
|
|
228
|
+
try {
|
|
229
|
+
execSync(`which ${name}`);
|
|
230
|
+
return true;
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function gitStatus() {
|
|
237
|
+
try {
|
|
238
|
+
return node_child_process_1.default.execSync('git status -s', {
|
|
239
|
+
encoding: 'utf8',
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
catch { }
|
|
243
|
+
}
|
|
244
|
+
function execSync(cmd, opt) {
|
|
245
|
+
try {
|
|
246
|
+
node_child_process_1.default.execSync(cmd, {
|
|
247
|
+
...opt,
|
|
248
|
+
encoding: 'utf8',
|
|
249
|
+
stdio: 'inherit',
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
catch {
|
|
253
|
+
process.exit(1);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.scriptsDir = exports.cfgOverwriteDir = exports.cfgDir = exports.testDir = exports.srcDir = exports.projectDir = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const node_path_1 = tslib_1.__importDefault(require("node:path"));
|
|
6
|
-
exports.projectDir = node_path_1.default.join(__dirname, '
|
|
6
|
+
exports.projectDir = node_path_1.default.join(__dirname, '..');
|
|
7
7
|
exports.srcDir = `${exports.projectDir}/src`;
|
|
8
8
|
exports.testDir = `${exports.srcDir}/test`;
|
|
9
9
|
exports.cfgDir = `${exports.projectDir}/cfg`;
|