@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.
Files changed (87) hide show
  1. package/dist/bin/dev-lib.d.ts +1 -0
  2. package/dist/bin/dev-lib.js +136 -0
  3. package/dist/bin/up.js +2 -8
  4. package/dist/bin/upnc.js +2 -3
  5. package/dist/build.util.d.ts +11 -0
  6. package/dist/build.util.js +103 -0
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.js +3 -2
  9. package/dist/{cmd/init-from-dev-lib.command.js → init-from-dev-lib.command.js} +2 -2
  10. package/dist/lint.util.d.ts +17 -0
  11. package/dist/lint.util.js +255 -0
  12. package/dist/{cnst/paths.cnst.js → paths.js} +1 -1
  13. package/dist/test.util.d.ts +10 -0
  14. package/dist/{util/jest.util.js → test.util.js} +31 -30
  15. package/dist/yarn.util.d.ts +2 -0
  16. package/dist/yarn.util.js +20 -0
  17. package/package.json +15 -47
  18. package/readme.md +33 -29
  19. package/dist/bin/bt.d.ts +0 -2
  20. package/dist/bin/bt.js +0 -12
  21. package/dist/bin/btl.d.ts +0 -2
  22. package/dist/bin/btl.js +0 -14
  23. package/dist/bin/build-copy.d.ts +0 -2
  24. package/dist/bin/build-copy.js +0 -6
  25. package/dist/bin/build-prod-esm-cjs.d.ts +0 -2
  26. package/dist/bin/build-prod-esm-cjs.js +0 -6
  27. package/dist/bin/build-prod.d.ts +0 -2
  28. package/dist/bin/build-prod.js +0 -6
  29. package/dist/bin/build.d.ts +0 -2
  30. package/dist/bin/build.js +0 -10
  31. package/dist/bin/commitlint-def.d.ts +0 -2
  32. package/dist/bin/commitlint-def.js +0 -34
  33. package/dist/bin/eslint-all.d.ts +0 -2
  34. package/dist/bin/eslint-all.js +0 -6
  35. package/dist/bin/init-from-dev-lib.d.ts +0 -2
  36. package/dist/bin/init-from-dev-lib.js +0 -6
  37. package/dist/bin/lint-all.d.ts +0 -2
  38. package/dist/bin/lint-all.js +0 -6
  39. package/dist/bin/lint-staged-def.d.ts +0 -2
  40. package/dist/bin/lint-staged-def.js +0 -28
  41. package/dist/bin/prettier-all.d.ts +0 -2
  42. package/dist/bin/prettier-all.js +0 -8
  43. package/dist/bin/stylelint-all.d.ts +0 -2
  44. package/dist/bin/stylelint-all.js +0 -8
  45. package/dist/bin/test-ci.d.ts +0 -2
  46. package/dist/bin/test-ci.js +0 -9
  47. package/dist/bin/test-integration-ci.d.ts +0 -2
  48. package/dist/bin/test-integration-ci.js +0 -9
  49. package/dist/bin/test-integration.d.ts +0 -2
  50. package/dist/bin/test-integration.js +0 -8
  51. package/dist/bin/test-leaks.d.ts +0 -2
  52. package/dist/bin/test-leaks.js +0 -8
  53. package/dist/bin/test-manual.d.ts +0 -2
  54. package/dist/bin/test-manual.js +0 -8
  55. package/dist/bin/test.d.ts +0 -2
  56. package/dist/bin/test.js +0 -8
  57. package/dist/bin/tsc-prod.d.ts +0 -2
  58. package/dist/bin/tsc-prod.js +0 -6
  59. package/dist/bin/tsc-scripts.d.ts +0 -2
  60. package/dist/bin/tsc-scripts.js +0 -6
  61. package/dist/bin/update-from-dev-lib.d.ts +0 -2
  62. package/dist/bin/update-from-dev-lib.js +0 -13
  63. package/dist/cmd/build-copy.command.d.ts +0 -1
  64. package/dist/cmd/build-copy.command.js +0 -22
  65. package/dist/cmd/build-prod-esm-cjs.command.d.ts +0 -1
  66. package/dist/cmd/build-prod-esm-cjs.command.js +0 -41
  67. package/dist/cmd/build-prod.command.d.ts +0 -1
  68. package/dist/cmd/build-prod.command.js +0 -12
  69. package/dist/cmd/eslint-all.command.d.ts +0 -4
  70. package/dist/cmd/eslint-all.command.js +0 -59
  71. package/dist/cmd/lint-all.command.d.ts +0 -4
  72. package/dist/cmd/lint-all.command.js +0 -97
  73. package/dist/cmd/tsc-prod.command.d.ts +0 -1
  74. package/dist/cmd/tsc-prod.command.js +0 -13
  75. package/dist/util/jest.util.d.ts +0 -17
  76. package/dist/util/lint.util.d.ts +0 -4
  77. package/dist/util/lint.util.js +0 -39
  78. package/dist/util/prettier.util.d.ts +0 -1
  79. package/dist/util/prettier.util.js +0 -23
  80. package/dist/util/stylelint.util.d.ts +0 -2
  81. package/dist/util/stylelint.util.js +0 -34
  82. package/dist/util/test.util.d.ts +0 -4
  83. package/dist/util/test.util.js +0 -11
  84. package/dist/util/tsc.util.d.ts +0 -9
  85. package/dist/util/tsc.util.js +0 -67
  86. /package/dist/{cmd/init-from-dev-lib.command.d.ts → init-from-dev-lib.command.d.ts} +0 -0
  87. /package/dist/{cnst/paths.cnst.d.ts → paths.d.ts} +0 -0
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const tsc_prod_command_1 = require("../cmd/tsc-prod.command");
6
- (0, nodejs_lib_1.runScript)(tsc_prod_command_1.tscProdCommand);
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const tsc_util_1 = require("../util/tsc.util");
6
- (0, nodejs_lib_1.runScript)(tsc_util_1.tscScripts);
@@ -1,2 +0,0 @@
1
- #!/usr/bin/env node
2
- export {};
@@ -1,13 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const paths_cnst_1 = require("../cnst/paths.cnst");
6
- (0, nodejs_lib_1.runScript)(() => {
7
- (0, nodejs_lib_1.kpySync)({
8
- baseDir: paths_cnst_1.cfgOverwriteDir,
9
- outputDir: './',
10
- dotfiles: true,
11
- verbose: true,
12
- });
13
- });
@@ -1 +0,0 @@
1
- export declare function buildCopyCommand(): void;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildCopyCommand = buildCopyCommand;
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- function buildCopyCommand() {
6
- const baseDir = 'src';
7
- const inputPatterns = [
8
- '**',
9
- '!**/*.ts',
10
- '!**/__snapshots__',
11
- '!**/__exclude',
12
- '!test',
13
- '!**/*.test.js',
14
- ];
15
- const outputDir = 'dist';
16
- (0, nodejs_lib_1.kpySync)({
17
- baseDir,
18
- inputPatterns,
19
- outputDir,
20
- dotfiles: true,
21
- });
22
- }
@@ -1 +0,0 @@
1
- export declare function buildProdESMCJSCommand(): Promise<void>;
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildProdESMCJSCommand = buildProdESMCJSCommand;
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
6
- const TSCONF_CJS_PATH = `./tsconfig.cjs.prod.json`;
7
- const TSCONF_ESM_PATH = `./tsconfig.esm.prod.json`;
8
- const TSCONF_PATH = `./tsconfig.prod.json`;
9
- async function buildProdESMCJSCommand() {
10
- const cjsExists = nodejs_lib_1.fs2.pathExists(TSCONF_CJS_PATH);
11
- const esmExists = nodejs_lib_1.fs2.pathExists(TSCONF_ESM_PATH);
12
- // it doesn't delete the dir itself, to prevent IDE jumping
13
- nodejs_lib_1.fs2.emptyDir('./dist');
14
- nodejs_lib_1.fs2.emptyDir('./dist-esm');
15
- const cjsPath = cjsExists ? TSCONF_CJS_PATH : TSCONF_PATH;
16
- const esmPath = esmExists ? TSCONF_ESM_PATH : TSCONF_PATH;
17
- await Promise.all([
18
- (0, nodejs_lib_1.execVoidCommand)('tsc', [
19
- '-P',
20
- cjsPath,
21
- '--outDir',
22
- './dist',
23
- '--module',
24
- 'nodenext',
25
- '--moduleResolution',
26
- 'nodenext',
27
- ]),
28
- (0, nodejs_lib_1.execVoidCommand)('tsc', [
29
- '-P',
30
- esmPath,
31
- '--outDir',
32
- './dist-esm',
33
- '--module',
34
- 'esnext',
35
- '--moduleResolution',
36
- 'bundler',
37
- '--declaration',
38
- 'false',
39
- ]),
40
- ]);
41
- }
@@ -1 +0,0 @@
1
- export declare function buildProdCommand(): void;
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildProdCommand = buildProdCommand;
4
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
5
- const build_copy_command_1 = require("./build-copy.command");
6
- const tsc_prod_command_1 = require("./tsc-prod.command");
7
- function buildProdCommand() {
8
- nodejs_lib_1.fs2.emptyDir('./dist'); // it doesn't delete the dir itself, to prevent IDE jumping
9
- // fs.rmSync('./dist', { recursive: true, force: true })
10
- (0, build_copy_command_1.buildCopyCommand)();
11
- (0, tsc_prod_command_1.tscProdCommand)();
12
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
3
- */
4
- export declare function eslintAllCommand(): Promise<void>;
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.eslintAllCommand = eslintAllCommand;
4
- const tslib_1 = require("tslib");
5
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
- const js_lib_1 = require("@naturalcycles/js-lib");
7
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
9
- const lint_util_1 = require("../util/lint.util");
10
- /**
11
- * Runs `eslint` command for all predefined paths (e.g /src, /scripts, etc).
12
- */
13
- async function eslintAllCommand() {
14
- const started = Date.now();
15
- const { ext, fix } = yargs_1.default.options({
16
- ext: {
17
- type: 'string',
18
- default: 'ts,tsx,vue',
19
- },
20
- fix: {
21
- type: 'boolean',
22
- default: true,
23
- },
24
- }).argv;
25
- const extensions = ext.split(',');
26
- const eslintConfigPathRoot = ['./eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
27
- const eslintConfigPathScripts = ['./scripts/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
28
- const eslintConfigPathE2e = ['./e2e/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
29
- const eslintConfigPathPlaywright = ['./playwright/eslint.config.js', './eslint.config.js'].find(p => node_fs_1.default.existsSync(p));
30
- // const tsconfigPath = getTSConfigPath()
31
- const tsconfigPathScripts = (0, lint_util_1.getTSConfigPathScripts)();
32
- const tsconfigPathE2e = `./e2e/tsconfig.json`;
33
- const tsconfigPathPlaywright = `./playwright/tsconfig.json`;
34
- // todo: run on other dirs too, e.g pages, components, layouts
35
- if (fix) {
36
- await Promise.all([
37
- // /src
38
- (0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix),
39
- // /scripts
40
- (0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix),
41
- // /e2e
42
- (0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix),
43
- // /playwright // todo: remove after migration to e2e folder is completed
44
- (0, lint_util_1.runESLintAsync)(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix),
45
- ]);
46
- }
47
- else {
48
- // with no-fix - let's run serially
49
- // /src
50
- await (0, lint_util_1.runESLintAsync)(`./src`, eslintConfigPathRoot, undefined, extensions, fix);
51
- // /scripts
52
- await (0, lint_util_1.runESLintAsync)(`./scripts`, eslintConfigPathScripts, tsconfigPathScripts, undefined, fix);
53
- // /e2e
54
- await (0, lint_util_1.runESLintAsync)(`./e2e`, eslintConfigPathE2e, tsconfigPathE2e, undefined, fix);
55
- // /e2e
56
- await (0, lint_util_1.runESLintAsync)(`./playwright`, eslintConfigPathPlaywright, tsconfigPathPlaywright, undefined, fix);
57
- }
58
- console.log(`${(0, nodejs_lib_1.boldGrey)('eslint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
59
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Run all linters.
3
- */
4
- export declare function lintAllCommand(): Promise<void>;
@@ -1,97 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.lintAllCommand = lintAllCommand;
4
- const tslib_1 = require("tslib");
5
- const node_child_process_1 = require("node:child_process");
6
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
- const js_lib_1 = require("@naturalcycles/js-lib");
8
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
9
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
10
- const prettier_util_1 = require("../util/prettier.util");
11
- const stylelint_util_1 = require("../util/stylelint.util");
12
- const eslint_all_command_1 = require("./eslint-all.command");
13
- /**
14
- * Run all linters.
15
- */
16
- async function lintAllCommand() {
17
- const started = Date.now();
18
- const { commitOnChanges, failOnChanges } = yargs_1.default.options({
19
- commitOnChanges: {
20
- type: 'boolean',
21
- default: false,
22
- },
23
- failOnChanges: {
24
- type: 'boolean',
25
- default: false,
26
- },
27
- }).argv;
28
- const needToTrackChanges = commitOnChanges || failOnChanges;
29
- const gitStatusAtStart = gitStatus();
30
- if (needToTrackChanges && gitStatusAtStart) {
31
- console.log('lint-all: git shows changes before run:');
32
- console.log(gitStatusAtStart);
33
- }
34
- // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
35
- await (0, eslint_all_command_1.eslintAllCommand)();
36
- if (node_fs_1.default.existsSync(`node_modules/stylelint`) &&
37
- node_fs_1.default.existsSync(`node_modules/stylelint-config-standard-scss`)) {
38
- (0, stylelint_util_1.stylelintAll)();
39
- }
40
- (0, prettier_util_1.runPrettier)();
41
- runActionLint();
42
- await runKTLint();
43
- console.log(`${(0, nodejs_lib_1.boldGrey)('lint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
44
- if (needToTrackChanges) {
45
- const gitStatusAfter = gitStatus();
46
- const hasChanges = gitStatusAfter !== gitStatusAtStart;
47
- if (!hasChanges)
48
- return;
49
- const msg = 'style(ci): ' + (0, js_lib_1._truncate)((0, nodejs_lib_1.commitMessageToTitleMessage)((0, nodejs_lib_1.getLastGitCommitMsg)()), 60);
50
- // pull, commit, push changes
51
- (0, nodejs_lib_1.gitPull)();
52
- (0, nodejs_lib_1.gitCommitAll)(msg);
53
- (0, nodejs_lib_1.gitPush)();
54
- // fail on changes
55
- if (failOnChanges) {
56
- console.log(gitStatusAfter);
57
- console.log('lint-all failOnChanges: exiting with status 1');
58
- process.exitCode = 1;
59
- }
60
- }
61
- }
62
- async function runKTLint() {
63
- if (node_fs_1.default.existsSync(`node_modules/@naturalcycles/ktlint`)) {
64
- const ktlintLib = require('@naturalcycles/ktlint');
65
- await ktlintLib.ktlintAll();
66
- }
67
- }
68
- function runActionLint() {
69
- // Only run if there is a folder of `.github/workflows`, otherwise actionlint will fail
70
- if (!node_fs_1.default.existsSync('.github/workflows'))
71
- return;
72
- if (canRunBinary('actionlint')) {
73
- const started = Date.now();
74
- (0, nodejs_lib_1.execVoidCommandSync)(`actionlint`);
75
- console.log(`${(0, nodejs_lib_1.boldGrey)('actionlint')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
76
- }
77
- else {
78
- 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`);
79
- }
80
- }
81
- function canRunBinary(name) {
82
- try {
83
- (0, node_child_process_1.execSync)(`which ${name}`);
84
- return true;
85
- }
86
- catch {
87
- return false;
88
- }
89
- }
90
- function gitStatus() {
91
- try {
92
- return (0, node_child_process_1.execSync)('git status -s', {
93
- encoding: 'utf8',
94
- });
95
- }
96
- catch { }
97
- }
@@ -1 +0,0 @@
1
- export declare function tscProdCommand(): void;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tscProdCommand = tscProdCommand;
4
- const js_lib_1 = require("@naturalcycles/js-lib");
5
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
6
- function tscProdCommand() {
7
- // You cannot have a shared `tsconfig.prod.json` because of relative paths for `include`
8
- const projectTsconfigPath = `./tsconfig.prod.json`;
9
- const args = ['-P', projectTsconfigPath];
10
- const started = Date.now();
11
- (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
12
- console.log(`${(0, nodejs_lib_1.boldGrey)('tsc prod')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
13
- }
@@ -1,17 +0,0 @@
1
- export declare function getJestConfigPath(): string | undefined;
2
- export declare function getJestIntegrationConfigPath(): string;
3
- export declare function getJestManualConfigPath(): string;
4
- /**
5
- * Detects if jest is run with all tests, or with specific tests.
6
- */
7
- export declare function isRunningAllTests(): boolean;
8
- interface RunJestOpt {
9
- integration?: boolean;
10
- manual?: boolean;
11
- leaks?: boolean;
12
- }
13
- /**
14
- * 1. Adds `--silent` if running all tests at once.
15
- */
16
- export declare function runJest(opt?: RunJestOpt): void;
17
- export {};
@@ -1,4 +0,0 @@
1
- export declare function getTSConfigPath(): string;
2
- export declare function getTSConfigPathScripts(): string;
3
- export declare function runESLint(dir: string, eslintConfigPath: string | undefined, tsconfigPath?: string, extensions?: string[], fix?: boolean): void;
4
- export declare function runESLintAsync(dir: string, eslintConfigPath: string | undefined, tsconfigPath?: string, extensions?: string[], fix?: boolean): Promise<void>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTSConfigPath = getTSConfigPath;
4
- exports.getTSConfigPathScripts = getTSConfigPathScripts;
5
- exports.runESLint = runESLint;
6
- exports.runESLintAsync = runESLintAsync;
7
- const tslib_1 = require("tslib");
8
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
9
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
10
- const paths_cnst_1 = require("../cnst/paths.cnst");
11
- function getTSConfigPath() {
12
- // this is to support "Solution style tsconfig.json" (as used in Angular10, for example)
13
- // return [`./tsconfig.base.json`].find(p => fs.existsSync(p)) || `./tsconfig.json`
14
- return './tsconfig.json';
15
- }
16
- function getTSConfigPathScripts() {
17
- return [`./scripts/tsconfig.json`].find(p => node_fs_1.default.existsSync(p)) || `${paths_cnst_1.scriptsDir}/tsconfig.json`;
18
- }
19
- function runESLint(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
20
- if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
21
- return; // faster to bail-out like this
22
- (0, nodejs_lib_1.execVoidCommandSync)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
23
- }
24
- async function runESLintAsync(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
25
- if (!eslintConfigPath || !node_fs_1.default.existsSync(dir))
26
- return; // faster to bail-out like this
27
- await (0, nodejs_lib_1.execVoidCommand)('eslint', getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions, fix));
28
- }
29
- function getEslintArgs(dir, eslintConfigPath, tsconfigPath, extensions = ['ts', 'tsx', 'vue'], fix = true) {
30
- return [
31
- `--config`,
32
- eslintConfigPath,
33
- `${dir}/**/*.{${extensions.join(',')}}`,
34
- ...(tsconfigPath ? [`--parser-options=project:${tsconfigPath}`] : []),
35
- `--no-error-on-unmatched-pattern`,
36
- `--report-unused-disable-directives`, // todo: unnecessary with flat, as it's defined in the config
37
- fix ? `--fix` : '',
38
- ].filter(Boolean);
39
- }
@@ -1 +0,0 @@
1
- export declare function runPrettier(): void;
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.runPrettier = runPrettier;
4
- const tslib_1 = require("tslib");
5
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
7
- const { prettierDirs, prettierExtensionsAll, lintExclude } = require('../../cfg/_cnst');
8
- const prettierPaths = [
9
- // Everything inside these folders
10
- `./{${prettierDirs}}/**/*.{${prettierExtensionsAll}}`,
11
- // Root
12
- `./*.{${prettierExtensionsAll}}`,
13
- // Exclude
14
- ...lintExclude.map((s) => `!${s}`),
15
- ];
16
- function runPrettier() {
17
- const prettierConfigPath = [`./prettier.config.js`].find(f => node_fs_1.default.existsSync(f));
18
- if (!prettierConfigPath)
19
- return;
20
- // prettier --write 'src/**/*.{js,ts,css,scss,graphql}'
21
- const args = [`--write`, `--log-level=warn`, `--config`, prettierConfigPath, ...prettierPaths];
22
- (0, nodejs_lib_1.execVoidCommandSync)('prettier', args);
23
- }
@@ -1,2 +0,0 @@
1
- export declare const stylelintPaths: any[];
2
- export declare function stylelintAll(): void;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stylelintPaths = void 0;
4
- exports.stylelintAll = stylelintAll;
5
- const tslib_1 = require("tslib");
6
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
7
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
8
- const yargs_1 = tslib_1.__importDefault(require("yargs"));
9
- const { prettierDirs, stylelintExtensions, lintExclude } = require('../../cfg/_cnst');
10
- exports.stylelintPaths = [
11
- // Everything inside these folders
12
- `./{${prettierDirs}}/**/*.{${stylelintExtensions}}`,
13
- // Exclude
14
- ...lintExclude.map((s) => `!${s}`),
15
- ];
16
- function stylelintAll() {
17
- const { fix } = yargs_1.default.options({
18
- fix: {
19
- type: 'boolean',
20
- default: true,
21
- },
22
- }).argv;
23
- const config = [`./stylelint.config.js`].find(f => node_fs_1.default.existsSync(f));
24
- if (!config)
25
- return;
26
- const args = [
27
- fix ? `--fix` : '',
28
- `--allow-empty-input`,
29
- `--config`,
30
- config,
31
- ...exports.stylelintPaths,
32
- ].filter(Boolean);
33
- (0, nodejs_lib_1.execVoidCommandSync)('stylelint', args);
34
- }
@@ -1,4 +0,0 @@
1
- /**
2
- * Returns true if module with given name exists in _target project's_ node_modules.
3
- */
4
- export declare function nodeModuleExists(moduleName: string): boolean;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodeModuleExists = nodeModuleExists;
4
- const tslib_1 = require("tslib");
5
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
6
- /**
7
- * Returns true if module with given name exists in _target project's_ node_modules.
8
- */
9
- function nodeModuleExists(moduleName) {
10
- return node_fs_1.default.existsSync(`./node_modules/${moduleName}`);
11
- }
@@ -1,9 +0,0 @@
1
- export declare function tscMainAndScripts(noEmit?: boolean): Promise<void>;
2
- export declare function tsc(noEmit?: boolean): void;
3
- export declare function tscAsync(noEmit?: boolean): Promise<void>;
4
- export declare function tscScripts(): void;
5
- export declare function tscScriptsAsync(): Promise<void>;
6
- /**
7
- * Returns path to /scripts/tsconfig.json
8
- */
9
- export declare function ensureProjectTsconfigScripts(): string;
@@ -1,67 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tscMainAndScripts = tscMainAndScripts;
4
- exports.tsc = tsc;
5
- exports.tscAsync = tscAsync;
6
- exports.tscScripts = tscScripts;
7
- exports.tscScriptsAsync = tscScriptsAsync;
8
- exports.ensureProjectTsconfigScripts = ensureProjectTsconfigScripts;
9
- const tslib_1 = require("tslib");
10
- const node_fs_1 = tslib_1.__importDefault(require("node:fs"));
11
- const js_lib_1 = require("@naturalcycles/js-lib");
12
- const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
13
- const paths_cnst_1 = require("../cnst/paths.cnst");
14
- async function tscMainAndScripts(noEmit = false) {
15
- await Promise.all([tscAsync(noEmit), tscScriptsAsync()]);
16
- }
17
- function tsc(noEmit = false) {
18
- const started = Date.now();
19
- const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
20
- (0, nodejs_lib_1.execVoidCommandSync)('tsc', args);
21
- console.log(`${(0, nodejs_lib_1.boldGrey)('tsc')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
22
- }
23
- async function tscAsync(noEmit = false) {
24
- const started = Date.now();
25
- const args = [noEmit && '--noEmit'].filter(js_lib_1._isTruthy);
26
- await (0, nodejs_lib_1.execVoidCommand)('tsc', args);
27
- console.log(`${(0, nodejs_lib_1.boldGrey)('tsc')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
28
- }
29
- function tscScripts() {
30
- if (!node_fs_1.default.existsSync('./scripts')) {
31
- // ./scripts folder doesn't exist, skipping
32
- return;
33
- }
34
- const projectTsconfigPath = ensureProjectTsconfigScripts();
35
- const args = ['-P', projectTsconfigPath, '--noEmit'];
36
- const started = Date.now();
37
- (0, nodejs_lib_1.execVoidCommandSync)(`tsc`, args);
38
- console.log(`${(0, nodejs_lib_1.boldGrey)('tsc scripts')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
39
- }
40
- async function tscScriptsAsync() {
41
- if (!node_fs_1.default.existsSync('./scripts')) {
42
- // ./scripts folder doesn't exist, skipping
43
- return;
44
- }
45
- const projectTsconfigPath = ensureProjectTsconfigScripts();
46
- const args = ['-P', projectTsconfigPath, '--noEmit'];
47
- const started = Date.now();
48
- await (0, nodejs_lib_1.execVoidCommand)(`tsc`, args);
49
- console.log(`${(0, nodejs_lib_1.boldGrey)('tsc scripts')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
50
- }
51
- /**
52
- * Returns path to /scripts/tsconfig.json
53
- */
54
- function ensureProjectTsconfigScripts() {
55
- const projectTsconfigPath = `./scripts/tsconfig.json`;
56
- if (!node_fs_1.default.existsSync(projectTsconfigPath)) {
57
- // You cannot just use a shared `tsconfig.scripts.json` because of relative paths for `include`
58
- // So, it will be copied into the project
59
- (0, nodejs_lib_1.kpySync)({
60
- baseDir: `${paths_cnst_1.cfgDir}/init/scripts/`,
61
- inputPatterns: ['tsconfig.json'],
62
- outputDir: './scripts',
63
- });
64
- console.log(`${(0, nodejs_lib_1.boldGrey)('/scripts/tsconfig.json')} file is automatically added`);
65
- }
66
- return projectTsconfigPath;
67
- }
File without changes