feat(create-nocobase-app): simplify the process

This commit is contained in:
chenos 2021-10-25 14:24:24 +08:00
parent 2a696eeb7a
commit 73d439eb1f
10 changed files with 62 additions and 75 deletions

View File

@ -76,18 +76,14 @@ yarn create nocobase-app my-nocobase-app --quickstart
~~~shell ~~~shell
# 1. create project # 1. create project
yarn create nocobase-app my-nocobase-app yarn create nocobase-app my-nocobase-app
# 2. switch to the project directory
cd my-nocobase-app cd my-nocobase-app
# 2. edit configuration in .env file # 3. create initialization data
vim .env
# 3. start a database (optional)
docker-compose up -d postgres
# 4. create initialization data
yarn nocobase init --import-demo yarn nocobase init --import-demo
# 5. start project # 4. start project
yarn start yarn start
~~~ ~~~

View File

@ -82,18 +82,14 @@ yarn create nocobase-app my-nocobase-app --quickstart
~~~shell ~~~shell
# 1. 创建项目 # 1. 创建项目
yarn create nocobase-app my-nocobase-app yarn create nocobase-app my-nocobase-app
# 2. 切换到项目根目录
cd my-nocobase-app cd my-nocobase-app
# 2. 修改.env中对应的数据库配置 # 3. 初始化数据
vim .env
# 3. 启动预置数据库(可选)
docker-compose up -d postgres
# 4. 初始化数据
yarn nocobase init --import-demo yarn nocobase init --import-demo
# 5. 启动项目 # 4. 启动项目
yarn start yarn start
~~~ ~~~

View File

@ -12,7 +12,6 @@ export default class AppGenerator extends Generator {
this.copyDirectory({ this.copyDirectory({
context: { context: {
version: require('../../package').version, version: require('../../package').version,
conventionRoutes: this.args.conventionRoutes,
...this.tplContext ...this.tplContext
}, },
path: join(__dirname, '../../templates/AppGenerator'), path: join(__dirname, '../../templates/AppGenerator'),

View File

@ -37,7 +37,7 @@ const program = new commander.Command(packageJson.name)
console.log(); console.log();
console.log(` ${chalk.cyan('cd')} ${directory}`); console.log(` ${chalk.cyan('cd')} ${directory}`);
console.log(` ${cmd} install`); console.log(` ${cmd} install`);
console.log(` ${cmd} nocobase init --import-demo`); console.log(` ${cmd} nocobase init${hasYarn() ? '' : ' --'} --import-demo`);
console.log(` ${cmd} start`); console.log(` ${cmd} start`);
console.log(); console.log();
return; return;
@ -98,7 +98,7 @@ const program = new commander.Command(packageJson.name)
console.log('You can start by doing:'); console.log('You can start by doing:');
console.log(); console.log();
console.log(` ${chalk.cyan('cd')} ${directory}`); console.log(` ${chalk.cyan('cd')} ${directory}`);
console.log(` ${cmd} nocobase init --import-demo`); console.log(` ${cmd} nocobase init${hasYarn() ? '' : ' --'} --import-demo`);
console.log(` ${cmd} start`); console.log(` ${cmd} start`);
console.log(); console.log();
} }

View File

@ -24,5 +24,5 @@ export function runStart(path) {
} }
export function runInit(path) { export function runInit(path) {
return runYarn(path, ['run', 'nocobase', 'init', '--import-demo']); return runYarn(path, ['run', 'nocobase', 'init', hasYarn() ? '--import-demo' : '-- --import-demo']);
} }

View File

@ -1,5 +1,4 @@
########## DOCKER COMPOSE ENV ########## ########## DOCKER COMPOSE ENV ##########
ADMINER_PORT=8080 ADMINER_PORT=8080
DB_MYSQL_PORT=3306 DB_MYSQL_PORT=3306
DB_POSTGRES_PORT=5432 DB_POSTGRES_PORT=5432
@ -10,13 +9,16 @@ API_PORT=13002
########## NOCOBASE ENV ########## ########## NOCOBASE ENV ##########
# DATABASE # DATABASE
DB_DIALECT=sqlite
DB_STORAGE=db.sqlite
# DB_DIALECT=postgres
# DB_HOST=localhost
# DB_PORT=5432
# DB_DATABASE=nocobase
# DB_USER=nocobase
# DB_PASSWORD=nocobase
DB_DIALECT=postgres
DB_HOST=localhost
DB_PORT=5432
DB_DATABASE=nocobase
DB_USER=nocobase
DB_PASSWORD=nocobase
# set to 'on' to enable log # set to 'on' to enable log
DB_LOG_SQL= DB_LOG_SQL=

View File

@ -9,18 +9,15 @@ API_PORT=13002
########## NOCOBASE ENV ########## ########## NOCOBASE ENV ##########
# DATABASE # DATABASE
{{#quickstart}}
DB_DIALECT=sqlite DB_DIALECT=sqlite
DB_STORAGE=db.sqlite DB_STORAGE=db.sqlite
{{/quickstart}}
{{^quickstart}} # DB_DIALECT=postgres
DB_DIALECT=postgres # DB_HOST=localhost
DB_HOST=localhost # DB_PORT=5432
DB_PORT=5432 # DB_DATABASE=nocobase
DB_DATABASE=nocobase # DB_USER=nocobase
DB_USER=nocobase # DB_PASSWORD=nocobase
DB_PASSWORD=nocobase
{{/quickstart}}
# set to 'on' to enable log # set to 'on' to enable log
DB_LOG_SQL= DB_LOG_SQL=

View File

@ -0,0 +1,32 @@
import path from 'path';
import { DatabaseOptions } from '@nocobase/database';
export default {
sqlite: {
dialect: 'sqlite',
dialectModule: require('sqlite3'),
storage: process.env.DB_STORAGE || path.resolve(process.cwd(), './db.sqlite'),
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
},
postgres: {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
host: process.env.DB_HOST,
port: process.env.DB_PORT as any,
dialect: 'postgres',
dialectOptions: {
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
},
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
sync: {
force: false,
alter: {
drop: false,
},
},
},
} as {
[key: string]: DatabaseOptions,
};

View File

@ -1,36 +0,0 @@
import { DatabaseOptions } from '@nocobase/database';
{{#quickstart}}
export default {
dialect: process.env.DB_DIALECT,
dialectModule: require('sqlite3'),
storage: process.env.DB_STORAGE
} as DatabaseOptions;
{{/quickstart}}
{{^quickstart}}
export default {
username: process.env.DB_USER,
password: process.env.DB_PASSWORD,
database: process.env.DB_DATABASE,
host: process.env.DB_HOST,
port: process.env.DB_PORT as any,
dialect: process.env.DB_DIALECT as any,
dialectOptions: {
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci',
},
pool: {
max: 5,
min: 0,
acquire: 60000,
idle: 10000,
},
logging: process.env.DB_LOG_SQL === 'on' ? console.log : false,
define: {},
sync: {
force: false,
alter: {
drop: false,
},
},
} as DatabaseOptions;
{{/quickstart}}

View File

@ -1,10 +1,11 @@
import path from 'path'; import path from 'path';
import Application from '@nocobase/server'; import Application from '@nocobase/server';
import dbConfig from './config/db';
const start = Date.now(); const start = Date.now();
const api = new Application({ const api = new Application({
database: require('./config/db').default, database: dbConfig[process.env.DB_DIALECT || 'sqlite'],
resourcer: { resourcer: {
prefix: '/api', prefix: '/api',
}, },
@ -29,7 +30,7 @@ for (const plugin of plugins) {
api.plugin(require(`@nocobase/plugin-client/lib/server`).default, { api.plugin(require(`@nocobase/plugin-client/lib/server`).default, {
dist: path.resolve(process.cwd(), './dist'), dist: path.resolve(process.cwd(), './dist'),
importDemo: true, // importDemo: true,
}); });
if (process.argv.length < 3) { if (process.argv.length < 3) {