479f64f197
* feat: i18next * multi language data * feat(client): locale support * en-US for collections * us-EN for routes * en-US for routes * en-US for attachments * feat: partial translations * translation * add AntdConfigProvider * translation * translation * feat: translation * feat: add translation * fix: improve translation * feat: improve translation * fix: SyntaxError: Unexpected token ) in JSON at position * typo * feat: improve translation * feat: improve translation * feat: language settings can be saved on the server * feat: lang option of init cli * demo translation * typo * change address field to textarea * address data * feat: chart translation * feat: chart translation * improve translation * signin,signup,signout... Co-authored-by: Zhou <zhou.working@gmail.com>
109 lines
3.2 KiB
TypeScript
Executable File
109 lines
3.2 KiB
TypeScript
Executable File
import { chalk } from '@umijs/utils';
|
|
import commander from 'commander';
|
|
import path from 'path';
|
|
import ora from 'ora';
|
|
import { hasYarn, runInit, runInstall, runStart } from './utils';
|
|
import execa from 'execa';
|
|
|
|
const packageJson = require('../package.json');
|
|
|
|
const program = new commander.Command(packageJson.name)
|
|
.version(packageJson.version)
|
|
.option('--simple', 'create nocobase app without install dependencies')
|
|
.option('--quickstart', 'create quickstart nocobase app')
|
|
.option('--lang [lang]', 'language settings')
|
|
.arguments('<project-directory>')
|
|
.usage(`${chalk.green('<project-directory>')}`)
|
|
.action(async (directory, options) => {
|
|
console.log(
|
|
`Creating a new NocoBase application at ${chalk.green(directory)}.`,
|
|
);
|
|
console.log('Creating files.');
|
|
|
|
const fullPath = path.join(process.cwd(), directory);
|
|
|
|
await require('./index').default({
|
|
cwd: fullPath,
|
|
args: {},
|
|
tplContext: options.quickstart
|
|
? { quickstart: true }
|
|
: { quickstart: false },
|
|
});
|
|
|
|
const cmd = chalk.cyan(hasYarn() ? 'yarn' : 'npm run');
|
|
|
|
if (options.simple) {
|
|
console.log();
|
|
console.log('Done. You can start by doing:');
|
|
console.log();
|
|
console.log(` ${chalk.cyan('cd')} ${directory}`);
|
|
console.log(` ${cmd} install`);
|
|
console.log(` ${cmd} nocobase init${hasYarn() ? '' : ' --'} --import-demo`);
|
|
console.log(` ${cmd} start`);
|
|
console.log();
|
|
return;
|
|
}
|
|
|
|
const installPrefix = chalk.yellow('Installing dependencies:');
|
|
const loader = ora(installPrefix).start();
|
|
const logInstall = (chunk = '') => {
|
|
loader.text = `${installPrefix} ${chunk
|
|
.toString()
|
|
.split('\n')
|
|
.join(' ')}`;
|
|
};
|
|
|
|
const runner = runInstall(fullPath);
|
|
|
|
runner?.stdout?.on('data', logInstall);
|
|
runner?.stderr?.on('data', logInstall);
|
|
|
|
await runner;
|
|
loader.stop();
|
|
console.log(`Dependencies installed ${chalk.green('successfully')}.`);
|
|
console.log();
|
|
console.log(`Your application was created at ${chalk.green(directory)}.\n`);
|
|
|
|
if (options.quickstart) {
|
|
// Using Sqlite as Database
|
|
const prefix = chalk.yellow('NocoBase init');
|
|
const initLoader = ora(prefix).start();
|
|
|
|
try {
|
|
const initLog = (chunk = '') => {
|
|
initLoader.text = `${prefix} ${chunk
|
|
.toString()
|
|
.split('\n')
|
|
.join(' ')}`;
|
|
};
|
|
|
|
const init = runInit(fullPath, ['--import-demo', `--lang=${options.lang||'en-US'}`]);
|
|
init.stderr.on('data', initLog);
|
|
init.stdout.on('data', initLog);
|
|
await init;
|
|
initLoader.stop();
|
|
} catch (e) {
|
|
initLoader.stop();
|
|
console.log();
|
|
console.log(e.message);
|
|
process.exit(1);
|
|
}
|
|
|
|
console.log(`Running your application.`);
|
|
await execa('npm', ['run', 'start'], {
|
|
stdio: 'inherit',
|
|
cwd: fullPath,
|
|
});
|
|
} else {
|
|
console.log();
|
|
console.log('You can start by doing:');
|
|
console.log();
|
|
console.log(` ${chalk.cyan('cd')} ${directory}`);
|
|
console.log(` ${cmd} nocobase init${hasYarn() ? '' : ' --'} --import-demo`);
|
|
console.log(` ${cmd} start`);
|
|
console.log();
|
|
}
|
|
})
|
|
.showHelpAfterError()
|
|
.parse(process.argv);
|