@quilted/create 0.1.20 → 0.1.23

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @quilted/create
2
2
 
3
+ ## 0.1.23
4
+
5
+ ### Patch Changes
6
+
7
+ - [#373](https://github.com/lemonmade/quilt/pull/373) [`a626d243`](https://github.com/lemonmade/quilt/commit/a626d24384548fc674ec180d221b00bb633c9358) Thanks [@lemonmade](https://github.com/lemonmade)! - Add quilt run command
8
+
9
+ ## 0.1.22
10
+
11
+ ### Patch Changes
12
+
13
+ - [`a12c3576`](https://github.com/lemonmade/quilt/commit/a12c357693b173461f51a35fb7efdd0a9267e471) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix more build issues
14
+
15
+ ## 0.1.21
16
+
17
+ ### Patch Changes
18
+
19
+ - [`0629288e`](https://github.com/lemonmade/quilt/commit/0629288ee4ba2e2ccfd73fbb216c3559e1a5c77e) Thanks [@lemonmade](https://github.com/lemonmade)! - Fix missing package builds
20
+
3
21
  ## 0.1.20
4
22
 
5
23
  ### Patch Changes
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node --experimental-vm-modules
2
+ import "../build/esm/index.mjs";
@@ -0,0 +1,309 @@
1
+ 'use strict';
2
+
3
+ var fs = require('fs');
4
+ var path = require('path');
5
+ var child_process = require('child_process');
6
+ var index = require('./index.cjs');
7
+ var packageManager = require('./package-manager.cjs');
8
+ require('tty');
9
+ require('url');
10
+ require('readline');
11
+ require('events');
12
+
13
+ function _interopNamespace(e) {
14
+ if (e && e.__esModule) return e;
15
+ var n = Object.create(null);
16
+ if (e) {
17
+ Object.keys(e).forEach(function (k) {
18
+ if (k !== 'default') {
19
+ var d = Object.getOwnPropertyDescriptor(e, k);
20
+ Object.defineProperty(n, k, d.get ? d : {
21
+ enumerable: true,
22
+ get: function () { return e[k]; }
23
+ });
24
+ }
25
+ });
26
+ }
27
+ n["default"] = e;
28
+ return Object.freeze(n);
29
+ }
30
+
31
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
32
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
33
+
34
+ let _ = t => t,
35
+ _t,
36
+ _t2,
37
+ _t3;
38
+ async function createApp() {
39
+ const argv = getArgv();
40
+
41
+ if (argv['--help']) {
42
+ var _argv$PackageManag;
43
+
44
+ const additionalOptions = index.stripIndent(_t || (_t = _`
45
+ ${0}
46
+ The template to use for your new application. If you don’t specify a template,
47
+ this command will ask you for one instead. Must be one of the following:
48
+
49
+ - ${0}, a web app with a minimal file structure
50
+ - ${0}, an entire web app in a single file
51
+ `), index.cyan_1(`--template`), index.bold_1('basic'), index.bold_1('single-file'));
52
+ index.printHelp({
53
+ kind: 'app',
54
+ options: additionalOptions,
55
+ packageManager: (_argv$PackageManag = argv['--package-manager']) === null || _argv$PackageManag === void 0 ? void 0 : _argv$PackageManag.toLowerCase()
56
+ });
57
+ return;
58
+ }
59
+
60
+ const inWorkspace = fs__namespace.existsSync('quilt.workspace.ts');
61
+ const name = await getName(argv, {
62
+ inWorkspace
63
+ });
64
+ const directory = await getDirectory(argv, {
65
+ name
66
+ });
67
+ const template = await getTemplate(argv);
68
+ const createAsMonorepo = !inWorkspace && (await index.getCreateAsMonorepo(argv));
69
+ const shouldInstall = await index.getShouldInstall(argv);
70
+ const packageManager$1 = await index.getPackageManager(argv);
71
+ const setupExtras = await index.getExtrasToSetup(argv, {
72
+ inWorkspace
73
+ });
74
+ const partOfMonorepo = inWorkspace || createAsMonorepo;
75
+ const appDirectory = createAsMonorepo ? path__namespace.join(directory, 'app') : directory;
76
+
77
+ if (fs__namespace.existsSync(directory)) {
78
+ await packageManager.emptyDirectory(directory);
79
+
80
+ if (appDirectory !== directory) {
81
+ fs__namespace.mkdirSync(appDirectory, {
82
+ recursive: true
83
+ });
84
+ }
85
+ } else {
86
+ fs__namespace.mkdirSync(appDirectory, {
87
+ recursive: true
88
+ });
89
+ }
90
+
91
+ const rootDirectory = inWorkspace ? process.cwd() : directory;
92
+ const outputRoot = packageManager.createOutputTarget(rootDirectory);
93
+ const appTemplate = packageManager.loadTemplate(template === 'basic' ? 'app-basic' : 'app-single-file');
94
+ const workspaceTemplate = packageManager.loadTemplate('workspace'); // If we aren’t already in a workspace, copy the workspace files over, which
95
+ // are needed if we are making a monorepo or not.
96
+
97
+ if (!inWorkspace) {
98
+ await workspaceTemplate.copy(directory, file => {
99
+ // When this is a single project, we use the project’s Quilt configuration as the base.
100
+ if (file === 'quilt.workspace.ts') return createAsMonorepo; // We need to make some adjustments to the root package.json
101
+
102
+ return file !== 'package.json';
103
+ }); // If we are creating a monorepo, we need to add the root package.json and
104
+ // package manager workspace configuration.
105
+
106
+ if (createAsMonorepo) {
107
+ const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
108
+ workspacePackageJson.name = packageManager.toValidPackageName(name);
109
+
110
+ if (packageManager$1 === 'pnpm') {
111
+ await outputRoot.write('pnpm-workspace.yaml', await packageManager.format(`
112
+ packages:
113
+ - './packages/*'
114
+ `, {
115
+ as: 'yaml'
116
+ }));
117
+ } else {
118
+ workspacePackageJson.workspaces = ['packages/*'];
119
+ }
120
+
121
+ await outputRoot.write('package.json', await packageManager.format(JSON.stringify(workspacePackageJson), {
122
+ as: 'json-stringify'
123
+ }));
124
+ } else {
125
+ const [projectPackageJson, projectTSConfig, workspacePackageJson] = await Promise.all([appTemplate.read('package.json').then(content => JSON.parse(content)), appTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
126
+ workspacePackageJson.name = packageManager.toValidPackageName(name);
127
+ workspacePackageJson.eslintConfig = projectPackageJson.eslintConfig;
128
+ workspacePackageJson.browserslist = projectPackageJson.browserslist;
129
+ let quiltProject = await appTemplate.read('quilt.project.ts');
130
+ quiltProject = quiltProject.replace('quiltApp', 'quiltWorkspace, quiltApp').replace('quiltApp(', 'quiltWorkspace(), quiltApp(');
131
+ await outputRoot.write('quilt.project.ts', await packageManager.format(quiltProject, {
132
+ as: 'typescript'
133
+ }));
134
+ await outputRoot.write('package.json', await packageManager.format(JSON.stringify(workspacePackageJson), {
135
+ as: 'json-stringify'
136
+ }));
137
+ await outputRoot.write('tsconfig.json', await packageManager.format(JSON.stringify(projectTSConfig), {
138
+ as: 'json'
139
+ }));
140
+ }
141
+
142
+ if (setupExtras.has('github')) {
143
+ await packageManager.loadTemplate('github').copy(directory);
144
+ }
145
+
146
+ if (setupExtras.has('vscode')) {
147
+ await packageManager.loadTemplate('vscode').copy(directory);
148
+ }
149
+ }
150
+
151
+ await appTemplate.copy(appDirectory, file => {
152
+ // If we are in a monorepo, we can use all the template files as they are
153
+ if (file === 'quilt.project.ts' || file === 'tsconfig.json') {
154
+ return partOfMonorepo;
155
+ } // We need to make some adjustments the project’s package.json
156
+
157
+
158
+ return file !== 'package.json';
159
+ });
160
+
161
+ if (partOfMonorepo) {
162
+ // Write the app’s package.json (the root one was already created)
163
+ const projectPackageJson = JSON.parse(await appTemplate.read('package.json'));
164
+ projectPackageJson.name = path__namespace.basename(appDirectory);
165
+ await outputRoot.write(path__namespace.join(appDirectory, 'package.json'), await packageManager.format(JSON.stringify(projectPackageJson), {
166
+ as: 'json-stringify'
167
+ }));
168
+ await Promise.all([packageManager.addToTsConfig(appDirectory, outputRoot), packageManager.addToPackageManagerWorkspaces(appDirectory, outputRoot, packageManager$1)]);
169
+ }
170
+
171
+ if (shouldInstall) {
172
+ process.stdout.write('\nInstalling dependencies...\n'); // TODO: better loading, handle errors
173
+
174
+ child_process.execSync(`${packageManager$1} install`, {
175
+ cwd: rootDirectory
176
+ });
177
+ process.stdout.moveCursor(0, -1);
178
+ process.stdout.clearLine(1);
179
+ console.log('Installed dependencies.');
180
+ }
181
+
182
+ const commands = [];
183
+
184
+ if (!inWorkspace && directory !== process.cwd()) {
185
+ commands.push(`cd ${index.cyan_1(packageManager.relativeDirectoryForDisplay(path__namespace.relative(process.cwd(), directory)))} ${index.dim_1('# Move into your new app’s directory')}`);
186
+ }
187
+
188
+ if (!shouldInstall) {
189
+ commands.push(`pnpm install ${index.dim_1('# Install all your dependencies')}`);
190
+ }
191
+
192
+ if (!inWorkspace) {
193
+ // TODO: change this condition to check if git was initialized already
194
+ commands.push(`git init && git add -A && git commit -m "Initial commit" ${index.dim_1('# Start your git history (optional)')}`);
195
+ }
196
+
197
+ commands.push(`pnpm develop ${index.dim_1('# Start the development server')}`);
198
+ const whatsNext = index.stripIndent(_t2 || (_t2 = _`
199
+ Your new app is ready to go! There’s just ${0} you’ll need to take
200
+ in order to start developing:
201
+ `), commands.length > 1 ? 'a few more steps' : 'one more step');
202
+ console.log();
203
+ console.log(whatsNext);
204
+ console.log();
205
+ console.log(commands.map(command => ` ${command}`).join('\n'));
206
+ const followUp = index.stripIndent(_t3 || (_t3 = _`
207
+ Quilt can also help you build, test, lint, and type-check your new application.
208
+ You can learn more about building apps with Quilt by reading the documentation:
209
+ ${0}
210
+
211
+ Have fun! 🎉
212
+ `), index.underline_1(index.magenta_1('https://github.com/lemonmade/quilt/tree/main/documentation')));
213
+ console.log();
214
+ console.log(followUp);
215
+ } // Argument handling
216
+
217
+ function getArgv() {
218
+ const argv = index.arg_1({
219
+ '--yes': Boolean,
220
+ '-y': '--yes',
221
+ '--name': String,
222
+ '--template': String,
223
+ '--directory': String,
224
+ '--install': Boolean,
225
+ '--no-install': Boolean,
226
+ '--monorepo': Boolean,
227
+ '--no-monorepo': Boolean,
228
+ '--package-manager': String,
229
+ '--extras': [String],
230
+ '--no-extras': Boolean,
231
+ '--help': Boolean,
232
+ '-h': '--help'
233
+ }, {
234
+ permissive: true
235
+ });
236
+ return argv;
237
+ }
238
+
239
+ async function getName(argv, {
240
+ inWorkspace
241
+ }) {
242
+ let {
243
+ '--name': name
244
+ } = argv;
245
+
246
+ if (name == null) {
247
+ name = await index.prompt({
248
+ type: 'text',
249
+ message: 'What would you like to name your new app?',
250
+ initial: inWorkspace ? 'app' : 'my-quilt-app'
251
+ });
252
+ }
253
+
254
+ return name;
255
+ }
256
+
257
+ async function getDirectory(argv, {
258
+ name
259
+ }) {
260
+ var _argv$Directory;
261
+
262
+ let directory = path__namespace.resolve((_argv$Directory = argv['--directory']) !== null && _argv$Directory !== void 0 ? _argv$Directory : packageManager.toValidPackageName(name));
263
+
264
+ while (!argv['--yes']) {
265
+ if (fs__namespace.existsSync(directory) && !(await packageManager.isEmpty(directory))) {
266
+ const relativeDirectory = path__namespace.relative(process.cwd(), directory);
267
+ const empty = await index.prompt({
268
+ type: 'confirm',
269
+ message: `Directory ${index.bold_1(packageManager.relativeDirectoryForDisplay(relativeDirectory))} is not empty, is it safe to empty it?`,
270
+ initial: true
271
+ });
272
+ if (empty) break;
273
+ const promptDirectory = await index.prompt({
274
+ type: 'text',
275
+ message: 'What directory do you want to create your new app in?'
276
+ });
277
+ directory = path__namespace.resolve(promptDirectory);
278
+ } else {
279
+ break;
280
+ }
281
+ }
282
+
283
+ return directory;
284
+ }
285
+
286
+ const VALID_TEMPLATES = new Set(['basic', 'single-file']);
287
+
288
+ async function getTemplate(argv) {
289
+ if (argv['--template'] && VALID_TEMPLATES.has(argv['--template'])) {
290
+ return argv['--template'];
291
+ }
292
+
293
+ const template = await index.prompt({
294
+ type: 'select',
295
+ message: 'What template would you like to use?',
296
+ hint: `Use ${index.bold_1('arrow keys')} to select, and ${index.bold_1('return')} to submit`,
297
+ choices: [{
298
+ title: `${index.bold_1('The basics')}, a web app with a minimal file structure`,
299
+ value: 'basic'
300
+ }, {
301
+ title: `${index.bold_1('Itty-bitty')}, an entire web app in a single file`,
302
+ value: 'single-file'
303
+ } // TODO: GraphQL API
304
+ ]
305
+ });
306
+ return template;
307
+ }
308
+
309
+ exports.createApp = createApp;