create-pkgbld 1.2.0 → 1.3.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/dist/index.cjs +156 -55
- package/dist/index.mjs +156 -55
- package/dist/types.d.ts +13 -0
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -7,77 +7,176 @@ var fs = require('fs/promises');
|
|
|
7
7
|
var userName = require('git-user-name');
|
|
8
8
|
var gitConfig = require('parse-git-config');
|
|
9
9
|
var minimist = require('minimist');
|
|
10
|
+
var kleur = require('kleur');
|
|
10
11
|
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
11
13
|
async function execute() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const parsedArgs = minimist(process.argv.slice(2));
|
|
18
|
-
const targetDir = path.join(process.cwd(), parsedArgs._[0] ?? '.');
|
|
14
|
+
await reportVersion();
|
|
15
|
+
const targetDir = getTargetDir();
|
|
16
|
+
console.log(kleur.grey(pad16plus('Target Directory', 0)) + kleur.white(targetDir));
|
|
17
|
+
const pkg = await readPackage(targetDir);
|
|
18
|
+
console.log(kleur.grey(pad16plus('Mode', 0)) + kleur.white(pkg.mode));
|
|
19
19
|
const packageName = path.basename(targetDir);
|
|
20
20
|
let cancelled = false;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
21
|
+
const options = getBasicOptions(packageName);
|
|
22
|
+
options.push(...await getGitOptions(packageName));
|
|
23
|
+
const state = getOptionsValue(options);
|
|
24
|
+
for (;;) {
|
|
25
|
+
const topLevelAction = await prompts({
|
|
26
|
+
type: 'select',
|
|
27
|
+
name: 'value',
|
|
28
|
+
message: 'Select an option to change, Done to execute, Ctrl+C to cancel',
|
|
29
|
+
choices: [
|
|
30
|
+
{ title: kleur.green('Done'), description: `${pkg.mode === 'update' ? 'Update' : 'Create'} package`, value: 'done' },
|
|
31
|
+
...options.map(mapOption(state))
|
|
32
|
+
],
|
|
33
|
+
initial: 0
|
|
34
|
+
}, { onCancel });
|
|
35
|
+
if (cancelled) {
|
|
36
|
+
process.exit(-1);
|
|
37
|
+
}
|
|
38
|
+
if (topLevelAction.value === 'done') {
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
let option = options.find(item => item.field === topLevelAction.value);
|
|
42
|
+
let mutateObject = state;
|
|
43
|
+
if ('items' in option) {
|
|
44
|
+
const nextLevelAction = await prompts([{
|
|
45
|
+
type: 'select',
|
|
46
|
+
name: 'value',
|
|
47
|
+
message: option.title,
|
|
48
|
+
choices: option.items.map(mapOption(state[option.field]))
|
|
49
|
+
}], { onCancel });
|
|
50
|
+
if (cancelled) {
|
|
51
|
+
process.exit(-1);
|
|
52
|
+
}
|
|
53
|
+
if (option.mutateInnerObject) {
|
|
54
|
+
mutateObject = state[option.field];
|
|
55
|
+
}
|
|
56
|
+
option = option.items.find(item => item.field === nextLevelAction.value);
|
|
57
|
+
}
|
|
58
|
+
const action = await prompts([{
|
|
59
|
+
type: 'text',
|
|
60
|
+
name: option.field,
|
|
61
|
+
message: option.title,
|
|
62
|
+
initial: state[option.field]
|
|
63
|
+
}], { onCancel });
|
|
64
|
+
if (cancelled) {
|
|
65
|
+
process.exit(-1);
|
|
66
|
+
}
|
|
67
|
+
mutateObject[option.field] = action[option.field];
|
|
68
|
+
}
|
|
47
69
|
if (cancelled) {
|
|
48
70
|
process.exit(-1);
|
|
49
71
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
72
|
+
Object.assign(pkg.pkg, state);
|
|
73
|
+
pkg.readme ??= `# ${state.name}`;
|
|
74
|
+
await writePackage(targetDir, pkg);
|
|
75
|
+
function onCancel() {
|
|
76
|
+
cancelled = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
execute();
|
|
80
|
+
function mapOption(state) {
|
|
81
|
+
return (option) => {
|
|
82
|
+
const fieldValue = state[option.field];
|
|
83
|
+
return {
|
|
84
|
+
title: pad16plus(option.title) + kleur.magenta('items' in option ? viewObject(option.items, fieldValue) : fieldValue),
|
|
85
|
+
value: option.field
|
|
86
|
+
};
|
|
54
87
|
};
|
|
88
|
+
}
|
|
89
|
+
function viewObject(items, json) {
|
|
90
|
+
return items
|
|
91
|
+
.map(item => kleur.grey(item.title) + ' ' + kleur.white(json[item.field]))
|
|
92
|
+
.join(', ');
|
|
93
|
+
}
|
|
94
|
+
function getOptionsValue(options) {
|
|
95
|
+
return options.reduce((accumulator, item) => ({
|
|
96
|
+
...accumulator,
|
|
97
|
+
[item.field]: 'items' in item ? getOptionsValue(item.items) : item.initialValue
|
|
98
|
+
}), {});
|
|
99
|
+
}
|
|
100
|
+
async function reportVersion() {
|
|
101
|
+
const createPkgBldPackage = await readPackage(path.resolve(__dirname, '..'));
|
|
102
|
+
console.log(kleur.grey(pad16plus('create-pkgbld', 0)) + kleur.white('v' + createPkgBldPackage.pkg.version));
|
|
103
|
+
}
|
|
104
|
+
function getTargetDir() {
|
|
105
|
+
const parsedArgs = minimist(process.argv.slice(2));
|
|
106
|
+
const targetDir = path.join(process.cwd(), parsedArgs._[0] ?? '.');
|
|
107
|
+
return targetDir;
|
|
108
|
+
}
|
|
109
|
+
async function getGitOptions(packageName) {
|
|
110
|
+
const options = [];
|
|
55
111
|
try {
|
|
56
112
|
const gitCfg = await gitConfig();
|
|
57
113
|
if (gitCfg) {
|
|
58
114
|
const url = gitCfg['remote "origin"'].url;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
115
|
+
options.push({
|
|
116
|
+
title: 'Homepage',
|
|
117
|
+
field: 'homepage',
|
|
118
|
+
initialValue: url.replace('.git', `/blob/main/${packageName}/README.md`)
|
|
119
|
+
});
|
|
120
|
+
options.push({
|
|
121
|
+
title: 'Repository',
|
|
122
|
+
field: 'repository',
|
|
123
|
+
items: [{
|
|
124
|
+
title: 'Type',
|
|
125
|
+
field: 'type',
|
|
126
|
+
initialValue: 'git'
|
|
127
|
+
}, {
|
|
128
|
+
title: 'Url',
|
|
129
|
+
field: 'url',
|
|
130
|
+
initialValue: `git+${url}`
|
|
131
|
+
}],
|
|
132
|
+
mutateInnerObject: true
|
|
133
|
+
});
|
|
134
|
+
options.push({
|
|
135
|
+
title: 'Bugs',
|
|
136
|
+
field: 'bugs',
|
|
137
|
+
initialValue: url.replace('.git', '/issues')
|
|
138
|
+
});
|
|
67
139
|
}
|
|
68
140
|
}
|
|
69
141
|
catch (e) {
|
|
70
142
|
/* ignore */
|
|
71
143
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
144
|
+
return options;
|
|
145
|
+
}
|
|
146
|
+
function getBasicOptions(packageName) {
|
|
147
|
+
return [{
|
|
148
|
+
title: 'Package Name',
|
|
149
|
+
field: 'name',
|
|
150
|
+
initialValue: packageName
|
|
151
|
+
}, {
|
|
152
|
+
title: 'Version',
|
|
153
|
+
field: 'version',
|
|
154
|
+
initialValue: '0.0.1'
|
|
155
|
+
}, {
|
|
156
|
+
title: 'Description',
|
|
157
|
+
field: 'description',
|
|
158
|
+
initialValue: ''
|
|
159
|
+
}, {
|
|
160
|
+
title: 'License',
|
|
161
|
+
field: 'license',
|
|
162
|
+
initialValue: 'MIT'
|
|
163
|
+
}, {
|
|
164
|
+
title: 'Author',
|
|
165
|
+
field: 'author',
|
|
166
|
+
initialValue: userName() ?? ''
|
|
167
|
+
}, {
|
|
168
|
+
title: 'Destination folder',
|
|
169
|
+
field: 'dest',
|
|
170
|
+
initialValue: 'dest'
|
|
171
|
+
}, {
|
|
172
|
+
title: 'Source folder',
|
|
173
|
+
field: 'src',
|
|
174
|
+
initialValue: 'src'
|
|
175
|
+
}];
|
|
176
|
+
}
|
|
177
|
+
function pad16plus(value, indent = 4, offset = 3) {
|
|
178
|
+
return value + ''.padEnd(offset - Math.floor((value.length + indent) / 8), '\t');
|
|
79
179
|
}
|
|
80
|
-
execute();
|
|
81
180
|
async function readPackage(dir) {
|
|
82
181
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
83
182
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
@@ -86,13 +185,15 @@ async function readPackage(dir) {
|
|
|
86
185
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
87
186
|
return {
|
|
88
187
|
pkg: JSON.parse(pkgFile.toString()),
|
|
89
|
-
readme: readmeFile.toString()
|
|
188
|
+
readme: readmeFile.toString(),
|
|
189
|
+
mode: 'update'
|
|
90
190
|
};
|
|
91
191
|
}
|
|
92
192
|
catch (e) { /**/ }
|
|
93
193
|
return {
|
|
94
194
|
pkg: {},
|
|
95
|
-
readme: ''
|
|
195
|
+
readme: '',
|
|
196
|
+
mode: 'create'
|
|
96
197
|
};
|
|
97
198
|
}
|
|
98
199
|
async function writePackage(dir, pkg) {
|
package/dist/index.mjs
CHANGED
|
@@ -4,77 +4,176 @@ import fs from 'fs/promises';
|
|
|
4
4
|
import userName from 'git-user-name';
|
|
5
5
|
import gitConfig from 'parse-git-config';
|
|
6
6
|
import minimist from 'minimist';
|
|
7
|
+
import { grey, white, green, magenta } from 'kleur';
|
|
7
8
|
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
8
10
|
async function execute() {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const parsedArgs = minimist(process.argv.slice(2));
|
|
15
|
-
const targetDir = path.join(process.cwd(), parsedArgs._[0] ?? '.');
|
|
11
|
+
await reportVersion();
|
|
12
|
+
const targetDir = getTargetDir();
|
|
13
|
+
console.log(grey(pad16plus('Target Directory', 0)) + white(targetDir));
|
|
14
|
+
const pkg = await readPackage(targetDir);
|
|
15
|
+
console.log(grey(pad16plus('Mode', 0)) + white(pkg.mode));
|
|
16
16
|
const packageName = path.basename(targetDir);
|
|
17
17
|
let cancelled = false;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
const options = getBasicOptions(packageName);
|
|
19
|
+
options.push(...await getGitOptions(packageName));
|
|
20
|
+
const state = getOptionsValue(options);
|
|
21
|
+
for (;;) {
|
|
22
|
+
const topLevelAction = await prompts({
|
|
23
|
+
type: 'select',
|
|
24
|
+
name: 'value',
|
|
25
|
+
message: 'Select an option to change, Done to execute, Ctrl+C to cancel',
|
|
26
|
+
choices: [
|
|
27
|
+
{ title: green('Done'), description: `${pkg.mode === 'update' ? 'Update' : 'Create'} package`, value: 'done' },
|
|
28
|
+
...options.map(mapOption(state))
|
|
29
|
+
],
|
|
30
|
+
initial: 0
|
|
31
|
+
}, { onCancel });
|
|
32
|
+
if (cancelled) {
|
|
33
|
+
process.exit(-1);
|
|
34
|
+
}
|
|
35
|
+
if (topLevelAction.value === 'done') {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
let option = options.find(item => item.field === topLevelAction.value);
|
|
39
|
+
let mutateObject = state;
|
|
40
|
+
if ('items' in option) {
|
|
41
|
+
const nextLevelAction = await prompts([{
|
|
42
|
+
type: 'select',
|
|
43
|
+
name: 'value',
|
|
44
|
+
message: option.title,
|
|
45
|
+
choices: option.items.map(mapOption(state[option.field]))
|
|
46
|
+
}], { onCancel });
|
|
47
|
+
if (cancelled) {
|
|
48
|
+
process.exit(-1);
|
|
49
|
+
}
|
|
50
|
+
if (option.mutateInnerObject) {
|
|
51
|
+
mutateObject = state[option.field];
|
|
52
|
+
}
|
|
53
|
+
option = option.items.find(item => item.field === nextLevelAction.value);
|
|
54
|
+
}
|
|
55
|
+
const action = await prompts([{
|
|
56
|
+
type: 'text',
|
|
57
|
+
name: option.field,
|
|
58
|
+
message: option.title,
|
|
59
|
+
initial: state[option.field]
|
|
60
|
+
}], { onCancel });
|
|
61
|
+
if (cancelled) {
|
|
62
|
+
process.exit(-1);
|
|
63
|
+
}
|
|
64
|
+
mutateObject[option.field] = action[option.field];
|
|
65
|
+
}
|
|
44
66
|
if (cancelled) {
|
|
45
67
|
process.exit(-1);
|
|
46
68
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
69
|
+
Object.assign(pkg.pkg, state);
|
|
70
|
+
pkg.readme ??= `# ${state.name}`;
|
|
71
|
+
await writePackage(targetDir, pkg);
|
|
72
|
+
function onCancel() {
|
|
73
|
+
cancelled = true;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
execute();
|
|
77
|
+
function mapOption(state) {
|
|
78
|
+
return (option) => {
|
|
79
|
+
const fieldValue = state[option.field];
|
|
80
|
+
return {
|
|
81
|
+
title: pad16plus(option.title) + magenta('items' in option ? viewObject(option.items, fieldValue) : fieldValue),
|
|
82
|
+
value: option.field
|
|
83
|
+
};
|
|
51
84
|
};
|
|
85
|
+
}
|
|
86
|
+
function viewObject(items, json) {
|
|
87
|
+
return items
|
|
88
|
+
.map(item => grey(item.title) + ' ' + white(json[item.field]))
|
|
89
|
+
.join(', ');
|
|
90
|
+
}
|
|
91
|
+
function getOptionsValue(options) {
|
|
92
|
+
return options.reduce((accumulator, item) => ({
|
|
93
|
+
...accumulator,
|
|
94
|
+
[item.field]: 'items' in item ? getOptionsValue(item.items) : item.initialValue
|
|
95
|
+
}), {});
|
|
96
|
+
}
|
|
97
|
+
async function reportVersion() {
|
|
98
|
+
const createPkgBldPackage = await readPackage(path.resolve(__dirname, '..'));
|
|
99
|
+
console.log(grey(pad16plus('create-pkgbld', 0)) + white('v' + createPkgBldPackage.pkg.version));
|
|
100
|
+
}
|
|
101
|
+
function getTargetDir() {
|
|
102
|
+
const parsedArgs = minimist(process.argv.slice(2));
|
|
103
|
+
const targetDir = path.join(process.cwd(), parsedArgs._[0] ?? '.');
|
|
104
|
+
return targetDir;
|
|
105
|
+
}
|
|
106
|
+
async function getGitOptions(packageName) {
|
|
107
|
+
const options = [];
|
|
52
108
|
try {
|
|
53
109
|
const gitCfg = await gitConfig();
|
|
54
110
|
if (gitCfg) {
|
|
55
111
|
const url = gitCfg['remote "origin"'].url;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
112
|
+
options.push({
|
|
113
|
+
title: 'Homepage',
|
|
114
|
+
field: 'homepage',
|
|
115
|
+
initialValue: url.replace('.git', `/blob/main/${packageName}/README.md`)
|
|
116
|
+
});
|
|
117
|
+
options.push({
|
|
118
|
+
title: 'Repository',
|
|
119
|
+
field: 'repository',
|
|
120
|
+
items: [{
|
|
121
|
+
title: 'Type',
|
|
122
|
+
field: 'type',
|
|
123
|
+
initialValue: 'git'
|
|
124
|
+
}, {
|
|
125
|
+
title: 'Url',
|
|
126
|
+
field: 'url',
|
|
127
|
+
initialValue: `git+${url}`
|
|
128
|
+
}],
|
|
129
|
+
mutateInnerObject: true
|
|
130
|
+
});
|
|
131
|
+
options.push({
|
|
132
|
+
title: 'Bugs',
|
|
133
|
+
field: 'bugs',
|
|
134
|
+
initialValue: url.replace('.git', '/issues')
|
|
135
|
+
});
|
|
64
136
|
}
|
|
65
137
|
}
|
|
66
138
|
catch (e) {
|
|
67
139
|
/* ignore */
|
|
68
140
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
141
|
+
return options;
|
|
142
|
+
}
|
|
143
|
+
function getBasicOptions(packageName) {
|
|
144
|
+
return [{
|
|
145
|
+
title: 'Package Name',
|
|
146
|
+
field: 'name',
|
|
147
|
+
initialValue: packageName
|
|
148
|
+
}, {
|
|
149
|
+
title: 'Version',
|
|
150
|
+
field: 'version',
|
|
151
|
+
initialValue: '0.0.1'
|
|
152
|
+
}, {
|
|
153
|
+
title: 'Description',
|
|
154
|
+
field: 'description',
|
|
155
|
+
initialValue: ''
|
|
156
|
+
}, {
|
|
157
|
+
title: 'License',
|
|
158
|
+
field: 'license',
|
|
159
|
+
initialValue: 'MIT'
|
|
160
|
+
}, {
|
|
161
|
+
title: 'Author',
|
|
162
|
+
field: 'author',
|
|
163
|
+
initialValue: userName() ?? ''
|
|
164
|
+
}, {
|
|
165
|
+
title: 'Destination folder',
|
|
166
|
+
field: 'dest',
|
|
167
|
+
initialValue: 'dest'
|
|
168
|
+
}, {
|
|
169
|
+
title: 'Source folder',
|
|
170
|
+
field: 'src',
|
|
171
|
+
initialValue: 'src'
|
|
172
|
+
}];
|
|
173
|
+
}
|
|
174
|
+
function pad16plus(value, indent = 4, offset = 3) {
|
|
175
|
+
return value + ''.padEnd(offset - Math.floor((value.length + indent) / 8), '\t');
|
|
76
176
|
}
|
|
77
|
-
execute();
|
|
78
177
|
async function readPackage(dir) {
|
|
79
178
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
80
179
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
@@ -83,13 +182,15 @@ async function readPackage(dir) {
|
|
|
83
182
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
84
183
|
return {
|
|
85
184
|
pkg: JSON.parse(pkgFile.toString()),
|
|
86
|
-
readme: readmeFile.toString()
|
|
185
|
+
readme: readmeFile.toString(),
|
|
186
|
+
mode: 'update'
|
|
87
187
|
};
|
|
88
188
|
}
|
|
89
189
|
catch (e) { /**/ }
|
|
90
190
|
return {
|
|
91
191
|
pkg: {},
|
|
92
|
-
readme: ''
|
|
192
|
+
readme: '',
|
|
193
|
+
mode: 'create'
|
|
93
194
|
};
|
|
94
195
|
}
|
|
95
196
|
async function writePackage(dir, pkg) {
|
package/dist/types.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.3.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "create-pkgbld",
|
|
5
5
|
"author": "Konstantin Shutkin",
|
|
@@ -38,13 +38,14 @@
|
|
|
38
38
|
"@types/parse-git-config": "3.0.1",
|
|
39
39
|
"@types/prompts": "2.4.4",
|
|
40
40
|
"@types/minimist": "1.2.2",
|
|
41
|
-
"pkgbld": "1.16.
|
|
41
|
+
"pkgbld": "1.16.7"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"git-user-name": "2.0.0",
|
|
45
45
|
"minimist": "1.2.8",
|
|
46
46
|
"parse-git-config": "3.0.0",
|
|
47
|
-
"prompts": "2.4.2"
|
|
47
|
+
"prompts": "2.4.2",
|
|
48
|
+
"kleur": "4.1.5"
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "node ../pkgbld/dist/index.js --formats=cjs,es",
|