create-moost 0.3.10 → 0.3.12

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 CHANGED
@@ -22,7 +22,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
22
22
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
23
23
  PERFORMANCE OF THIS SOFTWARE.
24
24
  ***************************************************************************** */
25
- /* global Reflect, Promise */
25
+ /* global Reflect, Promise, SuppressedError, Symbol */
26
26
 
27
27
 
28
28
  function __decorate(decorators, target, key, desc) {
@@ -40,254 +40,246 @@ function __metadata(metadataKey, metadataValue) {
40
40
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
41
41
  }
42
42
 
43
- function __awaiter(thisArg, _arguments, P, generator) {
44
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
45
- return new (P || (P = Promise))(function (resolve, reject) {
46
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
47
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
48
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
49
- step((generator = generator.apply(thisArg, _arguments || [])).next());
50
- });
51
- }
43
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
44
+ var e = new Error(message);
45
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
46
+ };
52
47
 
53
- const defaultProjectName = 'moost-app';
54
- function getPrompts(inputs) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const predefined = {
57
- targetDir: inputs.name || '',
58
- projectName: inputs.name || '',
59
- packageName: inputs.name || '',
60
- prettier: !!inputs.prettier,
61
- eslint: !!inputs.eslint,
62
- };
63
- try {
64
- const results = yield prompts([
65
- {
66
- name: 'projectName',
67
- type: predefined.targetDir ? null : 'text',
68
- message: 'Project name:',
69
- initial: defaultProjectName,
70
- onState: (state) => (predefined.targetDir =
71
- String(state.value).trim() || defaultProjectName),
72
- },
73
- {
74
- name: 'overwrite',
75
- type: () => canSkipEmptying(predefined.targetDir) || inputs.force
76
- ? null
77
- : 'confirm',
78
- message: () => {
79
- const dirForPrompt = predefined.targetDir === '.'
80
- ? 'Current directory'
81
- : `Target directory "${predefined.targetDir}"`;
82
- return `${dirForPrompt} is not empty. Remove existing files and continue?`;
83
- },
84
- },
85
- {
86
- name: 'overwriteChecker',
87
- type: (prev, values) => {
88
- if (values.overwrite === false) {
89
- throw new Error('Operation cancelled');
90
- }
91
- return null;
92
- },
93
- },
94
- {
95
- name: 'type',
96
- type: () => {
97
- if (inputs.cli && !inputs.http) {
98
- predefined.type = 'cli';
99
- return null;
100
- }
101
- if (!inputs.cli && inputs.http) {
102
- predefined.type = 'http';
103
- return null;
104
- }
105
- return 'select';
106
- },
107
- message: 'Moost Adapter:',
108
- choices: [
109
- { title: 'HTTP (Web) Application', value: 'http' },
110
- { title: 'CLI Application', value: 'cli' },
111
- ],
112
- },
113
- {
114
- name: 'bundler',
115
- type: () => {
116
- if (inputs.esbuild && !inputs.rollup) {
117
- predefined.bundler = 'esbuild';
118
- return null;
119
- }
120
- if (!inputs.esbuild && inputs.rollup) {
121
- predefined.bundler = 'rollup';
122
- return null;
123
- }
124
- return 'select';
125
- },
126
- message: 'Bundler:',
127
- choices: [
128
- { title: 'Rollup (recommended)', value: 'rollup' },
129
- { title: 'ESBuild', value: 'esbuild' },
130
- ],
131
- },
132
- {
133
- name: 'packageName',
134
- type: () => (isValidPackageName(predefined.targetDir) ? null : 'text'),
135
- message: 'Package name:',
136
- initial: () => toValidPackageName(predefined.targetDir),
137
- validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
138
- },
139
- {
140
- name: 'eslint',
141
- type: () => (inputs.eslint ? null : 'toggle'),
142
- message: 'Add ESLint for code quality?',
143
- initial: false,
144
- active: 'Yes',
145
- inactive: 'No',
146
- },
147
- {
148
- name: 'prettier',
149
- type: (prev, values) => {
150
- if (!values.eslint) {
151
- return null;
152
- }
153
- return 'toggle';
154
- },
155
- message: 'Add Prettier for code formatting?',
156
- initial: false,
157
- active: 'Yes',
158
- inactive: 'No',
159
- },
160
- ], {
161
- onCancel: () => {
162
- throw new Error('Operation cancelled');
163
- },
164
- });
165
- return Object.assign(Object.assign(Object.assign({}, predefined), results), { packageName: (results.packageName || results.targetDir || predefined.targetDir) });
166
- }
167
- catch (e) {
168
- console.log(e.message);
169
- process.exit(1);
170
- }
171
- });
172
- }
173
- function canSkipEmptying(dir) {
174
- if (!fs.existsSync(dir)) {
175
- return true;
176
- }
177
- const files = fs.readdirSync(dir);
178
- if (files.length === 0) {
179
- return true;
180
- }
181
- if (files.length === 1 && files[0] === '.git') {
182
- return true;
183
- }
184
- return false;
185
- }
186
- function isValidPackageName(projectName) {
187
- return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
188
- }
189
- function toValidPackageName(projectName) {
190
- return projectName
191
- .trim()
192
- .toLowerCase()
193
- .replace(/\s+/g, '-')
194
- .replace(/^[._]/, '')
195
- .replace(/[^a-z0-9-~]+/g, '-');
48
+ const defaultProjectName = 'moost-app';
49
+ async function getPrompts(inputs) {
50
+ const predefined = {
51
+ targetDir: inputs.name || '',
52
+ projectName: inputs.name || '',
53
+ packageName: inputs.name || '',
54
+ prettier: !!inputs.prettier,
55
+ eslint: !!inputs.eslint,
56
+ };
57
+ try {
58
+ const results = await prompts([
59
+ {
60
+ name: 'projectName',
61
+ type: predefined.targetDir ? null : 'text',
62
+ message: 'Project name:',
63
+ initial: defaultProjectName,
64
+ onState: (state) => (predefined.targetDir =
65
+ String(state.value).trim() || defaultProjectName),
66
+ },
67
+ {
68
+ name: 'overwrite',
69
+ type: () => canSkipEmptying(predefined.targetDir) || inputs.force
70
+ ? null
71
+ : 'confirm',
72
+ message: () => {
73
+ const dirForPrompt = predefined.targetDir === '.'
74
+ ? 'Current directory'
75
+ : `Target directory "${predefined.targetDir}"`;
76
+ return `${dirForPrompt} is not empty. Remove existing files and continue?`;
77
+ },
78
+ },
79
+ {
80
+ name: 'overwriteChecker',
81
+ type: (prev, values) => {
82
+ if (values.overwrite === false) {
83
+ throw new Error('Operation cancelled');
84
+ }
85
+ return null;
86
+ },
87
+ },
88
+ {
89
+ name: 'type',
90
+ type: () => {
91
+ if (inputs.cli && !inputs.http) {
92
+ predefined.type = 'cli';
93
+ return null;
94
+ }
95
+ if (!inputs.cli && inputs.http) {
96
+ predefined.type = 'http';
97
+ return null;
98
+ }
99
+ return 'select';
100
+ },
101
+ message: 'Moost Adapter:',
102
+ choices: [
103
+ { title: 'HTTP (Web) Application', value: 'http' },
104
+ { title: 'CLI Application', value: 'cli' },
105
+ ],
106
+ },
107
+ {
108
+ name: 'bundler',
109
+ type: () => {
110
+ if (inputs.esbuild && !inputs.rollup) {
111
+ predefined.bundler = 'esbuild';
112
+ return null;
113
+ }
114
+ if (!inputs.esbuild && inputs.rollup) {
115
+ predefined.bundler = 'rollup';
116
+ return null;
117
+ }
118
+ return 'select';
119
+ },
120
+ message: 'Bundler:',
121
+ choices: [
122
+ { title: 'Rollup (recommended)', value: 'rollup' },
123
+ { title: 'ESBuild', value: 'esbuild' },
124
+ ],
125
+ },
126
+ {
127
+ name: 'packageName',
128
+ type: () => (isValidPackageName(predefined.targetDir) ? null : 'text'),
129
+ message: 'Package name:',
130
+ initial: () => toValidPackageName(predefined.targetDir),
131
+ validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
132
+ },
133
+ {
134
+ name: 'eslint',
135
+ type: () => (inputs.eslint ? null : 'toggle'),
136
+ message: 'Add ESLint for code quality?',
137
+ initial: false,
138
+ active: 'Yes',
139
+ inactive: 'No',
140
+ },
141
+ {
142
+ name: 'prettier',
143
+ type: (prev, values) => {
144
+ if (!values.eslint) {
145
+ return null;
146
+ }
147
+ return 'toggle';
148
+ },
149
+ message: 'Add Prettier for code formatting?',
150
+ initial: false,
151
+ active: 'Yes',
152
+ inactive: 'No',
153
+ },
154
+ ], {
155
+ onCancel: () => {
156
+ throw new Error('Operation cancelled');
157
+ },
158
+ });
159
+ return {
160
+ ...predefined,
161
+ ...results,
162
+ packageName: (results.packageName || results.targetDir || predefined.targetDir),
163
+ };
164
+ }
165
+ catch (e) {
166
+ console.log(e.message);
167
+ process.exit(1);
168
+ }
169
+ }
170
+ function canSkipEmptying(dir) {
171
+ if (!fs.existsSync(dir)) {
172
+ return true;
173
+ }
174
+ const files = fs.readdirSync(dir);
175
+ if (files.length === 0) {
176
+ return true;
177
+ }
178
+ if (files.length === 1 && files[0] === '.git') {
179
+ return true;
180
+ }
181
+ return false;
182
+ }
183
+ function isValidPackageName(projectName) {
184
+ return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
185
+ }
186
+ function toValidPackageName(projectName) {
187
+ return projectName
188
+ .trim()
189
+ .toLowerCase()
190
+ .replace(/\s+/g, '-')
191
+ .replace(/^[._]/, '')
192
+ .replace(/[^a-z0-9-~]+/g, '-');
196
193
  }
197
194
 
198
- const rw = new rewrite.ProstoRewrite({
199
- textPattern: [
200
- '*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
201
- 'Dockerfile',
202
- '*config',
203
- '.gitignore',
204
- '.eslintrc.json',
205
- '.prettierignore',
206
- '.prettierrc',
207
- ],
208
- });
209
- const root = process.cwd();
210
- const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')).toString());
211
- function scaffold(data) {
212
- return __awaiter(this, void 0, void 0, function* () {
213
- const projectDir = path.join(root, data.targetDir);
214
- if (fs.existsSync(projectDir)) {
215
- if (data.overwrite) {
216
- emptyDirectorySync(projectDir);
217
- }
218
- }
219
- else {
220
- fs.mkdirSync(projectDir);
221
- }
222
- const templatePath = path.join(__dirname, '../templates', data.type);
223
- const commonPath = path.join(__dirname, '../templates/common');
224
- const context = Object.assign(Object.assign({}, data), { version });
225
- const excludeCommon = [];
226
- if (!data.eslint) {
227
- excludeCommon.push('.eslintrc.json');
228
- }
229
- if (!data.prettier) {
230
- excludeCommon.push('.prettierignore');
231
- excludeCommon.push('.prettierrc');
232
- }
233
- if (data.bundler !== 'rollup') {
234
- excludeCommon.push('rollup.config.js');
235
- }
236
- if (data.bundler !== 'esbuild') {
237
- excludeCommon.push('build.js');
238
- }
239
- yield rw.rewriteDir({
240
- baseDir: templatePath,
241
- output: projectDir,
242
- }, context);
243
- yield rw.rewriteDir({
244
- baseDir: commonPath,
245
- output: projectDir,
246
- exclude: excludeCommon,
247
- }, context);
248
- });
249
- }
250
- function emptyDirectorySync(directory) {
251
- if (fs.existsSync(directory)) {
252
- fs.readdirSync(directory).forEach((file) => {
253
- const currentPath = path.join(directory, file);
254
- if (fs.lstatSync(currentPath).isDirectory()) {
255
- // Recurse if the current path is a directory
256
- emptyDirectorySync(currentPath);
257
- fs.rmdirSync(currentPath); // Remove the empty directory
258
- }
259
- else {
260
- // Delete file
261
- fs.unlinkSync(currentPath);
262
- }
263
- });
264
- }
195
+ const rw = new rewrite.ProstoRewrite({
196
+ textPattern: [
197
+ '*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
198
+ 'Dockerfile',
199
+ '*config',
200
+ '.gitignore',
201
+ '.eslintrc.json',
202
+ '.prettierignore',
203
+ '.prettierrc',
204
+ ],
205
+ });
206
+ const root = process.cwd();
207
+ const { version } = JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json')).toString());
208
+ async function scaffold(data) {
209
+ const projectDir = path.join(root, data.targetDir);
210
+ if (fs.existsSync(projectDir)) {
211
+ if (data.overwrite) {
212
+ emptyDirectorySync(projectDir);
213
+ }
214
+ }
215
+ else {
216
+ fs.mkdirSync(projectDir);
217
+ }
218
+ const templatePath = path.join(__dirname, '../templates', data.type);
219
+ const commonPath = path.join(__dirname, '../templates/common');
220
+ const context = { ...data, version };
221
+ const excludeCommon = [];
222
+ if (!data.eslint) {
223
+ excludeCommon.push('.eslintrc.json');
224
+ }
225
+ if (!data.prettier) {
226
+ excludeCommon.push('.prettierignore');
227
+ excludeCommon.push('.prettierrc');
228
+ }
229
+ if (data.bundler !== 'rollup') {
230
+ excludeCommon.push('rollup.config.js');
231
+ }
232
+ if (data.bundler !== 'esbuild') {
233
+ excludeCommon.push('build.js');
234
+ }
235
+ await rw.rewriteDir({
236
+ baseDir: templatePath,
237
+ output: projectDir,
238
+ }, context);
239
+ await rw.rewriteDir({
240
+ baseDir: commonPath,
241
+ output: projectDir,
242
+ exclude: excludeCommon,
243
+ }, context);
244
+ }
245
+ function emptyDirectorySync(directory) {
246
+ if (fs.existsSync(directory)) {
247
+ fs.readdirSync(directory).forEach((file) => {
248
+ const currentPath = path.join(directory, file);
249
+ if (fs.lstatSync(currentPath).isDirectory()) {
250
+ emptyDirectorySync(currentPath);
251
+ fs.rmdirSync(currentPath);
252
+ }
253
+ else {
254
+ fs.unlinkSync(currentPath);
255
+ }
256
+ });
257
+ }
265
258
  }
266
259
 
267
- let CliController = class CliController extends moost.Moost {
268
- root() {
269
- return this.execute();
270
- }
271
- withName(name) {
272
- return this.execute(name);
273
- }
274
- execute(name) {
275
- return __awaiter(this, void 0, void 0, function* () {
276
- eventCli$1.useAutoHelp() && process.exit(0);
277
- const prompts = yield getPrompts({
278
- name,
279
- eslint: !!eventCli$1.useCliOption('eslint'),
280
- prettier: !!eventCli$1.useCliOption('prettier'),
281
- http: !!eventCli$1.useCliOption('http'),
282
- cli: !!eventCli$1.useCliOption('cli'),
283
- force: !!eventCli$1.useCliOption('force'),
284
- esbuild: !!eventCli$1.useCliOption('esbuild'),
285
- rollup: !!eventCli$1.useCliOption('rollup'),
286
- });
287
- console.log('\nScaffolding a new project...');
288
- yield scaffold(prompts);
289
- const cli = prompts.type === 'cli';
290
- return `
260
+ let CliController = class CliController extends moost.Moost {
261
+ root() {
262
+ return this.execute();
263
+ }
264
+ withName(name) {
265
+ return this.execute(name);
266
+ }
267
+ async execute(name) {
268
+ eventCli$1.useAutoHelp() && process.exit(0);
269
+ const prompts = await getPrompts({
270
+ name,
271
+ eslint: !!eventCli$1.useCliOption('eslint'),
272
+ prettier: !!eventCli$1.useCliOption('prettier'),
273
+ http: !!eventCli$1.useCliOption('http'),
274
+ cli: !!eventCli$1.useCliOption('cli'),
275
+ force: !!eventCli$1.useCliOption('force'),
276
+ esbuild: !!eventCli$1.useCliOption('esbuild'),
277
+ rollup: !!eventCli$1.useCliOption('rollup'),
278
+ });
279
+ console.log('\nScaffolding a new project...');
280
+ await scaffold(prompts);
281
+ const cli = prompts.type === 'cli';
282
+ return `
291
283
  ${'' + ''}Success! ${''}Your new "${prompts.projectName}" project has been created successfully. ${''}
292
284
 
293
285
  Follow these next steps to start your development server:
@@ -306,41 +298,39 @@ ${cli ? '4' : '3'}. Start the development server:
306
298
 
307
299
  ${''}You're all set! The development server will help you in building your application.
308
300
  Enjoy coding, and build something amazing!${''}
309
- `;
310
- });
311
- }
312
- };
313
- __decorate([
314
- eventCli.Cli(''),
315
- __metadata("design:type", Function),
316
- __metadata("design:paramtypes", []),
317
- __metadata("design:returntype", void 0)
318
- ], CliController.prototype, "root", null);
319
- __decorate([
320
- eventCli.Cli(':name'),
321
- __param(0, moost.Param('name')),
322
- __metadata("design:type", Function),
323
- __metadata("design:paramtypes", [String]),
324
- __metadata("design:returntype", void 0)
325
- ], CliController.prototype, "withName", null);
326
- CliController = __decorate([
327
- moost.Controller()
328
- ], CliController);
329
- function run() {
330
- const app = new CliController();
331
- app.adapter(new eventCli.MoostCli({
332
- globalCliOptions: [
333
- // { keys: ['ts'], description: '' },
334
- { keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
335
- { keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
336
- { keys: ['eslint'], description: 'Add ESLint', type: Boolean },
337
- { keys: ['prettier'], description: 'Add Prettier', type: Boolean },
338
- { keys: ['force'], description: 'Force Overwrite', type: Boolean },
339
- { keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
340
- { keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
341
- ],
342
- }));
343
- void app.init();
301
+ `;
302
+ }
303
+ };
304
+ __decorate([
305
+ eventCli.Cli(''),
306
+ __metadata("design:type", Function),
307
+ __metadata("design:paramtypes", []),
308
+ __metadata("design:returntype", void 0)
309
+ ], CliController.prototype, "root", null);
310
+ __decorate([
311
+ eventCli.Cli(':name'),
312
+ __param(0, moost.Param('name')),
313
+ __metadata("design:type", Function),
314
+ __metadata("design:paramtypes", [String]),
315
+ __metadata("design:returntype", void 0)
316
+ ], CliController.prototype, "withName", null);
317
+ CliController = __decorate([
318
+ moost.Controller()
319
+ ], CliController);
320
+ function run() {
321
+ const app = new CliController();
322
+ app.adapter(new eventCli.MoostCli({
323
+ globalCliOptions: [
324
+ { keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
325
+ { keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
326
+ { keys: ['eslint'], description: 'Add ESLint', type: Boolean },
327
+ { keys: ['prettier'], description: 'Add Prettier', type: Boolean },
328
+ { keys: ['force'], description: 'Force Overwrite', type: Boolean },
329
+ { keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
330
+ { keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
331
+ ],
332
+ }));
333
+ void app.init();
344
334
  }
345
335
 
346
336
  exports.run = run;
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export declare function run(): void;
2
-
3
- export { }
1
+ declare function run(): void;
2
+
3
+ export { run };
package/dist/index.mjs CHANGED
@@ -20,7 +20,7 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
20
20
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21
21
  PERFORMANCE OF THIS SOFTWARE.
22
22
  ***************************************************************************** */
23
- /* global Reflect, Promise */
23
+ /* global Reflect, Promise, SuppressedError, Symbol */
24
24
 
25
25
 
26
26
  function __decorate(decorators, target, key, desc) {
@@ -38,254 +38,246 @@ function __metadata(metadataKey, metadataValue) {
38
38
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
39
39
  }
40
40
 
41
- function __awaiter(thisArg, _arguments, P, generator) {
42
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
43
- return new (P || (P = Promise))(function (resolve, reject) {
44
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
46
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
47
- step((generator = generator.apply(thisArg, _arguments || [])).next());
48
- });
49
- }
41
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
42
+ var e = new Error(message);
43
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
44
+ };
50
45
 
51
- const defaultProjectName = 'moost-app';
52
- function getPrompts(inputs) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const predefined = {
55
- targetDir: inputs.name || '',
56
- projectName: inputs.name || '',
57
- packageName: inputs.name || '',
58
- prettier: !!inputs.prettier,
59
- eslint: !!inputs.eslint,
60
- };
61
- try {
62
- const results = yield prompts([
63
- {
64
- name: 'projectName',
65
- type: predefined.targetDir ? null : 'text',
66
- message: 'Project name:',
67
- initial: defaultProjectName,
68
- onState: (state) => (predefined.targetDir =
69
- String(state.value).trim() || defaultProjectName),
70
- },
71
- {
72
- name: 'overwrite',
73
- type: () => canSkipEmptying(predefined.targetDir) || inputs.force
74
- ? null
75
- : 'confirm',
76
- message: () => {
77
- const dirForPrompt = predefined.targetDir === '.'
78
- ? 'Current directory'
79
- : `Target directory "${predefined.targetDir}"`;
80
- return `${dirForPrompt} is not empty. Remove existing files and continue?`;
81
- },
82
- },
83
- {
84
- name: 'overwriteChecker',
85
- type: (prev, values) => {
86
- if (values.overwrite === false) {
87
- throw new Error('Operation cancelled');
88
- }
89
- return null;
90
- },
91
- },
92
- {
93
- name: 'type',
94
- type: () => {
95
- if (inputs.cli && !inputs.http) {
96
- predefined.type = 'cli';
97
- return null;
98
- }
99
- if (!inputs.cli && inputs.http) {
100
- predefined.type = 'http';
101
- return null;
102
- }
103
- return 'select';
104
- },
105
- message: 'Moost Adapter:',
106
- choices: [
107
- { title: 'HTTP (Web) Application', value: 'http' },
108
- { title: 'CLI Application', value: 'cli' },
109
- ],
110
- },
111
- {
112
- name: 'bundler',
113
- type: () => {
114
- if (inputs.esbuild && !inputs.rollup) {
115
- predefined.bundler = 'esbuild';
116
- return null;
117
- }
118
- if (!inputs.esbuild && inputs.rollup) {
119
- predefined.bundler = 'rollup';
120
- return null;
121
- }
122
- return 'select';
123
- },
124
- message: 'Bundler:',
125
- choices: [
126
- { title: 'Rollup (recommended)', value: 'rollup' },
127
- { title: 'ESBuild', value: 'esbuild' },
128
- ],
129
- },
130
- {
131
- name: 'packageName',
132
- type: () => (isValidPackageName(predefined.targetDir) ? null : 'text'),
133
- message: 'Package name:',
134
- initial: () => toValidPackageName(predefined.targetDir),
135
- validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
136
- },
137
- {
138
- name: 'eslint',
139
- type: () => (inputs.eslint ? null : 'toggle'),
140
- message: 'Add ESLint for code quality?',
141
- initial: false,
142
- active: 'Yes',
143
- inactive: 'No',
144
- },
145
- {
146
- name: 'prettier',
147
- type: (prev, values) => {
148
- if (!values.eslint) {
149
- return null;
150
- }
151
- return 'toggle';
152
- },
153
- message: 'Add Prettier for code formatting?',
154
- initial: false,
155
- active: 'Yes',
156
- inactive: 'No',
157
- },
158
- ], {
159
- onCancel: () => {
160
- throw new Error('Operation cancelled');
161
- },
162
- });
163
- return Object.assign(Object.assign(Object.assign({}, predefined), results), { packageName: (results.packageName || results.targetDir || predefined.targetDir) });
164
- }
165
- catch (e) {
166
- console.log(e.message);
167
- process.exit(1);
168
- }
169
- });
170
- }
171
- function canSkipEmptying(dir) {
172
- if (!existsSync(dir)) {
173
- return true;
174
- }
175
- const files = readdirSync(dir);
176
- if (files.length === 0) {
177
- return true;
178
- }
179
- if (files.length === 1 && files[0] === '.git') {
180
- return true;
181
- }
182
- return false;
183
- }
184
- function isValidPackageName(projectName) {
185
- return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
186
- }
187
- function toValidPackageName(projectName) {
188
- return projectName
189
- .trim()
190
- .toLowerCase()
191
- .replace(/\s+/g, '-')
192
- .replace(/^[._]/, '')
193
- .replace(/[^a-z0-9-~]+/g, '-');
46
+ const defaultProjectName = 'moost-app';
47
+ async function getPrompts(inputs) {
48
+ const predefined = {
49
+ targetDir: inputs.name || '',
50
+ projectName: inputs.name || '',
51
+ packageName: inputs.name || '',
52
+ prettier: !!inputs.prettier,
53
+ eslint: !!inputs.eslint,
54
+ };
55
+ try {
56
+ const results = await prompts([
57
+ {
58
+ name: 'projectName',
59
+ type: predefined.targetDir ? null : 'text',
60
+ message: 'Project name:',
61
+ initial: defaultProjectName,
62
+ onState: (state) => (predefined.targetDir =
63
+ String(state.value).trim() || defaultProjectName),
64
+ },
65
+ {
66
+ name: 'overwrite',
67
+ type: () => canSkipEmptying(predefined.targetDir) || inputs.force
68
+ ? null
69
+ : 'confirm',
70
+ message: () => {
71
+ const dirForPrompt = predefined.targetDir === '.'
72
+ ? 'Current directory'
73
+ : `Target directory "${predefined.targetDir}"`;
74
+ return `${dirForPrompt} is not empty. Remove existing files and continue?`;
75
+ },
76
+ },
77
+ {
78
+ name: 'overwriteChecker',
79
+ type: (prev, values) => {
80
+ if (values.overwrite === false) {
81
+ throw new Error('Operation cancelled');
82
+ }
83
+ return null;
84
+ },
85
+ },
86
+ {
87
+ name: 'type',
88
+ type: () => {
89
+ if (inputs.cli && !inputs.http) {
90
+ predefined.type = 'cli';
91
+ return null;
92
+ }
93
+ if (!inputs.cli && inputs.http) {
94
+ predefined.type = 'http';
95
+ return null;
96
+ }
97
+ return 'select';
98
+ },
99
+ message: 'Moost Adapter:',
100
+ choices: [
101
+ { title: 'HTTP (Web) Application', value: 'http' },
102
+ { title: 'CLI Application', value: 'cli' },
103
+ ],
104
+ },
105
+ {
106
+ name: 'bundler',
107
+ type: () => {
108
+ if (inputs.esbuild && !inputs.rollup) {
109
+ predefined.bundler = 'esbuild';
110
+ return null;
111
+ }
112
+ if (!inputs.esbuild && inputs.rollup) {
113
+ predefined.bundler = 'rollup';
114
+ return null;
115
+ }
116
+ return 'select';
117
+ },
118
+ message: 'Bundler:',
119
+ choices: [
120
+ { title: 'Rollup (recommended)', value: 'rollup' },
121
+ { title: 'ESBuild', value: 'esbuild' },
122
+ ],
123
+ },
124
+ {
125
+ name: 'packageName',
126
+ type: () => (isValidPackageName(predefined.targetDir) ? null : 'text'),
127
+ message: 'Package name:',
128
+ initial: () => toValidPackageName(predefined.targetDir),
129
+ validate: (dir) => isValidPackageName(dir) || 'Invalid package.json name',
130
+ },
131
+ {
132
+ name: 'eslint',
133
+ type: () => (inputs.eslint ? null : 'toggle'),
134
+ message: 'Add ESLint for code quality?',
135
+ initial: false,
136
+ active: 'Yes',
137
+ inactive: 'No',
138
+ },
139
+ {
140
+ name: 'prettier',
141
+ type: (prev, values) => {
142
+ if (!values.eslint) {
143
+ return null;
144
+ }
145
+ return 'toggle';
146
+ },
147
+ message: 'Add Prettier for code formatting?',
148
+ initial: false,
149
+ active: 'Yes',
150
+ inactive: 'No',
151
+ },
152
+ ], {
153
+ onCancel: () => {
154
+ throw new Error('Operation cancelled');
155
+ },
156
+ });
157
+ return {
158
+ ...predefined,
159
+ ...results,
160
+ packageName: (results.packageName || results.targetDir || predefined.targetDir),
161
+ };
162
+ }
163
+ catch (e) {
164
+ console.log(e.message);
165
+ process.exit(1);
166
+ }
167
+ }
168
+ function canSkipEmptying(dir) {
169
+ if (!existsSync(dir)) {
170
+ return true;
171
+ }
172
+ const files = readdirSync(dir);
173
+ if (files.length === 0) {
174
+ return true;
175
+ }
176
+ if (files.length === 1 && files[0] === '.git') {
177
+ return true;
178
+ }
179
+ return false;
180
+ }
181
+ function isValidPackageName(projectName) {
182
+ return /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/.test(projectName);
183
+ }
184
+ function toValidPackageName(projectName) {
185
+ return projectName
186
+ .trim()
187
+ .toLowerCase()
188
+ .replace(/\s+/g, '-')
189
+ .replace(/^[._]/, '')
190
+ .replace(/[^a-z0-9-~]+/g, '-');
194
191
  }
195
192
 
196
- const rw = new ProstoRewrite({
197
- textPattern: [
198
- '*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
199
- 'Dockerfile',
200
- '*config',
201
- '.gitignore',
202
- '.eslintrc.json',
203
- '.prettierignore',
204
- '.prettierrc',
205
- ],
206
- });
207
- const root = process.cwd();
208
- const { version } = JSON.parse(readFileSync(join(__dirname, '../package.json')).toString());
209
- function scaffold(data) {
210
- return __awaiter(this, void 0, void 0, function* () {
211
- const projectDir = join(root, data.targetDir);
212
- if (existsSync(projectDir)) {
213
- if (data.overwrite) {
214
- emptyDirectorySync(projectDir);
215
- }
216
- }
217
- else {
218
- mkdirSync(projectDir);
219
- }
220
- const templatePath = join(__dirname, '../templates', data.type);
221
- const commonPath = join(__dirname, '../templates/common');
222
- const context = Object.assign(Object.assign({}, data), { version });
223
- const excludeCommon = [];
224
- if (!data.eslint) {
225
- excludeCommon.push('.eslintrc.json');
226
- }
227
- if (!data.prettier) {
228
- excludeCommon.push('.prettierignore');
229
- excludeCommon.push('.prettierrc');
230
- }
231
- if (data.bundler !== 'rollup') {
232
- excludeCommon.push('rollup.config.js');
233
- }
234
- if (data.bundler !== 'esbuild') {
235
- excludeCommon.push('build.js');
236
- }
237
- yield rw.rewriteDir({
238
- baseDir: templatePath,
239
- output: projectDir,
240
- }, context);
241
- yield rw.rewriteDir({
242
- baseDir: commonPath,
243
- output: projectDir,
244
- exclude: excludeCommon,
245
- }, context);
246
- });
247
- }
248
- function emptyDirectorySync(directory) {
249
- if (existsSync(directory)) {
250
- readdirSync(directory).forEach((file) => {
251
- const currentPath = join(directory, file);
252
- if (lstatSync(currentPath).isDirectory()) {
253
- // Recurse if the current path is a directory
254
- emptyDirectorySync(currentPath);
255
- rmdirSync(currentPath); // Remove the empty directory
256
- }
257
- else {
258
- // Delete file
259
- unlinkSync(currentPath);
260
- }
261
- });
262
- }
193
+ const rw = new ProstoRewrite({
194
+ textPattern: [
195
+ '*.{js,jsx,ts,tsx,txt,json,yml,yaml,md,ini}',
196
+ 'Dockerfile',
197
+ '*config',
198
+ '.gitignore',
199
+ '.eslintrc.json',
200
+ '.prettierignore',
201
+ '.prettierrc',
202
+ ],
203
+ });
204
+ const root = process.cwd();
205
+ const { version } = JSON.parse(readFileSync(join(__dirname, '../package.json')).toString());
206
+ async function scaffold(data) {
207
+ const projectDir = join(root, data.targetDir);
208
+ if (existsSync(projectDir)) {
209
+ if (data.overwrite) {
210
+ emptyDirectorySync(projectDir);
211
+ }
212
+ }
213
+ else {
214
+ mkdirSync(projectDir);
215
+ }
216
+ const templatePath = join(__dirname, '../templates', data.type);
217
+ const commonPath = join(__dirname, '../templates/common');
218
+ const context = { ...data, version };
219
+ const excludeCommon = [];
220
+ if (!data.eslint) {
221
+ excludeCommon.push('.eslintrc.json');
222
+ }
223
+ if (!data.prettier) {
224
+ excludeCommon.push('.prettierignore');
225
+ excludeCommon.push('.prettierrc');
226
+ }
227
+ if (data.bundler !== 'rollup') {
228
+ excludeCommon.push('rollup.config.js');
229
+ }
230
+ if (data.bundler !== 'esbuild') {
231
+ excludeCommon.push('build.js');
232
+ }
233
+ await rw.rewriteDir({
234
+ baseDir: templatePath,
235
+ output: projectDir,
236
+ }, context);
237
+ await rw.rewriteDir({
238
+ baseDir: commonPath,
239
+ output: projectDir,
240
+ exclude: excludeCommon,
241
+ }, context);
242
+ }
243
+ function emptyDirectorySync(directory) {
244
+ if (existsSync(directory)) {
245
+ readdirSync(directory).forEach((file) => {
246
+ const currentPath = join(directory, file);
247
+ if (lstatSync(currentPath).isDirectory()) {
248
+ emptyDirectorySync(currentPath);
249
+ rmdirSync(currentPath);
250
+ }
251
+ else {
252
+ unlinkSync(currentPath);
253
+ }
254
+ });
255
+ }
263
256
  }
264
257
 
265
- let CliController = class CliController extends Moost {
266
- root() {
267
- return this.execute();
268
- }
269
- withName(name) {
270
- return this.execute(name);
271
- }
272
- execute(name) {
273
- return __awaiter(this, void 0, void 0, function* () {
274
- useAutoHelp() && process.exit(0);
275
- const prompts = yield getPrompts({
276
- name,
277
- eslint: !!useCliOption('eslint'),
278
- prettier: !!useCliOption('prettier'),
279
- http: !!useCliOption('http'),
280
- cli: !!useCliOption('cli'),
281
- force: !!useCliOption('force'),
282
- esbuild: !!useCliOption('esbuild'),
283
- rollup: !!useCliOption('rollup'),
284
- });
285
- console.log('\nScaffolding a new project...');
286
- yield scaffold(prompts);
287
- const cli = prompts.type === 'cli';
288
- return `
258
+ let CliController = class CliController extends Moost {
259
+ root() {
260
+ return this.execute();
261
+ }
262
+ withName(name) {
263
+ return this.execute(name);
264
+ }
265
+ async execute(name) {
266
+ useAutoHelp() && process.exit(0);
267
+ const prompts = await getPrompts({
268
+ name,
269
+ eslint: !!useCliOption('eslint'),
270
+ prettier: !!useCliOption('prettier'),
271
+ http: !!useCliOption('http'),
272
+ cli: !!useCliOption('cli'),
273
+ force: !!useCliOption('force'),
274
+ esbuild: !!useCliOption('esbuild'),
275
+ rollup: !!useCliOption('rollup'),
276
+ });
277
+ console.log('\nScaffolding a new project...');
278
+ await scaffold(prompts);
279
+ const cli = prompts.type === 'cli';
280
+ return `
289
281
  ${'' + ''}Success! ${''}Your new "${prompts.projectName}" project has been created successfully. ${''}
290
282
 
291
283
  Follow these next steps to start your development server:
@@ -304,41 +296,39 @@ ${cli ? '4' : '3'}. Start the development server:
304
296
 
305
297
  ${''}You're all set! The development server will help you in building your application.
306
298
  Enjoy coding, and build something amazing!${''}
307
- `;
308
- });
309
- }
310
- };
311
- __decorate([
312
- Cli(''),
313
- __metadata("design:type", Function),
314
- __metadata("design:paramtypes", []),
315
- __metadata("design:returntype", void 0)
316
- ], CliController.prototype, "root", null);
317
- __decorate([
318
- Cli(':name'),
319
- __param(0, Param('name')),
320
- __metadata("design:type", Function),
321
- __metadata("design:paramtypes", [String]),
322
- __metadata("design:returntype", void 0)
323
- ], CliController.prototype, "withName", null);
324
- CliController = __decorate([
325
- Controller()
326
- ], CliController);
327
- function run() {
328
- const app = new CliController();
329
- app.adapter(new MoostCli({
330
- globalCliOptions: [
331
- // { keys: ['ts'], description: '' },
332
- { keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
333
- { keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
334
- { keys: ['eslint'], description: 'Add ESLint', type: Boolean },
335
- { keys: ['prettier'], description: 'Add Prettier', type: Boolean },
336
- { keys: ['force'], description: 'Force Overwrite', type: Boolean },
337
- { keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
338
- { keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
339
- ],
340
- }));
341
- void app.init();
299
+ `;
300
+ }
301
+ };
302
+ __decorate([
303
+ Cli(''),
304
+ __metadata("design:type", Function),
305
+ __metadata("design:paramtypes", []),
306
+ __metadata("design:returntype", void 0)
307
+ ], CliController.prototype, "root", null);
308
+ __decorate([
309
+ Cli(':name'),
310
+ __param(0, Param('name')),
311
+ __metadata("design:type", Function),
312
+ __metadata("design:paramtypes", [String]),
313
+ __metadata("design:returntype", void 0)
314
+ ], CliController.prototype, "withName", null);
315
+ CliController = __decorate([
316
+ Controller()
317
+ ], CliController);
318
+ function run() {
319
+ const app = new CliController();
320
+ app.adapter(new MoostCli({
321
+ globalCliOptions: [
322
+ { keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
323
+ { keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
324
+ { keys: ['eslint'], description: 'Add ESLint', type: Boolean },
325
+ { keys: ['prettier'], description: 'Add Prettier', type: Boolean },
326
+ { keys: ['force'], description: 'Force Overwrite', type: Boolean },
327
+ { keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
328
+ { keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
329
+ ],
330
+ }));
331
+ void app.init();
342
332
  }
343
333
 
344
334
  export { run };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "create-moost",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "description": "create-moost",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "sideEffects": false,
9
9
  "exports": {
10
+ "./package.json": "./package.json",
10
11
  ".": {
11
12
  "import": "./dist/index.mjs",
12
13
  "require": "./dist/index.cjs",
@@ -41,10 +42,10 @@
41
42
  },
42
43
  "homepage": "https://github.com/moostjs/moostjs/tree/main/packages/create-moost#readme",
43
44
  "dependencies": {
44
- "@moostjs/event-cli": "0.3.10",
45
- "@wooksjs/event-cli": "^0.4.9",
45
+ "@moostjs/event-cli": "0.3.12",
46
+ "@wooksjs/event-cli": "^0.4.13",
46
47
  "@prostojs/rewrite": "^0.0.4",
47
- "moost": "0.3.10",
48
+ "moost": "0.3.12",
48
49
  "prompts": "^2.4.2"
49
50
  }
50
51
  }