@quilted/create 0.1.29 → 0.1.31
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.md +12 -0
- package/build/cjs/app.cjs +233 -39
- package/build/cjs/index.cjs +315 -413
- package/build/cjs/package.cjs +36 -36
- package/build/cjs/shared/package-manager.cjs +677 -0
- package/build/esm/app.mjs +207 -13
- package/build/esm/index.mjs +314 -389
- package/build/esm/package.mjs +37 -37
- package/build/esm/parser-babel.mjs +1 -1
- package/build/esm/parser-typescript.mjs +1 -1
- package/build/esm/parser-yaml.mjs +1 -1
- package/build/esm/shared/package-manager.mjs +635 -0
- package/build/esm/standalone.mjs +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/help.d.ts.map +1 -1
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared/prompts.d.ts +3 -4
- package/build/typescript/shared/prompts.d.ts.map +1 -1
- package/build/typescript/shared.d.ts +1 -1
- package/build/typescript/shared.d.ts.map +1 -1
- package/package.json +2 -2
- package/source/app.ts +12 -11
- package/source/create.ts +2 -5
- package/source/help.ts +1 -2
- package/source/package.ts +36 -38
- package/source/shared/prompts.ts +13 -44
- package/source/shared.ts +1 -2
- package/tsconfig.json +6 -1
- package/build/cjs/package-manager.cjs +0 -330
- package/build/esm/package-manager.mjs +0 -299
package/source/shared/prompts.ts
CHANGED
|
@@ -1,24 +1,10 @@
|
|
|
1
|
-
import * as fs from 'fs';
|
|
2
|
-
|
|
3
1
|
import type {Result as ArgvResult} from 'arg';
|
|
4
|
-
import prompts from 'prompts';
|
|
5
|
-
import type {PromptObject} from 'prompts';
|
|
6
2
|
import * as color from 'colorette';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
{name: 'value', ...prompt},
|
|
13
|
-
{
|
|
14
|
-
onCancel() {
|
|
15
|
-
throw new AbortError();
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
);
|
|
19
|
-
|
|
20
|
-
return result.value;
|
|
21
|
-
}
|
|
3
|
+
import {
|
|
4
|
+
prompt,
|
|
5
|
+
getPackageManager as baseGetPackageManager,
|
|
6
|
+
createPackageManagerRunner,
|
|
7
|
+
} from '@quilted/cli-kit';
|
|
22
8
|
|
|
23
9
|
type BaseArguments = ArgvResult<{
|
|
24
10
|
'--yes': BooleanConstructor;
|
|
@@ -31,6 +17,8 @@ type BaseArguments = ArgvResult<{
|
|
|
31
17
|
'--package-manager': StringConstructor;
|
|
32
18
|
}>;
|
|
33
19
|
|
|
20
|
+
export {prompt};
|
|
21
|
+
|
|
34
22
|
export async function getCreateAsMonorepo(argv: BaseArguments) {
|
|
35
23
|
let createAsMonorepo: boolean;
|
|
36
24
|
|
|
@@ -69,31 +57,12 @@ export async function getShouldInstall(argv: BaseArguments) {
|
|
|
69
57
|
return shouldInstall;
|
|
70
58
|
}
|
|
71
59
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const explicitPackageManager =
|
|
79
|
-
argv['--package-manager'].toLocaleLowerCase();
|
|
80
|
-
|
|
81
|
-
packageManager = VALID_PACKAGE_MANAGERS.has(explicitPackageManager)
|
|
82
|
-
? (explicitPackageManager as any)
|
|
83
|
-
: 'npm';
|
|
84
|
-
} else {
|
|
85
|
-
const npmUserAgent = process.env['npm_config_user_agent'] ?? 'npm';
|
|
86
|
-
|
|
87
|
-
if (npmUserAgent.includes('pnpm') || fs.existsSync('pnpm-lock.yaml')) {
|
|
88
|
-
packageManager = 'pnpm';
|
|
89
|
-
} else if (npmUserAgent.includes('yarn') || fs.existsSync('yarn.lock')) {
|
|
90
|
-
packageManager = 'yarn';
|
|
91
|
-
} else {
|
|
92
|
-
packageManager = 'npm';
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return packageManager;
|
|
60
|
+
export async function getPackageManager(
|
|
61
|
+
argv: BaseArguments,
|
|
62
|
+
options?: Parameters<typeof createPackageManagerRunner>[1],
|
|
63
|
+
) {
|
|
64
|
+
const packageManager = await baseGetPackageManager(argv['--package-manager']);
|
|
65
|
+
return createPackageManagerRunner(packageManager ?? 'npm', options);
|
|
97
66
|
}
|
|
98
67
|
|
|
99
68
|
type Extra = 'github' | 'vscode';
|
package/source/shared.ts
CHANGED
|
@@ -2,8 +2,7 @@ import * as fs from 'fs';
|
|
|
2
2
|
import * as path from 'path';
|
|
3
3
|
import {fileURLToPath} from 'url';
|
|
4
4
|
import type {BuiltInParserName} from 'prettier';
|
|
5
|
-
|
|
6
|
-
export {prompt} from './shared/prompts';
|
|
5
|
+
export {prompt} from '@quilted/cli-kit';
|
|
7
6
|
|
|
8
7
|
export function loadTemplate(
|
|
9
8
|
name:
|
package/tsconfig.json
CHANGED
|
@@ -6,5 +6,10 @@
|
|
|
6
6
|
},
|
|
7
7
|
"include": ["source"],
|
|
8
8
|
"exclude": ["quilt.project.ts", "**/*.test.ts", "**/*.test.tsx"],
|
|
9
|
-
"references": [
|
|
9
|
+
"references": [
|
|
10
|
+
{"path": "../quilt"},
|
|
11
|
+
{"path": "../craft"},
|
|
12
|
+
{"path": "../cli-kit"},
|
|
13
|
+
{"path": "../events"}
|
|
14
|
+
]
|
|
10
15
|
}
|
|
@@ -1,330 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var path = require('node:path');
|
|
4
|
-
var fs = require('node:fs');
|
|
5
|
-
var node_url = require('node:url');
|
|
6
|
-
require('./index.cjs');
|
|
7
|
-
|
|
8
|
-
function _interopNamespace(e) {
|
|
9
|
-
if (e && e.__esModule) return e;
|
|
10
|
-
var n = Object.create(null);
|
|
11
|
-
if (e) {
|
|
12
|
-
Object.keys(e).forEach(function (k) {
|
|
13
|
-
if (k !== 'default') {
|
|
14
|
-
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
15
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
get: function () { return e[k]; }
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
n["default"] = e;
|
|
23
|
-
return Object.freeze(n);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
var path__namespace = /*#__PURE__*/_interopNamespace(path);
|
|
27
|
-
var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
|
|
28
|
-
|
|
29
|
-
function loadTemplate(name) {
|
|
30
|
-
let templateRootPromise;
|
|
31
|
-
return {
|
|
32
|
-
async copy(to, handleFile) {
|
|
33
|
-
var _templateRootPromise;
|
|
34
|
-
|
|
35
|
-
(_templateRootPromise = templateRootPromise) !== null && _templateRootPromise !== void 0 ? _templateRootPromise : templateRootPromise = templateDirectory(name);
|
|
36
|
-
const templateRoot = await templateRootPromise;
|
|
37
|
-
const targetRoot = path__namespace.resolve(to);
|
|
38
|
-
const files = fs__namespace.readdirSync(templateRoot).filter(file => !path__namespace.basename(file).startsWith('.'));
|
|
39
|
-
|
|
40
|
-
for (const file of files) {
|
|
41
|
-
if (handleFile) {
|
|
42
|
-
if (!handleFile(file)) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const targetPath = path__namespace.join(targetRoot, file.startsWith('_') ? `.${file.slice(1)}` : file);
|
|
48
|
-
copy(path__namespace.join(templateRoot, file), targetPath);
|
|
49
|
-
}
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
async read(file) {
|
|
53
|
-
var _templateRootPromise2;
|
|
54
|
-
|
|
55
|
-
(_templateRootPromise2 = templateRootPromise) !== null && _templateRootPromise2 !== void 0 ? _templateRootPromise2 : templateRootPromise = templateDirectory(name);
|
|
56
|
-
const templateRoot = await templateRootPromise;
|
|
57
|
-
return fs__namespace.readFileSync(path__namespace.join(templateRoot, file), {
|
|
58
|
-
encoding: 'utf8'
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
function createOutputTarget(target) {
|
|
65
|
-
return {
|
|
66
|
-
root: target,
|
|
67
|
-
|
|
68
|
-
read(file) {
|
|
69
|
-
return fs__namespace.promises.readFile(path__namespace.resolve(target, file), {
|
|
70
|
-
encoding: 'utf8'
|
|
71
|
-
});
|
|
72
|
-
},
|
|
73
|
-
|
|
74
|
-
async write(file, content) {
|
|
75
|
-
await writeFile(path__namespace.resolve(target, file), content);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
let packageRootPromise;
|
|
81
|
-
|
|
82
|
-
async function templateDirectory(name) {
|
|
83
|
-
return path__namespace.join(await getPackageRoot(), 'templates', name);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
async function getPackageRoot() {
|
|
87
|
-
if (!packageRootPromise) {
|
|
88
|
-
packageRootPromise = (async () => {
|
|
89
|
-
const {
|
|
90
|
-
packageDirectory
|
|
91
|
-
} = await Promise.resolve().then(function () { return require('./index2.cjs'); });
|
|
92
|
-
return packageDirectory({
|
|
93
|
-
cwd: path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('package-manager.cjs', document.baseURI).href))))
|
|
94
|
-
});
|
|
95
|
-
})();
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return packageRootPromise;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function toValidPackageName(projectName) {
|
|
102
|
-
return projectName.trim().toLowerCase().replace(/\s+/g, '-').replace(/^[._]/, '').replace(/[^a-z0-9-~@/]+/g, '-');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function copy(source, destination) {
|
|
106
|
-
const stat = fs__namespace.statSync(source);
|
|
107
|
-
|
|
108
|
-
if (stat.isDirectory()) {
|
|
109
|
-
copyDirectory(source, destination);
|
|
110
|
-
} else {
|
|
111
|
-
fs__namespace.copyFileSync(source, destination);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
async function copyDirectory(source, destination) {
|
|
116
|
-
fs__namespace.mkdirSync(destination, {
|
|
117
|
-
recursive: true
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
for (const file of fs__namespace.readdirSync(source)) {
|
|
121
|
-
const srcFile = path__namespace.resolve(source, file);
|
|
122
|
-
const destFile = path__namespace.resolve(destination, file);
|
|
123
|
-
copy(srcFile, destFile);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function writeFile(file, content) {
|
|
128
|
-
await fs__namespace.promises.writeFile(file, content);
|
|
129
|
-
}
|
|
130
|
-
async function isEmpty(path) {
|
|
131
|
-
return fs__namespace.readdirSync(path).length === 0;
|
|
132
|
-
}
|
|
133
|
-
async function emptyDirectory(dir) {
|
|
134
|
-
if (!fs__namespace.existsSync(dir)) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
for (const file of fs__namespace.readdirSync(dir)) {
|
|
139
|
-
fs__namespace.rmSync(path__namespace.resolve(dir, file), {
|
|
140
|
-
force: true,
|
|
141
|
-
recursive: true
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
function relativeDirectoryForDisplay(relativeDirectory) {
|
|
146
|
-
return relativeDirectory.startsWith('.') ? relativeDirectory : `.${path__namespace.sep}${relativeDirectory}`;
|
|
147
|
-
}
|
|
148
|
-
async function format(content, {
|
|
149
|
-
as: parser
|
|
150
|
-
}) {
|
|
151
|
-
const [{
|
|
152
|
-
format
|
|
153
|
-
}, {
|
|
154
|
-
default: babel
|
|
155
|
-
}, {
|
|
156
|
-
default: typescript
|
|
157
|
-
}, {
|
|
158
|
-
default: yaml
|
|
159
|
-
}] = await Promise.all([Promise.resolve().then(function () { return require('./standalone.cjs'); }).then(function (n) { return n.standalone; }), Promise.resolve().then(function () { return require('./parser-babel.cjs'); }).then(function (n) { return n.parserBabel; }), Promise.resolve().then(function () { return require('./parser-typescript.cjs'); }).then(function (n) { return n.parserTypescript; }), Promise.resolve().then(function () { return require('./parser-yaml.cjs'); }).then(function (n) { return n.parserYaml; })]);
|
|
160
|
-
return format(content, {
|
|
161
|
-
arrowParens: 'always',
|
|
162
|
-
bracketSpacing: false,
|
|
163
|
-
singleQuote: true,
|
|
164
|
-
trailingComma: 'all',
|
|
165
|
-
parser,
|
|
166
|
-
plugins: [babel, typescript, yaml]
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
function mergeDependencies(first = {}, second = {}) {
|
|
170
|
-
const all = { ...first,
|
|
171
|
-
...second
|
|
172
|
-
};
|
|
173
|
-
const merged = {};
|
|
174
|
-
|
|
175
|
-
for (const [key, value] of Object.entries(all).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo))) {
|
|
176
|
-
merged[key] = value;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
return merged;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
|
|
183
|
-
async function addToTsConfig(directory, output) {
|
|
184
|
-
var _tsconfig$references;
|
|
185
|
-
|
|
186
|
-
const tsconfig = JSON.parse(await output.read('tsconfig.json'));
|
|
187
|
-
(_tsconfig$references = tsconfig.references) !== null && _tsconfig$references !== void 0 ? _tsconfig$references : tsconfig.references = [];
|
|
188
|
-
const relativePath = path.relative(output.root, directory);
|
|
189
|
-
const relativeForDisplay = relativeDirectoryForDisplay(relativePath);
|
|
190
|
-
|
|
191
|
-
if (tsconfig.references.length === 0) {
|
|
192
|
-
tsconfig.references.push({
|
|
193
|
-
path: relativeForDisplay
|
|
194
|
-
});
|
|
195
|
-
} else {
|
|
196
|
-
let hasExistingReference = false;
|
|
197
|
-
let referenceFormat = 'pretty-relative';
|
|
198
|
-
|
|
199
|
-
for (const {
|
|
200
|
-
path
|
|
201
|
-
} of tsconfig.references) {
|
|
202
|
-
if (path.startsWith('./')) {
|
|
203
|
-
if (ENDS_WITH_TSCONFIG.test(path)) {
|
|
204
|
-
referenceFormat = 'pretty-tsconfig';
|
|
205
|
-
|
|
206
|
-
if (path === `${relativeForDisplay}/tsconfig.json`) {
|
|
207
|
-
hasExistingReference = true;
|
|
208
|
-
break;
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
referenceFormat = 'pretty-relative';
|
|
213
|
-
|
|
214
|
-
if (path === relativeForDisplay) {
|
|
215
|
-
hasExistingReference = true;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
} else if (ENDS_WITH_TSCONFIG.test(path)) {
|
|
219
|
-
referenceFormat = 'tsconfig';
|
|
220
|
-
|
|
221
|
-
if (path === `${relativePath}/tsconfig.json`) {
|
|
222
|
-
hasExistingReference = true;
|
|
223
|
-
break;
|
|
224
|
-
}
|
|
225
|
-
} else {
|
|
226
|
-
referenceFormat = 'relative';
|
|
227
|
-
|
|
228
|
-
if (path === relativePath) {
|
|
229
|
-
hasExistingReference = true;
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (!hasExistingReference) {
|
|
236
|
-
let path;
|
|
237
|
-
|
|
238
|
-
if (referenceFormat === 'pretty-tsconfig') {
|
|
239
|
-
path = `${relativeForDisplay}/tsconfig.json`;
|
|
240
|
-
} else if (referenceFormat === 'pretty-relative') {
|
|
241
|
-
path = relativeForDisplay;
|
|
242
|
-
} else if (referenceFormat === 'tsconfig') {
|
|
243
|
-
path = `${relativePath}/tsconfig.json`;
|
|
244
|
-
} else {
|
|
245
|
-
path = relativePath;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
tsconfig.references.push({
|
|
249
|
-
path
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
tsconfig.references = tsconfig.references.sort(({
|
|
255
|
-
path: pathOne
|
|
256
|
-
}, {
|
|
257
|
-
path: pathTwo
|
|
258
|
-
}) => pathOne.localeCompare(pathTwo));
|
|
259
|
-
await output.write('tsconfig.json', await format(JSON.stringify(tsconfig), {
|
|
260
|
-
as: 'json'
|
|
261
|
-
}));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async function addToPackageManagerWorkspaces(directory, output, packageManager) {
|
|
265
|
-
if (packageManager === 'pnpm') {
|
|
266
|
-
var _workspaceYaml$packag;
|
|
267
|
-
|
|
268
|
-
const {
|
|
269
|
-
parse,
|
|
270
|
-
stringify
|
|
271
|
-
} = await Promise.resolve().then(function () { return require('./index3.cjs'); }).then(function (n) { return n.index; });
|
|
272
|
-
const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
|
|
273
|
-
workspaceYaml.packages = await addToWorkspaces(path.relative(output.root, directory), (_workspaceYaml$packag = workspaceYaml.packages) !== null && _workspaceYaml$packag !== void 0 ? _workspaceYaml$packag : []);
|
|
274
|
-
await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
|
|
275
|
-
as: 'yaml'
|
|
276
|
-
}));
|
|
277
|
-
} else {
|
|
278
|
-
var _packageJson$workspac;
|
|
279
|
-
|
|
280
|
-
const packageJson = JSON.parse(await output.read('package.json'));
|
|
281
|
-
packageJson.workspaces = await addToWorkspaces(path.relative(output.root, directory), (_packageJson$workspac = packageJson.workspaces) !== null && _packageJson$workspac !== void 0 ? _packageJson$workspac : []);
|
|
282
|
-
await output.write('package.json', await format(JSON.stringify(packageJson), {
|
|
283
|
-
as: 'json-stringify'
|
|
284
|
-
}));
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
async function addToWorkspaces(relative, workspaces) {
|
|
289
|
-
if (workspaces.length === 0) {
|
|
290
|
-
return [relative];
|
|
291
|
-
} // Default documentation seems to generally exclude leading `./` on paths
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
let pretty = false;
|
|
295
|
-
let hasMatch = false;
|
|
296
|
-
const {
|
|
297
|
-
default: minimatch
|
|
298
|
-
} = await Promise.resolve().then(function () { return require('./minimatch.cjs'); }).then(function (n) { return n.minimatch; });
|
|
299
|
-
|
|
300
|
-
for (const pattern of workspaces) {
|
|
301
|
-
let normalizedPattern = pattern;
|
|
302
|
-
|
|
303
|
-
if (pattern.startsWith('./')) {
|
|
304
|
-
pretty = true;
|
|
305
|
-
normalizedPattern = pattern.slice(2);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (minimatch(relative, normalizedPattern)) {
|
|
309
|
-
hasMatch = true;
|
|
310
|
-
break;
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
if (hasMatch) {
|
|
315
|
-
return workspaces;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
exports.addToPackageManagerWorkspaces = addToPackageManagerWorkspaces;
|
|
322
|
-
exports.addToTsConfig = addToTsConfig;
|
|
323
|
-
exports.createOutputTarget = createOutputTarget;
|
|
324
|
-
exports.emptyDirectory = emptyDirectory;
|
|
325
|
-
exports.format = format;
|
|
326
|
-
exports.isEmpty = isEmpty;
|
|
327
|
-
exports.loadTemplate = loadTemplate;
|
|
328
|
-
exports.mergeDependencies = mergeDependencies;
|
|
329
|
-
exports.relativeDirectoryForDisplay = relativeDirectoryForDisplay;
|
|
330
|
-
exports.toValidPackageName = toValidPackageName;
|