create-moost 0.3.10 → 0.3.11
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 +272 -279
- package/dist/index.mjs +272 -279
- package/package.json +4 -4
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,248 @@ 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
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
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
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
.
|
|
194
|
-
.
|
|
195
|
-
.replace(
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
//
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
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
|
+
// Recurse if the current path is a directory
|
|
251
|
+
emptyDirectorySync(currentPath);
|
|
252
|
+
fs.rmdirSync(currentPath); // Remove the empty directory
|
|
253
|
+
}
|
|
254
|
+
else {
|
|
255
|
+
// Delete file
|
|
256
|
+
fs.unlinkSync(currentPath);
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
}
|
|
265
260
|
}
|
|
266
261
|
|
|
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
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
return `
|
|
262
|
+
let CliController = class CliController extends moost.Moost {
|
|
263
|
+
root() {
|
|
264
|
+
return this.execute();
|
|
265
|
+
}
|
|
266
|
+
withName(name) {
|
|
267
|
+
return this.execute(name);
|
|
268
|
+
}
|
|
269
|
+
async execute(name) {
|
|
270
|
+
eventCli$1.useAutoHelp() && process.exit(0);
|
|
271
|
+
const prompts = await getPrompts({
|
|
272
|
+
name,
|
|
273
|
+
eslint: !!eventCli$1.useCliOption('eslint'),
|
|
274
|
+
prettier: !!eventCli$1.useCliOption('prettier'),
|
|
275
|
+
http: !!eventCli$1.useCliOption('http'),
|
|
276
|
+
cli: !!eventCli$1.useCliOption('cli'),
|
|
277
|
+
force: !!eventCli$1.useCliOption('force'),
|
|
278
|
+
esbuild: !!eventCli$1.useCliOption('esbuild'),
|
|
279
|
+
rollup: !!eventCli$1.useCliOption('rollup'),
|
|
280
|
+
});
|
|
281
|
+
console.log('\nScaffolding a new project...');
|
|
282
|
+
await scaffold(prompts);
|
|
283
|
+
const cli = prompts.type === 'cli';
|
|
284
|
+
return `
|
|
291
285
|
${'[97m' + '[1m'}Success! ${'[22m'}Your new "${prompts.projectName}" project has been created successfully. ${'[39m'}
|
|
292
286
|
|
|
293
287
|
Follow these next steps to start your development server:
|
|
@@ -306,41 +300,40 @@ ${cli ? '4' : '3'}. Start the development server:
|
|
|
306
300
|
|
|
307
301
|
${'[32m'}You're all set! The development server will help you in building your application.
|
|
308
302
|
Enjoy coding, and build something amazing!${'[39m'}
|
|
309
|
-
`;
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
__metadata("design:
|
|
316
|
-
__metadata("design:
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
__metadata("design:
|
|
323
|
-
__metadata("design:
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
{ keys: ['
|
|
335
|
-
{ keys: ['
|
|
336
|
-
{ keys: ['
|
|
337
|
-
{ keys: ['
|
|
338
|
-
{ keys: ['
|
|
339
|
-
{ keys: ['
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
void app.init();
|
|
303
|
+
`;
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
__decorate([
|
|
307
|
+
eventCli.Cli(''),
|
|
308
|
+
__metadata("design:type", Function),
|
|
309
|
+
__metadata("design:paramtypes", []),
|
|
310
|
+
__metadata("design:returntype", void 0)
|
|
311
|
+
], CliController.prototype, "root", null);
|
|
312
|
+
__decorate([
|
|
313
|
+
eventCli.Cli(':name'),
|
|
314
|
+
__param(0, moost.Param('name')),
|
|
315
|
+
__metadata("design:type", Function),
|
|
316
|
+
__metadata("design:paramtypes", [String]),
|
|
317
|
+
__metadata("design:returntype", void 0)
|
|
318
|
+
], CliController.prototype, "withName", null);
|
|
319
|
+
CliController = __decorate([
|
|
320
|
+
moost.Controller()
|
|
321
|
+
], CliController);
|
|
322
|
+
function run() {
|
|
323
|
+
const app = new CliController();
|
|
324
|
+
app.adapter(new eventCli.MoostCli({
|
|
325
|
+
globalCliOptions: [
|
|
326
|
+
// { keys: ['ts'], description: '' },
|
|
327
|
+
{ keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
|
|
328
|
+
{ keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
|
|
329
|
+
{ keys: ['eslint'], description: 'Add ESLint', type: Boolean },
|
|
330
|
+
{ keys: ['prettier'], description: 'Add Prettier', type: Boolean },
|
|
331
|
+
{ keys: ['force'], description: 'Force Overwrite', type: Boolean },
|
|
332
|
+
{ keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
|
|
333
|
+
{ keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
|
|
334
|
+
],
|
|
335
|
+
}));
|
|
336
|
+
void app.init();
|
|
344
337
|
}
|
|
345
338
|
|
|
346
339
|
exports.run = 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,248 @@ 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
|
|
42
|
-
|
|
43
|
-
return
|
|
44
|
-
|
|
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
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
.
|
|
192
|
-
.
|
|
193
|
-
.replace(
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
if (
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
+
// Recurse if the current path is a directory
|
|
249
|
+
emptyDirectorySync(currentPath);
|
|
250
|
+
rmdirSync(currentPath); // Remove the empty directory
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
// Delete file
|
|
254
|
+
unlinkSync(currentPath);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
}
|
|
263
258
|
}
|
|
264
259
|
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
return `
|
|
260
|
+
let CliController = class CliController extends Moost {
|
|
261
|
+
root() {
|
|
262
|
+
return this.execute();
|
|
263
|
+
}
|
|
264
|
+
withName(name) {
|
|
265
|
+
return this.execute(name);
|
|
266
|
+
}
|
|
267
|
+
async execute(name) {
|
|
268
|
+
useAutoHelp() && process.exit(0);
|
|
269
|
+
const prompts = await getPrompts({
|
|
270
|
+
name,
|
|
271
|
+
eslint: !!useCliOption('eslint'),
|
|
272
|
+
prettier: !!useCliOption('prettier'),
|
|
273
|
+
http: !!useCliOption('http'),
|
|
274
|
+
cli: !!useCliOption('cli'),
|
|
275
|
+
force: !!useCliOption('force'),
|
|
276
|
+
esbuild: !!useCliOption('esbuild'),
|
|
277
|
+
rollup: !!useCliOption('rollup'),
|
|
278
|
+
});
|
|
279
|
+
console.log('\nScaffolding a new project...');
|
|
280
|
+
await scaffold(prompts);
|
|
281
|
+
const cli = prompts.type === 'cli';
|
|
282
|
+
return `
|
|
289
283
|
${'[97m' + '[1m'}Success! ${'[22m'}Your new "${prompts.projectName}" project has been created successfully. ${'[39m'}
|
|
290
284
|
|
|
291
285
|
Follow these next steps to start your development server:
|
|
@@ -304,41 +298,40 @@ ${cli ? '4' : '3'}. Start the development server:
|
|
|
304
298
|
|
|
305
299
|
${'[32m'}You're all set! The development server will help you in building your application.
|
|
306
300
|
Enjoy coding, and build something amazing!${'[39m'}
|
|
307
|
-
`;
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
__metadata("design:
|
|
314
|
-
__metadata("design:
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
__metadata("design:
|
|
321
|
-
__metadata("design:
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
{ keys: ['
|
|
333
|
-
{ keys: ['
|
|
334
|
-
{ keys: ['
|
|
335
|
-
{ keys: ['
|
|
336
|
-
{ keys: ['
|
|
337
|
-
{ keys: ['
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
void app.init();
|
|
301
|
+
`;
|
|
302
|
+
}
|
|
303
|
+
};
|
|
304
|
+
__decorate([
|
|
305
|
+
Cli(''),
|
|
306
|
+
__metadata("design:type", Function),
|
|
307
|
+
__metadata("design:paramtypes", []),
|
|
308
|
+
__metadata("design:returntype", void 0)
|
|
309
|
+
], CliController.prototype, "root", null);
|
|
310
|
+
__decorate([
|
|
311
|
+
Cli(':name'),
|
|
312
|
+
__param(0, 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
|
+
Controller()
|
|
319
|
+
], CliController);
|
|
320
|
+
function run() {
|
|
321
|
+
const app = new CliController();
|
|
322
|
+
app.adapter(new MoostCli({
|
|
323
|
+
globalCliOptions: [
|
|
324
|
+
// { keys: ['ts'], description: '' },
|
|
325
|
+
{ keys: ['http'], description: 'Use Moost HTTP', type: Boolean },
|
|
326
|
+
{ keys: ['cli'], description: 'Use Moost CLI', type: Boolean },
|
|
327
|
+
{ keys: ['eslint'], description: 'Add ESLint', type: Boolean },
|
|
328
|
+
{ keys: ['prettier'], description: 'Add Prettier', type: Boolean },
|
|
329
|
+
{ keys: ['force'], description: 'Force Overwrite', type: Boolean },
|
|
330
|
+
{ keys: ['esbuild'], description: 'Use esbuild for builds', type: Boolean },
|
|
331
|
+
{ keys: ['rollup'], description: 'Use rollup for builds', type: Boolean },
|
|
332
|
+
],
|
|
333
|
+
}));
|
|
334
|
+
void app.init();
|
|
342
335
|
}
|
|
343
336
|
|
|
344
337
|
export { run };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-moost",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "create-moost",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://github.com/moostjs/moostjs/tree/main/packages/create-moost#readme",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@moostjs/event-cli": "0.3.
|
|
45
|
-
"@wooksjs/event-cli": "^0.4.
|
|
44
|
+
"@moostjs/event-cli": "0.3.11",
|
|
45
|
+
"@wooksjs/event-cli": "^0.4.11",
|
|
46
46
|
"@prostojs/rewrite": "^0.0.4",
|
|
47
|
-
"moost": "0.3.
|
|
47
|
+
"moost": "0.3.11",
|
|
48
48
|
"prompts": "^2.4.2"
|
|
49
49
|
}
|
|
50
50
|
}
|