@naturalcycles/dev-lib 13.28.1 → 13.28.3

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.
@@ -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, git_util_1.gitCurrentBranchName)(),
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 git_util_1 = require("../util/git.util");
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, git_util_1.gitHasUncommittedChanges)();
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, git_util_1.gitHasUncommittedChanges)();
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, git_util_1.commitMessageToTitleMessage)((0, git_util_1.getLastGitCommitMsg)()), 60) +
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, git_util_1.gitPull)();
49
- (0, git_util_1.gitCommitAll)(msg);
50
- (0, git_util_1.gitPush)();
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
@@ -1,4 +1 @@
1
1
  export * from './cmd/build-prod.command';
2
- export * from './util/buildInfo.model';
3
- export * from './util/buildInfo.util';
4
- export * from './util/git.util';
package/dist/index.js CHANGED
@@ -2,6 +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.model"), exports);
6
- tslib_1.__exportStar(require("./util/buildInfo.util"), exports);
7
- 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.28.1",
3
+ "version": "13.28.3",
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",
@@ -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,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 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,40 +0,0 @@
1
- import { UnixTimestampNumber } from '@naturalcycles/js-lib';
2
- export interface BuildInfo {
3
- /**
4
- * Unix timestamp of when the build was made.
5
- */
6
- ts: UnixTimestampNumber;
7
- /**
8
- * Unix timestamp of commit ("committer date", not "author date")
9
- */
10
- tsCommit: UnixTimestampNumber;
11
- /**
12
- * Human-readable time of the build. E.g:
13
- * 2019-06-21 18:35:19
14
- */
15
- tsStr: string;
16
- repoName: string;
17
- branchName: string;
18
- /**
19
- * GIT sha revision (first 7 characters)
20
- */
21
- rev: string;
22
- /**
23
- * "Version string" in the following format:
24
- * yyyyMMdd_HHmm_$repoName_$branch_$rev
25
- *
26
- * E.g:
27
- * 20190419_1728_myrepo_master_21aecf5
28
- */
29
- ver: string;
30
- /**
31
- * Build during development.
32
- */
33
- dev?: boolean;
34
- /**
35
- * Build "environment".
36
- * Normally taken from process.env.APP_ENV
37
- * Can be undefined.
38
- */
39
- env?: string;
40
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- import type { BuildInfo } from './buildInfo.model';
2
- export declare function generateBuildInfo(): BuildInfo;
@@ -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 {
17
- ts,
18
- tsCommit,
19
- tsStr,
20
- repoName,
21
- branchName,
22
- rev,
23
- ver,
24
- env: APP_ENV,
25
- };
26
- }
27
- exports.generateBuildInfo = generateBuildInfo;
@@ -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;
@@ -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
- }