@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.
@@ -1,299 +0,0 @@
1
- import * as path from 'node:path';
2
- import { relative } from 'node:path';
3
- import * as fs from 'node:fs';
4
- import { fileURLToPath } from 'node:url';
5
- import './index.mjs';
6
-
7
- function loadTemplate(name) {
8
- let templateRootPromise;
9
- return {
10
- async copy(to, handleFile) {
11
- var _templateRootPromise;
12
-
13
- (_templateRootPromise = templateRootPromise) !== null && _templateRootPromise !== void 0 ? _templateRootPromise : templateRootPromise = templateDirectory(name);
14
- const templateRoot = await templateRootPromise;
15
- const targetRoot = path.resolve(to);
16
- const files = fs.readdirSync(templateRoot).filter(file => !path.basename(file).startsWith('.'));
17
-
18
- for (const file of files) {
19
- if (handleFile) {
20
- if (!handleFile(file)) {
21
- continue;
22
- }
23
- }
24
-
25
- const targetPath = path.join(targetRoot, file.startsWith('_') ? `.${file.slice(1)}` : file);
26
- copy(path.join(templateRoot, file), targetPath);
27
- }
28
- },
29
-
30
- async read(file) {
31
- var _templateRootPromise2;
32
-
33
- (_templateRootPromise2 = templateRootPromise) !== null && _templateRootPromise2 !== void 0 ? _templateRootPromise2 : templateRootPromise = templateDirectory(name);
34
- const templateRoot = await templateRootPromise;
35
- return fs.readFileSync(path.join(templateRoot, file), {
36
- encoding: 'utf8'
37
- });
38
- }
39
-
40
- };
41
- }
42
- function createOutputTarget(target) {
43
- return {
44
- root: target,
45
-
46
- read(file) {
47
- return fs.promises.readFile(path.resolve(target, file), {
48
- encoding: 'utf8'
49
- });
50
- },
51
-
52
- async write(file, content) {
53
- await writeFile(path.resolve(target, file), content);
54
- }
55
-
56
- };
57
- }
58
- let packageRootPromise;
59
-
60
- async function templateDirectory(name) {
61
- return path.join(await getPackageRoot(), 'templates', name);
62
- }
63
-
64
- async function getPackageRoot() {
65
- if (!packageRootPromise) {
66
- packageRootPromise = (async () => {
67
- const {
68
- packageDirectory
69
- } = await import('./index2.mjs');
70
- return packageDirectory({
71
- cwd: path.dirname(fileURLToPath(import.meta.url))
72
- });
73
- })();
74
- }
75
-
76
- return packageRootPromise;
77
- }
78
-
79
- function toValidPackageName(projectName) {
80
- return projectName.trim().toLowerCase().replace(/\s+/g, '-').replace(/^[._]/, '').replace(/[^a-z0-9-~@/]+/g, '-');
81
- }
82
-
83
- function copy(source, destination) {
84
- const stat = fs.statSync(source);
85
-
86
- if (stat.isDirectory()) {
87
- copyDirectory(source, destination);
88
- } else {
89
- fs.copyFileSync(source, destination);
90
- }
91
- }
92
-
93
- async function copyDirectory(source, destination) {
94
- fs.mkdirSync(destination, {
95
- recursive: true
96
- });
97
-
98
- for (const file of fs.readdirSync(source)) {
99
- const srcFile = path.resolve(source, file);
100
- const destFile = path.resolve(destination, file);
101
- copy(srcFile, destFile);
102
- }
103
- }
104
-
105
- async function writeFile(file, content) {
106
- await fs.promises.writeFile(file, content);
107
- }
108
- async function isEmpty(path) {
109
- return fs.readdirSync(path).length === 0;
110
- }
111
- async function emptyDirectory(dir) {
112
- if (!fs.existsSync(dir)) {
113
- return;
114
- }
115
-
116
- for (const file of fs.readdirSync(dir)) {
117
- fs.rmSync(path.resolve(dir, file), {
118
- force: true,
119
- recursive: true
120
- });
121
- }
122
- }
123
- function relativeDirectoryForDisplay(relativeDirectory) {
124
- return relativeDirectory.startsWith('.') ? relativeDirectory : `.${path.sep}${relativeDirectory}`;
125
- }
126
- async function format(content, {
127
- as: parser
128
- }) {
129
- const [{
130
- format
131
- }, {
132
- default: babel
133
- }, {
134
- default: typescript
135
- }, {
136
- default: yaml
137
- }] = await Promise.all([import('./standalone.mjs').then(function (n) { return n.s; }), import('./parser-babel.mjs').then(function (n) { return n.p; }), import('./parser-typescript.mjs').then(function (n) { return n.p; }), import('./parser-yaml.mjs').then(function (n) { return n.p; })]);
138
- return format(content, {
139
- arrowParens: 'always',
140
- bracketSpacing: false,
141
- singleQuote: true,
142
- trailingComma: 'all',
143
- parser,
144
- plugins: [babel, typescript, yaml]
145
- });
146
- }
147
- function mergeDependencies(first = {}, second = {}) {
148
- const all = { ...first,
149
- ...second
150
- };
151
- const merged = {};
152
-
153
- for (const [key, value] of Object.entries(all).sort(([keyOne], [keyTwo]) => keyOne.localeCompare(keyTwo))) {
154
- merged[key] = value;
155
- }
156
-
157
- return merged;
158
- }
159
-
160
- const ENDS_WITH_TSCONFIG = /[/]?tsconfig[.a-z0-9]*[.]json/i;
161
- async function addToTsConfig(directory, output) {
162
- var _tsconfig$references;
163
-
164
- const tsconfig = JSON.parse(await output.read('tsconfig.json'));
165
- (_tsconfig$references = tsconfig.references) !== null && _tsconfig$references !== void 0 ? _tsconfig$references : tsconfig.references = [];
166
- const relativePath = relative(output.root, directory);
167
- const relativeForDisplay = relativeDirectoryForDisplay(relativePath);
168
-
169
- if (tsconfig.references.length === 0) {
170
- tsconfig.references.push({
171
- path: relativeForDisplay
172
- });
173
- } else {
174
- let hasExistingReference = false;
175
- let referenceFormat = 'pretty-relative';
176
-
177
- for (const {
178
- path
179
- } of tsconfig.references) {
180
- if (path.startsWith('./')) {
181
- if (ENDS_WITH_TSCONFIG.test(path)) {
182
- referenceFormat = 'pretty-tsconfig';
183
-
184
- if (path === `${relativeForDisplay}/tsconfig.json`) {
185
- hasExistingReference = true;
186
- break;
187
- }
188
- }
189
-
190
- referenceFormat = 'pretty-relative';
191
-
192
- if (path === relativeForDisplay) {
193
- hasExistingReference = true;
194
- break;
195
- }
196
- } else if (ENDS_WITH_TSCONFIG.test(path)) {
197
- referenceFormat = 'tsconfig';
198
-
199
- if (path === `${relativePath}/tsconfig.json`) {
200
- hasExistingReference = true;
201
- break;
202
- }
203
- } else {
204
- referenceFormat = 'relative';
205
-
206
- if (path === relativePath) {
207
- hasExistingReference = true;
208
- break;
209
- }
210
- }
211
- }
212
-
213
- if (!hasExistingReference) {
214
- let path;
215
-
216
- if (referenceFormat === 'pretty-tsconfig') {
217
- path = `${relativeForDisplay}/tsconfig.json`;
218
- } else if (referenceFormat === 'pretty-relative') {
219
- path = relativeForDisplay;
220
- } else if (referenceFormat === 'tsconfig') {
221
- path = `${relativePath}/tsconfig.json`;
222
- } else {
223
- path = relativePath;
224
- }
225
-
226
- tsconfig.references.push({
227
- path
228
- });
229
- }
230
- }
231
-
232
- tsconfig.references = tsconfig.references.sort(({
233
- path: pathOne
234
- }, {
235
- path: pathTwo
236
- }) => pathOne.localeCompare(pathTwo));
237
- await output.write('tsconfig.json', await format(JSON.stringify(tsconfig), {
238
- as: 'json'
239
- }));
240
- }
241
-
242
- async function addToPackageManagerWorkspaces(directory, output, packageManager) {
243
- if (packageManager === 'pnpm') {
244
- var _workspaceYaml$packag;
245
-
246
- const {
247
- parse,
248
- stringify
249
- } = await import('./index3.mjs').then(function (n) { return n.i; });
250
- const workspaceYaml = parse(await output.read('pnpm-workspace.yaml'));
251
- workspaceYaml.packages = await addToWorkspaces(relative(output.root, directory), (_workspaceYaml$packag = workspaceYaml.packages) !== null && _workspaceYaml$packag !== void 0 ? _workspaceYaml$packag : []);
252
- await output.write('pnpm-workspace.yaml', await format(stringify(workspaceYaml), {
253
- as: 'yaml'
254
- }));
255
- } else {
256
- var _packageJson$workspac;
257
-
258
- const packageJson = JSON.parse(await output.read('package.json'));
259
- packageJson.workspaces = await addToWorkspaces(relative(output.root, directory), (_packageJson$workspac = packageJson.workspaces) !== null && _packageJson$workspac !== void 0 ? _packageJson$workspac : []);
260
- await output.write('package.json', await format(JSON.stringify(packageJson), {
261
- as: 'json-stringify'
262
- }));
263
- }
264
- }
265
-
266
- async function addToWorkspaces(relative, workspaces) {
267
- if (workspaces.length === 0) {
268
- return [relative];
269
- } // Default documentation seems to generally exclude leading `./` on paths
270
-
271
-
272
- let pretty = false;
273
- let hasMatch = false;
274
- const {
275
- default: minimatch
276
- } = await import('./minimatch.mjs').then(function (n) { return n.m; });
277
-
278
- for (const pattern of workspaces) {
279
- let normalizedPattern = pattern;
280
-
281
- if (pattern.startsWith('./')) {
282
- pretty = true;
283
- normalizedPattern = pattern.slice(2);
284
- }
285
-
286
- if (minimatch(relative, normalizedPattern)) {
287
- hasMatch = true;
288
- break;
289
- }
290
- }
291
-
292
- if (hasMatch) {
293
- return workspaces;
294
- }
295
-
296
- return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
297
- }
298
-
299
- export { addToTsConfig as a, addToPackageManagerWorkspaces as b, createOutputTarget as c, emptyDirectory as e, format as f, isEmpty as i, loadTemplate as l, mergeDependencies as m, relativeDirectoryForDisplay as r, toValidPackageName as t };