wisdom 12.2.0 → 13.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/ChangeLog CHANGED
@@ -1,3 +1,15 @@
1
+ 2022.05.24, v12.2.2
2
+
3
+ fix:
4
+ - wisdom: before commit
5
+
6
+
7
+ 2022.05.24, v12.2.1
8
+
9
+ fix:
10
+ - wisdom: add script
11
+
12
+
1
13
  2022.05.24, v12.2.0
2
14
 
3
15
  feature:
package/lib/parser.js ADDED
@@ -0,0 +1,42 @@
1
+ import jessy from 'jessy';
2
+
3
+ const {isArray} = Array;
4
+
5
+ const maybeArray = (a) => isArray(a) ? a : [a];
6
+
7
+ const paths = [
8
+ 'scripts.wisdom',
9
+ 'scripts.wisdom:type',
10
+ 'changelog',
11
+ ['changelog', false],
12
+ ':version',
13
+ 'scripts:wisdom:build',
14
+ ':commit',
15
+ 'tag',
16
+ ['tag', false],
17
+ ':release',
18
+ '!private',
19
+ 'scripts.wisdom:done',
20
+ ];
21
+
22
+ const check = (info) => (data) => {
23
+ const [path, value = 'any'] = maybeArray(data);
24
+
25
+ if (path.startsWith(':'))
26
+ return true;
27
+
28
+ const result = jessy(path, info);
29
+
30
+ if (path.startsWith('!'))
31
+ return !result;
32
+
33
+ if (value === 'any')
34
+ return Boolean(result);
35
+
36
+ return result === value;
37
+ };
38
+
39
+ export const parse = (info) => {
40
+ return paths.filter(check(info));
41
+ };
42
+
package/lib/runner.js ADDED
@@ -0,0 +1,109 @@
1
+ import {promisify} from 'util';
2
+ import path from 'path';
3
+ import {execSync} from 'child_process';
4
+
5
+ import tryCatch from 'try-catch';
6
+ import tryToCatch from 'try-to-catch';
7
+ import _prepend from 'prepend';
8
+ import versionio from 'version-io';
9
+ import changelog from 'changelog-io';
10
+
11
+ import getEnv from './get-env.js';
12
+ import {release} from './release.js';
13
+ import runWisdom from './run-wisdom.js';
14
+ import {traverse} from './traverse.js';
15
+
16
+ const prepend = promisify(_prepend);
17
+
18
+ export const run = async (paths, params) => {
19
+ const {
20
+ info,
21
+ emitter,
22
+ version,
23
+ chlogStore,
24
+ cmd,
25
+ cmdTag,
26
+ type,
27
+ cwd,
28
+ } = params;
29
+
30
+ const [error] = await tryToCatch(traverse, paths, {
31
+ 'scripts.wisdom': async () => {
32
+ await runWisdom('wisdom', '', version, info, emitter);
33
+ },
34
+ 'scripts.wisdom:type': async () => {
35
+ await runWisdom('wisdom:type', type, version, info, emitter);
36
+ },
37
+ 'changelog:true': async () => {
38
+ const [error, data] = tryCatch(changelog, version);
39
+
40
+ if (error) {
41
+ error.message += '\n';
42
+ throw error;
43
+ }
44
+
45
+ const name = path.join(cwd, 'ChangeLog');
46
+
47
+ await prepend(name, data);
48
+
49
+ const value = rmLines(data, 2);
50
+ chlogStore(value);
51
+ },
52
+ 'changelog:false': () => {
53
+ emitter.emit('data', 'changelog: false\n');
54
+ },
55
+ 'version': async () => {
56
+ await versionio(version);
57
+ },
58
+ 'scripts.wisdom:build': async () => {
59
+ await runWisdom('wisdom:build', '', version, info, emitter);
60
+ },
61
+ 'commit': () => {
62
+ execute(cmd, version, cwd);
63
+ },
64
+ 'tag:true': () => {
65
+ execute(cmdTag, version, cwd);
66
+ },
67
+ 'tag:false': () => {
68
+ emitter.emit('data', 'tag: false\n');
69
+ },
70
+ 'release': async () => {
71
+ await release({
72
+ version,
73
+ info,
74
+ chlog: chlogStore,
75
+ emitter,
76
+ count: info.releaseTriesCount || 10,
77
+ });
78
+ },
79
+ 'publish': () => {
80
+ execute(`npm publish`, version, cwd);
81
+ },
82
+ 'scripts.wisdom:done': async () => {
83
+ await runWisdom('wisdom:done', '', version, info, emitter);
84
+ },
85
+ });
86
+
87
+ if (error)
88
+ emitter.emit('error', error);
89
+
90
+ emitter.emit('exit');
91
+ };
92
+
93
+ function execute(cmd, version, cwd) {
94
+ const stdio = [0, 1, 2, 'pipe'];
95
+
96
+ execSync(cmd, {
97
+ env: getEnv(version),
98
+ cwd,
99
+ stdio,
100
+ });
101
+ }
102
+
103
+ function rmLines(str, count) {
104
+ return str
105
+ .split('\n')
106
+ .slice(count)
107
+ .join('\n');
108
+ }
109
+
@@ -0,0 +1,60 @@
1
+ const {isArray} = Array;
2
+
3
+ const maybeArray = (a) => isArray(a) ? a : [a];
4
+
5
+ export const traverse = async (paths, visitors) => {
6
+ for (const current of paths) {
7
+ const [path, value = true] = maybeArray(current);
8
+
9
+ if (path === 'scripts.wisdom') {
10
+ await visitors['scripts.wisdom']();
11
+ continue;
12
+ }
13
+
14
+ if (path === 'scripts.wisdom:type') {
15
+ await visitors['scripts.wisdom:type']();
16
+ continue;
17
+ }
18
+
19
+ if (path === 'changelog') {
20
+ await visitors[`changelog:${value}`]();
21
+ continue;
22
+ }
23
+
24
+ if (path === ':version') {
25
+ await visitors.version();
26
+ continue;
27
+ }
28
+
29
+ if (path === 'scripts:wisdom:build') {
30
+ await visitors['scripts.wisdom:build']();
31
+ continue;
32
+ }
33
+
34
+ if (path === ':commit') {
35
+ await visitors.commit();
36
+ continue;
37
+ }
38
+
39
+ if (path === 'tag') {
40
+ await visitors[`path:${value}`]();
41
+ continue;
42
+ }
43
+
44
+ if (path === ':release') {
45
+ await visitors.release();
46
+ continue;
47
+ }
48
+
49
+ if (path === '!private') {
50
+ await visitors.publish();
51
+ continue;
52
+ }
53
+
54
+ if (path === 'scripts:wisdom:done') {
55
+ await visitors['scripts.wisdom:done']();
56
+ continue;
57
+ }
58
+ }
59
+ };
60
+
package/lib/wisdom.js CHANGED
@@ -1,30 +1,17 @@
1
- import {promisify} from 'util';
2
1
  import path from 'path';
3
- import {execSync} from 'child_process';
4
2
  import {EventEmitter} from 'events';
5
3
 
6
- import tryCatch from 'try-catch';
7
- import versionio from 'version-io';
8
4
  import changelog from 'changelog-io';
9
5
  import rendy from 'rendy';
10
- import series from 'async/series.js';
11
6
  import minor from 'minor';
12
- import jessy from 'jessy';
13
7
  import {readPackageUp} from 'read-pkg-up';
14
8
  import fullstore from 'fullstore';
15
9
  import currify from 'currify';
16
- import _prepend from 'prepend';
17
10
 
18
11
  import {validatePackage} from './validate-package.js';
19
12
  import {parseCommitType} from './parse-commit-type.js';
20
- import {release} from './release.js';
21
-
22
- const prepend = promisify(_prepend);
23
-
24
- import runWisdom from './run-wisdom.js';
25
- import getEnv from './get-env.js';
26
-
27
- const isUndefined = (a) => typeof a === 'undefined';
13
+ import {parse} from './parser.js';
14
+ import {run} from './runner.js';
28
15
 
29
16
  const Cmd = [
30
17
  'git add --all',
@@ -59,11 +46,11 @@ export default (version) => {
59
46
  emitter.emit('error', error);
60
47
  };
61
48
 
62
- const start = currify((version, emitter, info) => {
49
+ const start = currify(async (version, emitter, info) => {
63
50
  if (validatePackage({version, emitter, info}))
64
51
  return;
65
52
 
66
- publish(version, info, emitter);
53
+ await publish(version, info, emitter);
67
54
  });
68
55
 
69
56
  readPackageUp()
@@ -75,7 +62,7 @@ export default (version) => {
75
62
  return emitter;
76
63
  };
77
64
 
78
- function publish(version, info, emitter) {
65
+ async function publish(version, info, emitter) {
79
66
  let type = '--';
80
67
 
81
68
  if (!version.indexOf('v')) {
@@ -96,125 +83,22 @@ function publish(version, info, emitter) {
96
83
  version,
97
84
  });
98
85
 
99
- series([
100
- async function beforeStart() {
101
- const cmd = jessy('scripts.wisdom', info);
102
-
103
- if (!cmd)
104
- return;
105
-
106
- await runWisdom('wisdom', '', version, info, emitter);
107
- },
108
-
109
- async function beforeStartType() {
110
- const cmd = jessy('scripts.wisdom:type', info);
111
-
112
- if (!cmd)
113
- return;
114
-
115
- await runWisdom('wisdom:type', type, version, info, emitter);
116
- },
117
-
118
- async () => {
119
- if (!isUndefined(info.changelog) && !info.changelog) {
120
- emitter.emit('data', 'changelog: false\n');
121
- return;
122
- }
123
-
124
- const [error, data] = tryCatch(changelog, version);
125
-
126
- if (error) {
127
- error.message += '\n';
128
- throw error;
129
- }
130
-
131
- const name = path.join(InfoDirStore(), 'ChangeLog');
132
-
133
- await prepend(name, data);
134
-
135
- const value = rmLines(data, 2);
136
- chlogStore(value);
137
- },
138
-
139
- async () => {
140
- await versionio(version);
141
- },
142
-
143
- (callback) => {
144
- execute(cmd, version, emitter, callback);
145
- },
146
-
147
- function tag(callback) {
148
- const isNoTag = !info.tag && !isUndefined(info.tag);
149
-
150
- if (isNoTag) {
151
- emitter.emit('data', 'tag: false\n');
152
- return callback();
153
- }
154
-
155
- execute(cmdTag, version, emitter, callback);
156
- },
157
-
158
- async function releaseToGitHub() {
159
- await release({
160
- version,
161
- info,
162
- chlog: chlogStore,
163
- emitter,
164
- count: info.releaseTriesCount || 10,
165
- });
166
- },
167
-
168
- async function build() {
169
- const cmd = jessy('scripts.wisdom:build', info);
170
-
171
- if (!cmd)
172
- return;
173
-
174
- await runWisdom('wisdom:build', '', version, info, emitter);
175
- },
176
-
177
- function npmPublish(callback) {
178
- if (info.private)
179
- return callback();
180
-
181
- execute(`npm publish`, version, emitter, callback);
182
- },
183
-
184
- async function afterPublish() {
185
- const cmd = jessy('scripts.wisdom:done', info);
186
-
187
- if (!cmd)
188
- return;
189
-
190
- await runWisdom('wisdom:done', '', version, info, emitter);
191
- },
192
- ], (error) => {
193
- if (error)
194
- emitter.emit('error', error);
195
-
196
- emitter.emit('exit');
197
- });
198
-
199
- return emitter;
200
- }
201
-
202
- function execute(cmd, version, emitter, callback) {
203
- const stdio = [0, 1, 2, 'pipe'];
86
+ const paths = parse(info);
87
+ const cwd = InfoDirStore();
204
88
 
205
- const [e] = tryCatch(execSync, cmd, {
206
- env: getEnv(version),
207
- cwd: InfoDirStore(),
208
- stdio,
89
+ await run(paths, {
90
+ type,
91
+ changelog,
92
+ cwd,
93
+ info,
94
+ emitter,
95
+ version,
96
+ chlogStore,
97
+ cmd,
98
+ cmdTag,
99
+ InfoDirStore,
209
100
  });
210
101
 
211
- callback(e);
212
- }
213
-
214
- function rmLines(str, count) {
215
- return str
216
- .split('\n')
217
- .slice(count)
218
- .join('\n');
102
+ return emitter;
219
103
  }
220
104
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wisdom",
3
- "version": "12.2.0",
3
+ "version": "13.0.0",
4
4
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
5
5
  "description": "configurable publish releases to github and npm",
6
6
  "homepage": "http://github.com/coderaiser/wisdom",
@@ -24,6 +24,7 @@
24
24
  "major": "madrun major",
25
25
  "wisdom:type": "madrun wisdom:type",
26
26
  "wisdom:done": "madrun wisdom:done",
27
+ "wisdom:build": "madrun wisdom:build",
27
28
  "lint": "madrun lint",
28
29
  "fix:lint": "madrun fix:lint"
29
30
  },