create-pkgbld 1.1.10 → 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 +163 -122
- package/dist/index.mjs +163 -122
- package/dist/types.d.ts +13 -0
- package/package.json +5 -9
package/dist/index.cjs
CHANGED
|
@@ -7,139 +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
|
|
10
|
+
var kleur = require('kleur');
|
|
11
11
|
|
|
12
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
12
13
|
async function execute() {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
|
|
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
|
+
const packageName = path.basename(targetDir);
|
|
18
20
|
let cancelled = false;
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
pkg: {},
|
|
34
|
-
readme: ''
|
|
35
|
-
};
|
|
36
|
-
if (chooseAction.action === 'subpackage') {
|
|
37
|
-
rootPkg = await readPackage(path.resolve(dir, packageName ? '..' : '.'));
|
|
38
|
-
}
|
|
39
|
-
const template = chooseAction.action === 'root' ? 'kshutkin/monorepo-root' : 'kshutkin/monorepo-package';
|
|
40
|
-
const emitter = degit(template, {
|
|
41
|
-
cache: false,
|
|
42
|
-
force: true,
|
|
43
|
-
verbose: true,
|
|
44
|
-
});
|
|
45
|
-
emitter.on('info', (info) => {
|
|
46
|
-
console.log(info.message);
|
|
47
|
-
});
|
|
48
|
-
await emitter.clone(dir);
|
|
49
|
-
const basePackageName = (packageName && path.basename(packageName)) || path.basename(process.cwd());
|
|
50
|
-
if (chooseAction.action === 'root') {
|
|
51
|
-
const response = await prompts([{
|
|
52
|
-
type: 'text',
|
|
53
|
-
name: 'name',
|
|
54
|
-
message: 'package name',
|
|
55
|
-
initial: basePackageName
|
|
56
|
-
}, {
|
|
57
|
-
type: 'text',
|
|
58
|
-
name: 'scope',
|
|
59
|
-
message: 'scope (without @ or empty)'
|
|
60
|
-
}, {
|
|
61
|
-
type: 'text',
|
|
62
|
-
name: 'description',
|
|
63
|
-
message: 'description',
|
|
64
|
-
initial: ''
|
|
65
|
-
}], { onCancel });
|
|
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 });
|
|
66
35
|
if (cancelled) {
|
|
67
36
|
process.exit(-1);
|
|
68
37
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
name: 'description',
|
|
91
|
-
message: 'description',
|
|
92
|
-
initial: ''
|
|
93
|
-
}, {
|
|
94
|
-
type: 'text',
|
|
95
|
-
name: 'license',
|
|
96
|
-
message: 'license',
|
|
97
|
-
initial: 'MIT'
|
|
98
|
-
}, {
|
|
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([{
|
|
99
59
|
type: 'text',
|
|
100
|
-
name:
|
|
101
|
-
message:
|
|
102
|
-
initial:
|
|
60
|
+
name: option.field,
|
|
61
|
+
message: option.title,
|
|
62
|
+
initial: state[option.field]
|
|
103
63
|
}], { onCancel });
|
|
104
64
|
if (cancelled) {
|
|
105
65
|
process.exit(-1);
|
|
106
66
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
};
|
|
112
|
-
try {
|
|
113
|
-
const gitCfg = await gitConfig();
|
|
114
|
-
if (gitCfg) {
|
|
115
|
-
const url = gitCfg['remote "origin"'].url;
|
|
116
|
-
gitInfo.homepage = url.replace('.git', `/blob/main/${basePackageName}/README.md`);
|
|
117
|
-
gitInfo.repository = {
|
|
118
|
-
type: 'git',
|
|
119
|
-
url: `git+${url}`
|
|
120
|
-
};
|
|
121
|
-
gitInfo.bugs = {
|
|
122
|
-
url: url.replace('.git', '/issues')
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
catch (e) {
|
|
127
|
-
/* ignore */
|
|
128
|
-
}
|
|
129
|
-
const pkg = await readPackage(dir);
|
|
130
|
-
Object.assign(pkg.pkg, response, gitInfo);
|
|
131
|
-
pkg.readme = `# ${response.name}`;
|
|
132
|
-
await writePackage(dir, pkg);
|
|
133
|
-
rootPkg.pkg.workspaces ??= [];
|
|
134
|
-
rootPkg.pkg.workspaces.push(basePackageName);
|
|
135
|
-
rootPkg.readme += `\n- [${basePackageName}](./${basePackageName}/README.md)`;
|
|
136
|
-
await writePackage(path.resolve(dir, '..'), rootPkg);
|
|
67
|
+
mutateObject[option.field] = action[option.field];
|
|
68
|
+
}
|
|
69
|
+
if (cancelled) {
|
|
70
|
+
process.exit(-1);
|
|
137
71
|
}
|
|
72
|
+
Object.assign(pkg.pkg, state);
|
|
73
|
+
pkg.readme ??= `# ${state.name}`;
|
|
74
|
+
await writePackage(targetDir, pkg);
|
|
138
75
|
function onCancel() {
|
|
139
76
|
cancelled = true;
|
|
140
77
|
}
|
|
141
78
|
}
|
|
142
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
|
+
};
|
|
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 = [];
|
|
111
|
+
try {
|
|
112
|
+
const gitCfg = await gitConfig();
|
|
113
|
+
if (gitCfg) {
|
|
114
|
+
const url = gitCfg['remote "origin"'].url;
|
|
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
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
catch (e) {
|
|
142
|
+
/* ignore */
|
|
143
|
+
}
|
|
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');
|
|
179
|
+
}
|
|
143
180
|
async function readPackage(dir) {
|
|
144
181
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
145
182
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
@@ -148,19 +185,23 @@ async function readPackage(dir) {
|
|
|
148
185
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
149
186
|
return {
|
|
150
187
|
pkg: JSON.parse(pkgFile.toString()),
|
|
151
|
-
readme: readmeFile.toString()
|
|
188
|
+
readme: readmeFile.toString(),
|
|
189
|
+
mode: 'update'
|
|
152
190
|
};
|
|
153
191
|
}
|
|
154
|
-
catch (e) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
192
|
+
catch (e) { /**/ }
|
|
193
|
+
return {
|
|
194
|
+
pkg: {},
|
|
195
|
+
readme: '',
|
|
196
|
+
mode: 'create'
|
|
197
|
+
};
|
|
158
198
|
}
|
|
159
199
|
async function writePackage(dir, pkg) {
|
|
160
200
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
161
201
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
162
202
|
try {
|
|
163
|
-
await fs.
|
|
203
|
+
await fs.mkdir(dir, { recursive: true });
|
|
204
|
+
await fs.writeFile(packageFileName, JSON.stringify(pkg.pkg, null, 2), {});
|
|
164
205
|
await fs.writeFile(readmeFileName, pkg.readme);
|
|
165
206
|
}
|
|
166
207
|
catch (e) {
|
package/dist/index.mjs
CHANGED
|
@@ -4,139 +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
|
|
7
|
+
import { grey, white, green, magenta } from 'kleur';
|
|
8
8
|
|
|
9
|
+
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
|
9
10
|
async function execute() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
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
|
+
const packageName = path.basename(targetDir);
|
|
15
17
|
let cancelled = false;
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
pkg: {},
|
|
31
|
-
readme: ''
|
|
32
|
-
};
|
|
33
|
-
if (chooseAction.action === 'subpackage') {
|
|
34
|
-
rootPkg = await readPackage(path.resolve(dir, packageName ? '..' : '.'));
|
|
35
|
-
}
|
|
36
|
-
const template = chooseAction.action === 'root' ? 'kshutkin/monorepo-root' : 'kshutkin/monorepo-package';
|
|
37
|
-
const emitter = degit(template, {
|
|
38
|
-
cache: false,
|
|
39
|
-
force: true,
|
|
40
|
-
verbose: true,
|
|
41
|
-
});
|
|
42
|
-
emitter.on('info', (info) => {
|
|
43
|
-
console.log(info.message);
|
|
44
|
-
});
|
|
45
|
-
await emitter.clone(dir);
|
|
46
|
-
const basePackageName = (packageName && path.basename(packageName)) || path.basename(process.cwd());
|
|
47
|
-
if (chooseAction.action === 'root') {
|
|
48
|
-
const response = await prompts([{
|
|
49
|
-
type: 'text',
|
|
50
|
-
name: 'name',
|
|
51
|
-
message: 'package name',
|
|
52
|
-
initial: basePackageName
|
|
53
|
-
}, {
|
|
54
|
-
type: 'text',
|
|
55
|
-
name: 'scope',
|
|
56
|
-
message: 'scope (without @ or empty)'
|
|
57
|
-
}, {
|
|
58
|
-
type: 'text',
|
|
59
|
-
name: 'description',
|
|
60
|
-
message: 'description',
|
|
61
|
-
initial: ''
|
|
62
|
-
}], { onCancel });
|
|
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 });
|
|
63
32
|
if (cancelled) {
|
|
64
33
|
process.exit(-1);
|
|
65
34
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
name: 'description',
|
|
88
|
-
message: 'description',
|
|
89
|
-
initial: ''
|
|
90
|
-
}, {
|
|
91
|
-
type: 'text',
|
|
92
|
-
name: 'license',
|
|
93
|
-
message: 'license',
|
|
94
|
-
initial: 'MIT'
|
|
95
|
-
}, {
|
|
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([{
|
|
96
56
|
type: 'text',
|
|
97
|
-
name:
|
|
98
|
-
message:
|
|
99
|
-
initial:
|
|
57
|
+
name: option.field,
|
|
58
|
+
message: option.title,
|
|
59
|
+
initial: state[option.field]
|
|
100
60
|
}], { onCancel });
|
|
101
61
|
if (cancelled) {
|
|
102
62
|
process.exit(-1);
|
|
103
63
|
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
};
|
|
109
|
-
try {
|
|
110
|
-
const gitCfg = await gitConfig();
|
|
111
|
-
if (gitCfg) {
|
|
112
|
-
const url = gitCfg['remote "origin"'].url;
|
|
113
|
-
gitInfo.homepage = url.replace('.git', `/blob/main/${basePackageName}/README.md`);
|
|
114
|
-
gitInfo.repository = {
|
|
115
|
-
type: 'git',
|
|
116
|
-
url: `git+${url}`
|
|
117
|
-
};
|
|
118
|
-
gitInfo.bugs = {
|
|
119
|
-
url: url.replace('.git', '/issues')
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
catch (e) {
|
|
124
|
-
/* ignore */
|
|
125
|
-
}
|
|
126
|
-
const pkg = await readPackage(dir);
|
|
127
|
-
Object.assign(pkg.pkg, response, gitInfo);
|
|
128
|
-
pkg.readme = `# ${response.name}`;
|
|
129
|
-
await writePackage(dir, pkg);
|
|
130
|
-
rootPkg.pkg.workspaces ??= [];
|
|
131
|
-
rootPkg.pkg.workspaces.push(basePackageName);
|
|
132
|
-
rootPkg.readme += `\n- [${basePackageName}](./${basePackageName}/README.md)`;
|
|
133
|
-
await writePackage(path.resolve(dir, '..'), rootPkg);
|
|
64
|
+
mutateObject[option.field] = action[option.field];
|
|
65
|
+
}
|
|
66
|
+
if (cancelled) {
|
|
67
|
+
process.exit(-1);
|
|
134
68
|
}
|
|
69
|
+
Object.assign(pkg.pkg, state);
|
|
70
|
+
pkg.readme ??= `# ${state.name}`;
|
|
71
|
+
await writePackage(targetDir, pkg);
|
|
135
72
|
function onCancel() {
|
|
136
73
|
cancelled = true;
|
|
137
74
|
}
|
|
138
75
|
}
|
|
139
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
|
+
};
|
|
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 = [];
|
|
108
|
+
try {
|
|
109
|
+
const gitCfg = await gitConfig();
|
|
110
|
+
if (gitCfg) {
|
|
111
|
+
const url = gitCfg['remote "origin"'].url;
|
|
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
|
+
});
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
catch (e) {
|
|
139
|
+
/* ignore */
|
|
140
|
+
}
|
|
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');
|
|
176
|
+
}
|
|
140
177
|
async function readPackage(dir) {
|
|
141
178
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
142
179
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
@@ -145,19 +182,23 @@ async function readPackage(dir) {
|
|
|
145
182
|
const readmeFile = await fs.readFile(readmeFileName);
|
|
146
183
|
return {
|
|
147
184
|
pkg: JSON.parse(pkgFile.toString()),
|
|
148
|
-
readme: readmeFile.toString()
|
|
185
|
+
readme: readmeFile.toString(),
|
|
186
|
+
mode: 'update'
|
|
149
187
|
};
|
|
150
188
|
}
|
|
151
|
-
catch (e) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
189
|
+
catch (e) { /**/ }
|
|
190
|
+
return {
|
|
191
|
+
pkg: {},
|
|
192
|
+
readme: '',
|
|
193
|
+
mode: 'create'
|
|
194
|
+
};
|
|
155
195
|
}
|
|
156
196
|
async function writePackage(dir, pkg) {
|
|
157
197
|
const packageFileName = path.resolve(dir, 'package.json');
|
|
158
198
|
const readmeFileName = path.resolve(dir, 'README.md');
|
|
159
199
|
try {
|
|
160
|
-
await fs.
|
|
200
|
+
await fs.mkdir(dir, { recursive: true });
|
|
201
|
+
await fs.writeFile(packageFileName, JSON.stringify(pkg.pkg, null, 2), {});
|
|
161
202
|
await fs.writeFile(readmeFileName, pkg.readme);
|
|
162
203
|
}
|
|
163
204
|
catch (e) {
|
package/dist/types.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.
|
|
2
|
+
"version": "1.3.0",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "create-pkgbld",
|
|
5
|
-
"author":
|
|
6
|
-
"name": "Konstantin Shutkin"
|
|
7
|
-
},
|
|
8
|
-
"funding": "https://www.donationalerts.com/r/excitingcode",
|
|
5
|
+
"author": "Konstantin Shutkin",
|
|
9
6
|
"bin": "./dist/index.cjs",
|
|
10
7
|
"exports": {
|
|
11
8
|
".": {
|
|
@@ -37,19 +34,18 @@
|
|
|
37
34
|
"init"
|
|
38
35
|
],
|
|
39
36
|
"devDependencies": {
|
|
40
|
-
"@types/degit": "2.8.3",
|
|
41
37
|
"@types/git-user-name": "2.0.1",
|
|
42
38
|
"@types/parse-git-config": "3.0.1",
|
|
43
39
|
"@types/prompts": "2.4.4",
|
|
44
40
|
"@types/minimist": "1.2.2",
|
|
45
|
-
"pkgbld": "1.16.
|
|
41
|
+
"pkgbld": "1.16.7"
|
|
46
42
|
},
|
|
47
43
|
"dependencies": {
|
|
48
|
-
"degit": "2.8.4",
|
|
49
44
|
"git-user-name": "2.0.0",
|
|
50
45
|
"minimist": "1.2.8",
|
|
51
46
|
"parse-git-config": "3.0.0",
|
|
52
|
-
"prompts": "2.4.2"
|
|
47
|
+
"prompts": "2.4.2",
|
|
48
|
+
"kleur": "4.1.5"
|
|
53
49
|
},
|
|
54
50
|
"scripts": {
|
|
55
51
|
"build": "node ../pkgbld/dist/index.js --formats=cjs,es",
|