@naturalcycles/dev-lib 13.28.2 → 13.29.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/cfg/eslint-rules.js +1 -0
- package/dist/bin/commitlint-def.js +2 -2
- package/dist/cmd/lint-all.command.js +7 -7
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/package.json +2 -4
- package/readme.md +0 -3
- package/dist/bin/generate-build-info.d.ts +0 -2
- package/dist/bin/generate-build-info.js +0 -6
- package/dist/cmd/generate-build-info.command.d.ts +0 -1
- package/dist/cmd/generate-build-info.command.js +0 -22
- package/dist/util/buildInfo.util.d.ts +0 -2
- package/dist/util/buildInfo.util.js +0 -27
- package/dist/util/git.util.d.ts +0 -18
- package/dist/util/git.util.js +0 -109
package/cfg/eslint-rules.js
CHANGED
|
@@ -168,6 +168,7 @@ module.exports = {
|
|
|
168
168
|
],
|
|
169
169
|
'id-match': 2,
|
|
170
170
|
'import/order': 2,
|
|
171
|
+
'import/no-anonymous-default-export': 2,
|
|
171
172
|
// 'import/namespace': 0, // issues with e.g globby
|
|
172
173
|
// 'import/no-unresolved': 0, // breaks for type-aliases, e.g '@/store'
|
|
173
174
|
// 'import/no-duplicates': 0,
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const cp = require("node:child_process");
|
|
5
5
|
const fs = require("node:fs");
|
|
6
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
6
7
|
const paths_cnst_1 = require("../cnst/paths.cnst");
|
|
7
|
-
const git_util_1 = require("../util/git.util");
|
|
8
8
|
const editMsg = process.argv[process.argv.length - 1] || '.git/COMMIT_EDITMSG';
|
|
9
9
|
// console.log(editMsg)
|
|
10
10
|
const cwd = process.cwd();
|
|
@@ -13,7 +13,7 @@ const sharedConfig = `${paths_cnst_1.cfgDir}/commitlint.config.js`;
|
|
|
13
13
|
const config = fs.existsSync(localConfig) ? localConfig : sharedConfig;
|
|
14
14
|
const env = {
|
|
15
15
|
...process.env,
|
|
16
|
-
GIT_BRANCH: (0,
|
|
16
|
+
GIT_BRANCH: (0, nodejs_lib_1.gitCurrentBranchName)(),
|
|
17
17
|
};
|
|
18
18
|
// await execWithArgs(`commitlint`, [`--edit`, editMsg, `--config`, config], { env })
|
|
19
19
|
execSync(`node ./node_modules/.bin/commitlint --edit ${editMsg} --config ${config}`, {
|
|
@@ -4,7 +4,7 @@ exports.lintAllCommand = void 0;
|
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
6
6
|
const yargs = require("yargs");
|
|
7
|
-
const
|
|
7
|
+
const nodejs_lib_1 = require("@naturalcycles/nodejs-lib");
|
|
8
8
|
const prettier_util_1 = require("../util/prettier.util");
|
|
9
9
|
const stylelint_util_1 = require("../util/stylelint.util");
|
|
10
10
|
const eslint_all_command_1 = require("./eslint-all.command");
|
|
@@ -22,7 +22,7 @@ async function lintAllCommand() {
|
|
|
22
22
|
default: false,
|
|
23
23
|
},
|
|
24
24
|
}).argv;
|
|
25
|
-
const hadChangesBefore = (0,
|
|
25
|
+
const hadChangesBefore = (0, nodejs_lib_1.gitHasUncommittedChanges)();
|
|
26
26
|
(0, eslint_all_command_1.eslintAllCommand)();
|
|
27
27
|
if (fs.existsSync(`node_modules/stylelint`) &&
|
|
28
28
|
fs.existsSync(`node_modules/stylelint-config-standard-scss`)) {
|
|
@@ -35,19 +35,19 @@ async function lintAllCommand() {
|
|
|
35
35
|
}
|
|
36
36
|
if (commitOnChanges || failOnChanges) {
|
|
37
37
|
// detect changes
|
|
38
|
-
const hasChanges = (0,
|
|
38
|
+
const hasChanges = (0, nodejs_lib_1.gitHasUncommittedChanges)();
|
|
39
39
|
if (hasChanges) {
|
|
40
40
|
if (hadChangesBefore) {
|
|
41
41
|
console.log(`lint-all: there are changes before running lint-all, will not commit`);
|
|
42
42
|
}
|
|
43
43
|
else {
|
|
44
44
|
const msg = 'style(ci): ' +
|
|
45
|
-
(0, js_lib_1._truncate)((0,
|
|
45
|
+
(0, js_lib_1._truncate)((0, nodejs_lib_1.commitMessageToTitleMessage)((0, nodejs_lib_1.getLastGitCommitMsg)()), 60) +
|
|
46
46
|
'\n\n[skip ci]';
|
|
47
47
|
// pull, commit, push changes
|
|
48
|
-
(0,
|
|
49
|
-
(0,
|
|
50
|
-
(0,
|
|
48
|
+
(0, nodejs_lib_1.gitPull)();
|
|
49
|
+
(0, nodejs_lib_1.gitCommitAll)(msg);
|
|
50
|
+
(0, nodejs_lib_1.gitPush)();
|
|
51
51
|
}
|
|
52
52
|
// fail on changes
|
|
53
53
|
if (failOnChanges) {
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -2,5 +2,3 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
4
|
tslib_1.__exportStar(require("./cmd/build-prod.command"), exports);
|
|
5
|
-
tslib_1.__exportStar(require("./util/buildInfo.util"), exports);
|
|
6
|
-
tslib_1.__exportStar(require("./util/git.util"), exports);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/dev-lib",
|
|
3
|
-
"version": "13.
|
|
3
|
+
"version": "13.29.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky install",
|
|
6
6
|
"tsn-debug": "tsn testScript.ts",
|
|
@@ -12,7 +12,6 @@
|
|
|
12
12
|
"build-copy": "tsn ./src/bin/build-copy.ts",
|
|
13
13
|
"build-prod": "tsn ./src/bin/build-prod.ts",
|
|
14
14
|
"build-prod-esm-cjs": "tsn ./src/bin/build-prod-esm-cjs.ts",
|
|
15
|
-
"generate-build-info": "tsn ./src/bin/generate-build-info.ts",
|
|
16
15
|
"test": "tsn ./src/bin/test.ts",
|
|
17
16
|
"test-ci": "tsn ./src/bin/test-ci.ts",
|
|
18
17
|
"test-leaks": "tsn ./src/bin/test-leaks.ts",
|
|
@@ -61,7 +60,7 @@
|
|
|
61
60
|
"devDependencies": {
|
|
62
61
|
"jest": "^29.0.0",
|
|
63
62
|
"stylelint": "^15.0.0",
|
|
64
|
-
"stylelint-config-standard-scss": "^
|
|
63
|
+
"stylelint-config-standard-scss": "^10.0.0"
|
|
65
64
|
},
|
|
66
65
|
"files": [
|
|
67
66
|
"dist",
|
|
@@ -80,7 +79,6 @@
|
|
|
80
79
|
"build-prod-esm-cjs": "dist/bin/build-prod-esm-cjs.js",
|
|
81
80
|
"commitlint-def": "dist/bin/commitlint-def.js",
|
|
82
81
|
"eslint-all": "dist/bin/eslint-all.js",
|
|
83
|
-
"generate-build-info": "dist/bin/generate-build-info.js",
|
|
84
82
|
"init-from-dev-lib": "dist/bin/init-from-dev-lib.js",
|
|
85
83
|
"lint-all": "dist/bin/lint-all.js",
|
|
86
84
|
"lint-staged-def": "dist/bin/lint-staged-def.js",
|
package/readme.md
CHANGED
|
@@ -170,9 +170,6 @@ Install it **locally** in you project by adding
|
|
|
170
170
|
|
|
171
171
|
- `init-from-dev-lib`: copy config files from `dev-lib/cfg/init` to the project
|
|
172
172
|
- `update-from-dev-lib`: copy config files from `dev-lib/cfg/overwrite` to the project
|
|
173
|
-
- `generate-build-info`: generate `buildInfo.json`
|
|
174
|
-
- `--dir <someDir>` will save it to given dir
|
|
175
|
-
- `--shell` will also generate `buildInfo.sh`
|
|
176
173
|
|
|
177
174
|
## Non-extendable config files
|
|
178
175
|
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
const script_1 = require("@naturalcycles/nodejs-lib/dist/script");
|
|
5
|
-
const generate_build_info_command_1 = require("../cmd/generate-build-info.command");
|
|
6
|
-
(0, script_1.runScript)(generate_build_info_command_1.generateBuildInfoCommand);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function generateBuildInfoCommand(): void;
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateBuildInfoCommand = void 0;
|
|
4
|
-
const fs = require("node:fs");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const yargs = require("yargs");
|
|
7
|
-
const __1 = require("..");
|
|
8
|
-
function generateBuildInfoCommand() {
|
|
9
|
-
const { dir } = yargs.options({
|
|
10
|
-
dir: {
|
|
11
|
-
type: 'string',
|
|
12
|
-
desc: 'Output directory',
|
|
13
|
-
},
|
|
14
|
-
}).argv;
|
|
15
|
-
const buildInfo = (0, __1.generateBuildInfo)();
|
|
16
|
-
console.log(buildInfo);
|
|
17
|
-
if (dir)
|
|
18
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
19
|
-
const buildInfoPath = dir ? path.resolve(dir, 'buildInfo.json') : 'buildInfo.json';
|
|
20
|
-
fs.writeFileSync(buildInfoPath, JSON.stringify(buildInfo, null, 2));
|
|
21
|
-
}
|
|
22
|
-
exports.generateBuildInfoCommand = generateBuildInfoCommand;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateBuildInfo = void 0;
|
|
4
|
-
const js_lib_1 = require("@naturalcycles/js-lib");
|
|
5
|
-
const git_util_1 = require("./git.util");
|
|
6
|
-
function generateBuildInfo() {
|
|
7
|
-
const { APP_ENV } = process.env;
|
|
8
|
-
const now = (0, js_lib_1.localTime)();
|
|
9
|
-
const ts = now.unix();
|
|
10
|
-
const tsStr = now.toPretty();
|
|
11
|
-
const rev = (0, git_util_1.gitCurrentCommitSha)();
|
|
12
|
-
const branchName = (0, git_util_1.gitCurrentBranchName)();
|
|
13
|
-
const repoName = (0, git_util_1.gitCurrentRepoName)();
|
|
14
|
-
const tsCommit = (0, git_util_1.gitCurrentCommitTimestamp)();
|
|
15
|
-
const ver = [now.toStringCompact(), repoName, branchName, rev].join('_');
|
|
16
|
-
return (0, js_lib_1._filterUndefinedValues)({
|
|
17
|
-
ts,
|
|
18
|
-
tsCommit,
|
|
19
|
-
tsStr,
|
|
20
|
-
repoName,
|
|
21
|
-
branchName,
|
|
22
|
-
rev,
|
|
23
|
-
ver,
|
|
24
|
-
env: APP_ENV,
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.generateBuildInfo = generateBuildInfo;
|
package/dist/util/git.util.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { UnixTimestampNumber } from '@naturalcycles/js-lib';
|
|
2
|
-
export declare function getLastGitCommitMsg(): string;
|
|
3
|
-
export declare function commitMessageToTitleMessage(msg: string): string;
|
|
4
|
-
export declare function gitHasUncommittedChanges(): boolean;
|
|
5
|
-
/**
|
|
6
|
-
* @returns true if there were changes
|
|
7
|
-
*/
|
|
8
|
-
export declare function gitCommitAll(msg: string): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* @returns true if there are not pushed commits.
|
|
11
|
-
*/
|
|
12
|
-
export declare function gitIsAhead(): boolean;
|
|
13
|
-
export declare function gitPull(): void;
|
|
14
|
-
export declare function gitPush(): void;
|
|
15
|
-
export declare function gitCurrentCommitSha(full?: boolean): string;
|
|
16
|
-
export declare function gitCurrentCommitTimestamp(): UnixTimestampNumber;
|
|
17
|
-
export declare function gitCurrentBranchName(): string;
|
|
18
|
-
export declare function gitCurrentRepoName(): string;
|
package/dist/util/git.util.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gitCurrentRepoName = exports.gitCurrentBranchName = exports.gitCurrentCommitTimestamp = exports.gitCurrentCommitSha = exports.gitPush = exports.gitPull = exports.gitIsAhead = exports.gitCommitAll = exports.gitHasUncommittedChanges = exports.commitMessageToTitleMessage = exports.getLastGitCommitMsg = void 0;
|
|
4
|
-
const cp = require("node:child_process");
|
|
5
|
-
const path = require("node:path");
|
|
6
|
-
const colors_1 = require("@naturalcycles/nodejs-lib/dist/colors");
|
|
7
|
-
function getLastGitCommitMsg() {
|
|
8
|
-
return execSync('git log -1 --pretty=%B');
|
|
9
|
-
}
|
|
10
|
-
exports.getLastGitCommitMsg = getLastGitCommitMsg;
|
|
11
|
-
function commitMessageToTitleMessage(msg) {
|
|
12
|
-
const firstLine = msg.split('\n')[0];
|
|
13
|
-
const [preTitle, title] = firstLine.split(': ');
|
|
14
|
-
return title || preTitle;
|
|
15
|
-
}
|
|
16
|
-
exports.commitMessageToTitleMessage = commitMessageToTitleMessage;
|
|
17
|
-
function gitHasUncommittedChanges() {
|
|
18
|
-
// git diff-index --quiet HEAD -- || echo "untracked"
|
|
19
|
-
try {
|
|
20
|
-
cp.execSync('git diff-index --quiet HEAD --', {
|
|
21
|
-
encoding: 'utf8',
|
|
22
|
-
});
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
catch {
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.gitHasUncommittedChanges = gitHasUncommittedChanges;
|
|
30
|
-
/**
|
|
31
|
-
* @returns true if there were changes
|
|
32
|
-
*/
|
|
33
|
-
function gitCommitAll(msg) {
|
|
34
|
-
// git commit -a -m "style(lint-all): $GIT_MSG" || true
|
|
35
|
-
const cmd = `git commit -a --no-verify -m "${msg}"`;
|
|
36
|
-
// const cmd = `git`
|
|
37
|
-
// const args = ['commit', '-a', '--no-verify', '-m', msg]
|
|
38
|
-
console.log((0, colors_1.grey)(cmd));
|
|
39
|
-
try {
|
|
40
|
-
cp.execSync(cmd, {
|
|
41
|
-
stdio: 'inherit',
|
|
42
|
-
});
|
|
43
|
-
return true;
|
|
44
|
-
}
|
|
45
|
-
catch {
|
|
46
|
-
return false;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
exports.gitCommitAll = gitCommitAll;
|
|
50
|
-
/**
|
|
51
|
-
* @returns true if there are not pushed commits.
|
|
52
|
-
*/
|
|
53
|
-
function gitIsAhead() {
|
|
54
|
-
// ahead=`git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`
|
|
55
|
-
const cmd = `git rev-list HEAD --not --remotes | wc -l | awk '{print $1}'`;
|
|
56
|
-
const stdout = execSync(cmd);
|
|
57
|
-
// console.log(`gitIsAhead: ${stdout}`)
|
|
58
|
-
return Number(stdout) > 0;
|
|
59
|
-
}
|
|
60
|
-
exports.gitIsAhead = gitIsAhead;
|
|
61
|
-
function gitPull() {
|
|
62
|
-
const cmd = 'git pull';
|
|
63
|
-
try {
|
|
64
|
-
cp.execSync(cmd, {
|
|
65
|
-
stdio: 'inherit',
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
catch { }
|
|
69
|
-
}
|
|
70
|
-
exports.gitPull = gitPull;
|
|
71
|
-
function gitPush() {
|
|
72
|
-
// git push --set-upstream origin $CIRCLE_BRANCH && echo "pushed, exiting" && exit 0
|
|
73
|
-
let cmd = 'git push';
|
|
74
|
-
const branchName = gitCurrentBranchName();
|
|
75
|
-
if (branchName) {
|
|
76
|
-
cmd += ` --set-upstream origin ${branchName}`;
|
|
77
|
-
}
|
|
78
|
-
console.log((0, colors_1.grey)(cmd));
|
|
79
|
-
cp.execSync(cmd, {
|
|
80
|
-
stdio: 'inherit',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
exports.gitPush = gitPush;
|
|
84
|
-
function gitCurrentCommitSha(full = false) {
|
|
85
|
-
const sha = execSync('git rev-parse HEAD');
|
|
86
|
-
return full ? sha : sha.slice(0, 7);
|
|
87
|
-
}
|
|
88
|
-
exports.gitCurrentCommitSha = gitCurrentCommitSha;
|
|
89
|
-
function gitCurrentCommitTimestamp() {
|
|
90
|
-
return Number(execSync('git log -1 --format=%ct'));
|
|
91
|
-
}
|
|
92
|
-
exports.gitCurrentCommitTimestamp = gitCurrentCommitTimestamp;
|
|
93
|
-
function gitCurrentBranchName() {
|
|
94
|
-
return execSync('git rev-parse --abbrev-ref HEAD');
|
|
95
|
-
}
|
|
96
|
-
exports.gitCurrentBranchName = gitCurrentBranchName;
|
|
97
|
-
function gitCurrentRepoName() {
|
|
98
|
-
const originUrl = execSync('git config --get remote.origin.url');
|
|
99
|
-
return path.basename(originUrl, '.git');
|
|
100
|
-
}
|
|
101
|
-
exports.gitCurrentRepoName = gitCurrentRepoName;
|
|
102
|
-
function execSync(cmd) {
|
|
103
|
-
return cp
|
|
104
|
-
.execSync(cmd, {
|
|
105
|
-
encoding: 'utf8',
|
|
106
|
-
// stdio: 'inherit', // no, otherwise we don't get the output returned
|
|
107
|
-
})
|
|
108
|
-
.trim();
|
|
109
|
-
}
|