* create-nocobase-app template from [develop] * change create-nocobase-app package.json config * feat: load configuration from directory * feat: configuration repository toObject * feat: create application from configuration dir * feat: application factory with plugins options * export type * feat: read application config & application with plugins options * feat: release command * fix: database release * chore: workflow package.json * feat: nocobase cli package * feat: console command * chore: load application in command * fix: load packages from process.cwd * feat: cli load env file * feat: create-nocobase-app * fix: gitignore create-nocobase-app lib * fix: sqlite path * feat: create plugin * chore: plugin files template * chore: move cli into application * chore: create-nocobase-app * fix: create plugin * chore: app-client && app-server * chore: package.json * feat: create-nocobase-app download template from npm * chore: create-nocobase-app template * fix: config of plugin-users * fix: yarn.lock * fix: database build error * fix: yarn.lock * fix: resourcer config * chore: cross-env * chore: app-client dependents * fix: env * chore: v0.6.0-alpha.1 * chore: verdaccio * chore(versions): 😊 publish v0.6.0 * chore(versions): 😊 publish v0.6.1-alpha.0 * chore(versions): 😊 publish v0.6.2-alpha.0 * chore(versions): 😊 publish v0.6.2-alpha.1 * chore: 0.6.2-alpha.2 * feat: workspaces * chore(versions): 😊 publish v0.6.2-alpha.3 * chore(versions): 😊 publish v0.6.2-alpha.4 * chore: create-nocobase-app * chore: create-nocobase-app lib * fix: update tsconfig.jest.json * chore: .env * chore(versions): 😊 publish v0.6.2-alpha.5 * chore(versions): 😊 publish v0.6.2-alpha.6 * feat: improve code * chore(versions): 😊 publish v0.6.2-alpha.7 * fix: cleanup * chore(versions): 😊 publish v0.6.2-alpha.8 * chore: tsconfig for app server package * fix: move files * fix: move files Co-authored-by: chenos <chenlinxh@gmail.com>
102 lines
3.1 KiB
JavaScript
102 lines
3.1 KiB
JavaScript
const chalk = require('chalk');
|
|
const fse = require('fs-extra');
|
|
const path = require('path');
|
|
const { hasYarn, runInit, runInstall } = require('./utils');
|
|
const ora = require('ora');
|
|
const execa = require('execa');
|
|
const { join, resolve } = require('path');
|
|
|
|
const createEnvFile = require('./resources/templates/env');
|
|
const createPackageJson = require('./resources/templates/package.json.js');
|
|
const createServerPackageJson = require('./resources/templates/server.package.json.js');
|
|
const loadSrcFromNpm = require('./resources/templates/load-src-from-npm');
|
|
|
|
const getDatabaseOptionsFromCommandOptions = (commandOptions) => {
|
|
if (
|
|
commandOptions.quickstart ||
|
|
!commandOptions.dbdialect ||
|
|
commandOptions.dbdialect === 'sqlite' ||
|
|
commandOptions.dbstorage
|
|
) {
|
|
return {
|
|
dialect: 'sqlite',
|
|
storage: commandOptions.dbstorage || 'db.sqlite',
|
|
};
|
|
}
|
|
|
|
return {
|
|
dialect: commandOptions.dbdialect,
|
|
host: commandOptions.dbhost,
|
|
port: commandOptions.dbport,
|
|
database: commandOptions.dbdatabase,
|
|
username: commandOptions.dbusername,
|
|
password: commandOptions.dbpassword,
|
|
};
|
|
};
|
|
|
|
async function createApp(directory, options) {
|
|
console.log(`Creating a new NocoBase application at ${chalk.green(directory)}.`);
|
|
console.log('Creating files.');
|
|
|
|
const projectPath = path.join(process.cwd(), directory);
|
|
const resourcePath = path.join(__dirname, 'resources');
|
|
|
|
const dbOptions = getDatabaseOptionsFromCommandOptions(options);
|
|
|
|
// copy files
|
|
await fse.copy(path.join(resourcePath, 'files'), projectPath);
|
|
|
|
console.log('download @nocobase/app-server');
|
|
await loadSrcFromNpm('@nocobase/app-server', path.join(projectPath, 'packages/app/server'));
|
|
|
|
console.log('download @nocobase/app-client');
|
|
await loadSrcFromNpm('@nocobase/app-client', path.join(projectPath, 'packages/app/client'));
|
|
|
|
// write .env file
|
|
await fse.writeFile(join(projectPath, '.env'), createEnvFile({ dbOptions }));
|
|
|
|
// write root packages.json
|
|
await fse.writeJson(
|
|
join(projectPath, 'package.json'),
|
|
createPackageJson({
|
|
projectName: 'nocobase-app',
|
|
}),
|
|
{
|
|
spaces: 2,
|
|
},
|
|
);
|
|
|
|
// write server package.json
|
|
await fse.writeJson(
|
|
join(projectPath, 'packages/app/server/package.json'),
|
|
createServerPackageJson({
|
|
projectPath,
|
|
dbOptions,
|
|
}),
|
|
{
|
|
spaces: 2,
|
|
},
|
|
);
|
|
|
|
// run install command
|
|
}
|
|
|
|
function setCommandOptions(command) {
|
|
return command
|
|
.arguments('<directory>', 'directory of new NocoBase app')
|
|
.option('--quickstart', 'Quickstart app creation')
|
|
.option('--dbdialect <dbdialect>', 'Database dialect, current support sqlite/mysql/postgres')
|
|
.option('--dbhost <dbhost>', 'Database host')
|
|
.option('--dbport <dbport>', 'Database port')
|
|
.option('--dbdatabase <dbdatabase>', 'Database name')
|
|
.option('--dbusername <dbusername>', 'Database username')
|
|
.option('--dbpassword <dbpassword>', 'Database password')
|
|
.option('--dbstorage <dbstorage>', 'Database file storage path for sqlite')
|
|
.description('create a new application');
|
|
}
|
|
|
|
module.exports = {
|
|
setCommandOptions,
|
|
createApp,
|
|
};
|