@corva/create-app 0.53.0-rc.0 → 0.54.0-1
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/lib/commands/create.js +42 -10
- package/lib/constants/manifest.js +7 -0
- package/lib/constants/package.js +38 -6
- package/lib/helpers/utils.js +4 -0
- package/lib/helpers/versioning.js +1 -1
- package/package.json +1 -1
package/lib/commands/create.js
CHANGED
|
@@ -16,7 +16,7 @@ import { originalCwdOption } from '../options/original-cwd.js';
|
|
|
16
16
|
import { ensureBumpVersion, ensureLatestVersion } from '../helpers/cli-version.js';
|
|
17
17
|
import { logger } from '../helpers/logger.js';
|
|
18
18
|
import { IS_WINDOWS, resolveAppRuntime } from '../helpers/resolve-app-runtime.js';
|
|
19
|
-
import {
|
|
19
|
+
import { tryGitCommit, tryGitInit } from '../helpers/versioning.js';
|
|
20
20
|
import { copyFolderRecursiveSync, putVariablesInEnvFile } from '../helpers/utils.js';
|
|
21
21
|
import { getDefaultsForPackageJson } from '../constants/package.js';
|
|
22
22
|
import { getRealWorkingDir } from '../helpers/commands.js';
|
|
@@ -44,7 +44,7 @@ export const createCommand = new Command('create')
|
|
|
44
44
|
});
|
|
45
45
|
|
|
46
46
|
manifestOptions().forEach((value) => {
|
|
47
|
-
const type = typeof value.default;
|
|
47
|
+
const type = value.commaSeparated ? 'string' : typeof value.default;
|
|
48
48
|
const cliType = type === 'undefined' ? (value.choices ? ' [string]' : '') : ` [${type}]`;
|
|
49
49
|
const alias = value.alias ? `-${value.alias}, ` : '';
|
|
50
50
|
const optionString = `${alias}--${value.name}${cliType}`;
|
|
@@ -61,6 +61,8 @@ manifestOptions().forEach((value) => {
|
|
|
61
61
|
|
|
62
62
|
if (type === 'number') {
|
|
63
63
|
option.argParser(Number);
|
|
64
|
+
} else if (value.commaSeparated) {
|
|
65
|
+
option.argParser((str) => str.split(',').map((s) => s.trim()));
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
if (type !== 'undefined') {
|
|
@@ -145,12 +147,23 @@ async function initPackage(projectName, opts) {
|
|
|
145
147
|
|
|
146
148
|
await fs.writeJSON(join(root, 'manifest.json'), manifest.manifest, WRITE_TO_JSON_OPTS);
|
|
147
149
|
|
|
148
|
-
await addTemplate(root, manifest, runtime);
|
|
149
|
-
await configureApp(root, manifest, runtime);
|
|
150
|
+
await addTemplate(root, manifest, runtime, opts);
|
|
151
|
+
await configureApp(root, manifest, runtime, opts);
|
|
152
|
+
|
|
153
|
+
if (opts.gitInit) {
|
|
154
|
+
if (!tryGitInit(root)) {
|
|
155
|
+
logger.log('Already in a git repository. Skipping git initialization.');
|
|
156
|
+
}
|
|
157
|
+
}
|
|
150
158
|
|
|
151
159
|
opts.dependenciesInstall && (await installDependencies(root, manifest, runtime));
|
|
152
160
|
|
|
153
|
-
opts.gitInit
|
|
161
|
+
if (opts.gitInit) {
|
|
162
|
+
if (tryGitCommit(root)) {
|
|
163
|
+
logger.log();
|
|
164
|
+
logger.log('Created git commit');
|
|
165
|
+
}
|
|
166
|
+
}
|
|
154
167
|
|
|
155
168
|
logger.log();
|
|
156
169
|
logger.log(`Success! Created ${chalk.green(manifest.name)} at ${chalk.yellow(root)}`);
|
|
@@ -183,8 +196,9 @@ async function createApp(dirName, opts) {
|
|
|
183
196
|
* @param {string} root
|
|
184
197
|
* @param {import('./flows/lib/manifest').Manifest} manifest
|
|
185
198
|
* @param {*} runtime
|
|
199
|
+
* @param {*} opts
|
|
186
200
|
*/
|
|
187
|
-
async function addTemplate(root, manifest, runtime) {
|
|
201
|
+
async function addTemplate(root, manifest, runtime, opts) {
|
|
188
202
|
logger.log(chalk.green('Copying app template...'));
|
|
189
203
|
logger.log();
|
|
190
204
|
|
|
@@ -218,6 +232,23 @@ async function addTemplate(root, manifest, runtime) {
|
|
|
218
232
|
}
|
|
219
233
|
|
|
220
234
|
logger.log(chalk.green('Done: copying app template!'));
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
if (Array.isArray(opts?.extensions) && opts.extensions.length) {
|
|
238
|
+
opts.extensions.forEach((extension) => {
|
|
239
|
+
const extPath = join(cliRoot, 'template_extensions', extension);
|
|
240
|
+
|
|
241
|
+
if (fs.existsSync(extPath)) {
|
|
242
|
+
copyFolderRecursiveSync(extPath, root);
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
logger.log(chalk.green('Done: applying app extensions!'));
|
|
247
|
+
}
|
|
248
|
+
} catch (e) {
|
|
249
|
+
logger.log(chalk.red('Error: applying app extensions!'));
|
|
250
|
+
logger.log(e);
|
|
251
|
+
}
|
|
221
252
|
}
|
|
222
253
|
|
|
223
254
|
/**
|
|
@@ -225,11 +256,12 @@ async function addTemplate(root, manifest, runtime) {
|
|
|
225
256
|
* @param {string} root
|
|
226
257
|
* @param {import('./flows/lib/manifest').Manifest} manifest
|
|
227
258
|
* @param {*} runtime
|
|
259
|
+
* @param {*} opts
|
|
228
260
|
*/
|
|
229
|
-
async function configureApp(root, manifest, runtime) {
|
|
261
|
+
async function configureApp(root, manifest, runtime, opts) {
|
|
230
262
|
if (manifest.isJs()) {
|
|
231
263
|
await addNvmRc(root, manifest, runtime);
|
|
232
|
-
await addPackageJSON(root, manifest, runtime);
|
|
264
|
+
await addPackageJSON(root, manifest, runtime, opts);
|
|
233
265
|
}
|
|
234
266
|
|
|
235
267
|
if (manifest.isNode()) {
|
|
@@ -290,7 +322,7 @@ const addTsConfigs = (root, manifest, runtime) => {
|
|
|
290
322
|
* @param {string} root
|
|
291
323
|
* @param {import('./flows/lib/manifest').Manifest} manifest
|
|
292
324
|
*/
|
|
293
|
-
function addPackageJSON(root, manifest, runtime) {
|
|
325
|
+
function addPackageJSON(root, manifest, runtime, opts) {
|
|
294
326
|
const {
|
|
295
327
|
version,
|
|
296
328
|
description,
|
|
@@ -301,7 +333,7 @@ function addPackageJSON(root, manifest, runtime) {
|
|
|
301
333
|
license = 'UNLICENSED',
|
|
302
334
|
private: isPrivate = true,
|
|
303
335
|
...rest
|
|
304
|
-
} = getDefaultsForPackageJson(manifest, runtime);
|
|
336
|
+
} = getDefaultsForPackageJson(manifest, runtime, opts);
|
|
305
337
|
|
|
306
338
|
const packageJson = {
|
|
307
339
|
name: manifest.unix_name,
|
|
@@ -252,4 +252,11 @@ export const manifestOptions = (projectName = 'Corva Dev Center App') => [
|
|
|
252
252
|
name: 'no-git-init',
|
|
253
253
|
message: 'Skip initializing git repository',
|
|
254
254
|
},
|
|
255
|
+
{
|
|
256
|
+
name: 'extensions',
|
|
257
|
+
message: 'App template extensions',
|
|
258
|
+
default: [],
|
|
259
|
+
when: (answers) => answers.appType === APP_TYPES.UI,
|
|
260
|
+
commaSeparated: true,
|
|
261
|
+
},
|
|
255
262
|
];
|
package/lib/constants/package.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
1
3
|
const uiDependencies = {
|
|
2
4
|
'@corva/ui': 'latest',
|
|
3
5
|
'@material-ui/core': '4.11.2',
|
|
@@ -44,6 +46,36 @@ const tsUiDevDependencies = {
|
|
|
44
46
|
'typescript': '4.6.3',
|
|
45
47
|
};
|
|
46
48
|
|
|
49
|
+
const corvaUiExtension = {
|
|
50
|
+
scripts: {
|
|
51
|
+
prepare: 'husky install',
|
|
52
|
+
},
|
|
53
|
+
devDependencies: {
|
|
54
|
+
'@commitlint/cli': '^17.0.0',
|
|
55
|
+
'@commitlint/config-conventional': '^17.0.0',
|
|
56
|
+
'husky': '^8.0.0',
|
|
57
|
+
'lint-staged': '^13.0.0',
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
function applyUiExtension(packageJson, extensionNames) {
|
|
62
|
+
if (!Array.isArray(extensionNames) || extensionNames.length === 0) {
|
|
63
|
+
return packageJson;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const extensions = extensionNames
|
|
67
|
+
.map((extensionName) => {
|
|
68
|
+
if (extensionName === 'corva') {
|
|
69
|
+
return corvaUiExtension;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return null;
|
|
73
|
+
})
|
|
74
|
+
.filter(Boolean);
|
|
75
|
+
|
|
76
|
+
return _.merge({}, packageJson, ...extensions);
|
|
77
|
+
}
|
|
78
|
+
|
|
47
79
|
const uiScripts = {
|
|
48
80
|
build: 'webpack --config=./config-overrides.js --mode production',
|
|
49
81
|
start: 'webpack-dev-server --config=./config-overrides.js --open --mode development',
|
|
@@ -193,13 +225,13 @@ const extendWithTsConfig = (packageJson, version) => {
|
|
|
193
225
|
const defaults = {
|
|
194
226
|
javascript: {
|
|
195
227
|
yarn: {
|
|
196
|
-
ui: () => uiPackage,
|
|
228
|
+
ui: (runtime, opts) => applyUiExtension(uiPackage, opts?.extensions),
|
|
197
229
|
task: () => nodeYarnPackage,
|
|
198
230
|
scheduler: () => nodeYarnPackage,
|
|
199
231
|
stream: () => nodeYarnPackage,
|
|
200
232
|
},
|
|
201
233
|
npm: {
|
|
202
|
-
ui: () => uiPackage,
|
|
234
|
+
ui: (runtime, opts) => applyUiExtension(uiPackage, opts?.extensions),
|
|
203
235
|
task: () => nodeNpmPackage,
|
|
204
236
|
scheduler: () => nodeNpmPackage,
|
|
205
237
|
stream: () => nodeNpmPackage,
|
|
@@ -207,13 +239,13 @@ const defaults = {
|
|
|
207
239
|
},
|
|
208
240
|
typescript: {
|
|
209
241
|
yarn: {
|
|
210
|
-
ui: () => tsUiPackage,
|
|
242
|
+
ui: (runtime, opts) => applyUiExtension(tsUiPackage, opts?.extensions),
|
|
211
243
|
task: ({ version }) => extendWithTsConfig(nodeTsYarnPackage, version),
|
|
212
244
|
scheduler: ({ version }) => extendWithTsConfig(nodeTsYarnPackage, version),
|
|
213
245
|
stream: ({ version }) => extendWithTsConfig(nodeTsYarnPackage, version),
|
|
214
246
|
},
|
|
215
247
|
npm: {
|
|
216
|
-
ui: () => tsUiPackage,
|
|
248
|
+
ui: (runtime, opts) => applyUiExtension(tsUiPackage, opts?.extensions),
|
|
217
249
|
task: ({ version }) => extendWithTsConfig(nodeTsNpmPackage, version),
|
|
218
250
|
scheduler: ({ version }) => extendWithTsConfig(nodeTsNpmPackage, version),
|
|
219
251
|
stream: ({ version }) => extendWithTsConfig(nodeTsNpmPackage, version),
|
|
@@ -221,6 +253,6 @@ const defaults = {
|
|
|
221
253
|
},
|
|
222
254
|
};
|
|
223
255
|
|
|
224
|
-
export const getDefaultsForPackageJson = (manifest, runtime) => {
|
|
225
|
-
return defaults[runtime.language][runtime.packageManager][manifest.type](runtime);
|
|
256
|
+
export const getDefaultsForPackageJson = (manifest, runtime, opts) => {
|
|
257
|
+
return defaults[runtime.language][runtime.packageManager][manifest.type](runtime, opts);
|
|
226
258
|
};
|
package/lib/helpers/utils.js
CHANGED
|
@@ -12,6 +12,10 @@ export function copyFileSync(source, target) {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
fs.writeFileSync(targetFile, fs.readFileSync(source));
|
|
15
|
+
|
|
16
|
+
const targetMode = fs.lstatSync(source).mode;
|
|
17
|
+
|
|
18
|
+
fs.chmodSync(targetFile, targetMode);
|
|
15
19
|
}
|
|
16
20
|
|
|
17
21
|
export function copyFolderRecursiveSync(sourceFolder, targetFolder) {
|
|
@@ -65,7 +65,7 @@ export function tryGitInit(appPath) {
|
|
|
65
65
|
export function tryGitCommit(appPath) {
|
|
66
66
|
try {
|
|
67
67
|
execSync('git add -A', { stdio: 'ignore', cwd: appPath });
|
|
68
|
-
execSync('git commit -m "chore: initialize project using @corva/create-app"', {
|
|
68
|
+
execSync('git commit -m "chore: initialize project using @corva/create-app" -n', {
|
|
69
69
|
stdio: 'ignore',
|
|
70
70
|
cwd: appPath,
|
|
71
71
|
});
|