@naturalcycles/dev-lib 14.1.1 → 14.1.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.
@@ -25,7 +25,12 @@ async function lintAllCommand() {
25
25
  default: false,
26
26
  },
27
27
  }).argv;
28
- const hadChangesBefore = (0, nodejs_lib_1.gitHasUncommittedChanges)();
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
+ }
29
34
  // We run eslint BEFORE Prettier, because eslint can delete e.g unused imports.
30
35
  await (0, eslint_all_command_1.eslintAllCommand)();
31
36
  if (node_fs_1.default.existsSync(`node_modules/stylelint`) &&
@@ -36,25 +41,21 @@ async function lintAllCommand() {
36
41
  runActionLint();
37
42
  await runKTLint();
38
43
  console.log(`${(0, nodejs_lib_1.boldGrey)('lint-all')} ${(0, nodejs_lib_1.dimGrey)(`took ` + (0, js_lib_1._since)(started))}`);
39
- if (commitOnChanges || failOnChanges) {
40
- // detect changes
41
- const hasChanges = (0, nodejs_lib_1.gitHasUncommittedChanges)();
42
- if (hasChanges) {
43
- if (hadChangesBefore) {
44
- console.log(`lint-all: there are changes before running lint-all, will not commit`);
45
- }
46
- else {
47
- const msg = 'style(ci): ' + (0, js_lib_1._truncate)((0, nodejs_lib_1.commitMessageToTitleMessage)((0, nodejs_lib_1.getLastGitCommitMsg)()), 60);
48
- // pull, commit, push changes
49
- (0, nodejs_lib_1.gitPull)();
50
- (0, nodejs_lib_1.gitCommitAll)(msg);
51
- (0, nodejs_lib_1.gitPush)();
52
- }
53
- // fail on changes
54
- if (failOnChanges) {
55
- console.log('lint-all failOnChanges: exiting with status 1');
56
- process.exitCode = 1;
57
- }
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;
58
59
  }
59
60
  }
60
61
  }
@@ -86,3 +87,11 @@ function canRunBinary(name) {
86
87
  return false;
87
88
  }
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/dev-lib",
3
- "version": "14.1.1",
3
+ "version": "14.1.3",
4
4
  "scripts": {
5
5
  "prepare": "husky",
6
6
  "tsn-debug": "tsn testScript.ts",