wisdom 12.2.1 → 13.0.1
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 +6 -0
- package/bin/wisdom.js +8 -1
- package/json/bin.json +1 -0
- package/lib/parser.js +42 -0
- package/lib/runner.js +109 -0
- package/lib/traverse.js +60 -0
- package/lib/wisdom.js +30 -135
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/bin/wisdom.js
CHANGED
|
@@ -17,12 +17,19 @@ if (!arg || /^(-h|--help)$/.test(arg)) {
|
|
|
17
17
|
process.exit();
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
if (/^(-v|--v)$/.test(arg)) {
|
|
21
|
+
version();
|
|
22
|
+
process.exit();
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
if (!/^(patch|minor|major)$/.test(arg)) {
|
|
21
26
|
console.error(`'%s' is not a wisdom option. See 'wisdom --help'`, arg);
|
|
22
27
|
process.exit();
|
|
23
28
|
}
|
|
24
29
|
|
|
25
|
-
|
|
30
|
+
const dryRun = arg.includes('--dry-run');
|
|
31
|
+
|
|
32
|
+
wisdom(arg, {dryRun})
|
|
26
33
|
.on('data', (a) => {
|
|
27
34
|
process.stdout.write(a);
|
|
28
35
|
})
|
package/json/bin.json
CHANGED
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
|
+
'wisdom': async () => {
|
|
32
|
+
await runWisdom('wisdom', '', version, info, emitter);
|
|
33
|
+
},
|
|
34
|
+
'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
|
+
'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
|
+
'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
|
+
|
package/lib/traverse.js
ADDED
|
@@ -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.wisdom();
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (path === 'scripts.wisdom:type') {
|
|
15
|
+
await visitors.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.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.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 {
|
|
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',
|
|
@@ -51,7 +38,7 @@ const setInfoDir = (data) => {
|
|
|
51
38
|
|
|
52
39
|
const getPkg = (data) => data.packageJson;
|
|
53
40
|
|
|
54
|
-
export default (version) => {
|
|
41
|
+
export default (version, {dryRun}) => {
|
|
55
42
|
const emitter = new EventEmitter();
|
|
56
43
|
|
|
57
44
|
const onError = (e) => {
|
|
@@ -59,11 +46,16 @@ 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(
|
|
53
|
+
await publish({
|
|
54
|
+
version,
|
|
55
|
+
info,
|
|
56
|
+
emitter,
|
|
57
|
+
dryRun,
|
|
58
|
+
});
|
|
67
59
|
});
|
|
68
60
|
|
|
69
61
|
readPackageUp()
|
|
@@ -75,7 +67,7 @@ export default (version) => {
|
|
|
75
67
|
return emitter;
|
|
76
68
|
};
|
|
77
69
|
|
|
78
|
-
function publish(version, info, emitter) {
|
|
70
|
+
async function publish({version, info, emitter, dryRun}) {
|
|
79
71
|
let type = '--';
|
|
80
72
|
|
|
81
73
|
if (!version.indexOf('v')) {
|
|
@@ -96,125 +88,28 @@ function publish(version, info, emitter) {
|
|
|
96
88
|
version,
|
|
97
89
|
});
|
|
98
90
|
|
|
99
|
-
|
|
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
|
-
});
|
|
91
|
+
const paths = parse(info);
|
|
198
92
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const stdio = [0, 1, 2, 'pipe'];
|
|
93
|
+
if (dryRun) {
|
|
94
|
+
emitter.emit('data', paths.join('\n'));
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
204
97
|
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
98
|
+
const cwd = InfoDirStore();
|
|
99
|
+
|
|
100
|
+
await run(paths, {
|
|
101
|
+
type,
|
|
102
|
+
changelog,
|
|
103
|
+
cwd,
|
|
104
|
+
info,
|
|
105
|
+
emitter,
|
|
106
|
+
version,
|
|
107
|
+
chlogStore,
|
|
108
|
+
cmd,
|
|
109
|
+
cmdTag,
|
|
110
|
+
InfoDirStore,
|
|
209
111
|
});
|
|
210
112
|
|
|
211
|
-
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function rmLines(str, count) {
|
|
215
|
-
return str
|
|
216
|
-
.split('\n')
|
|
217
|
-
.slice(count)
|
|
218
|
-
.join('\n');
|
|
113
|
+
return emitter;
|
|
219
114
|
}
|
|
220
115
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wisdom",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "13.0.1",
|
|
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",
|