create-nocobase-app 0.7.0-alpha.34 → 0.7.0-alpha.56

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.
Files changed (43) hide show
  1. package/bin/index.js +5 -0
  2. package/package.json +8 -10
  3. package/src/cli.js +34 -0
  4. package/src/generator.js +175 -0
  5. package/src/index.js +0 -0
  6. package/src/{resources/templates/load-src-from-npm.js → util.js} +21 -13
  7. package/{src/resources/files/packages/app/server → templates}/.gitkeep +0 -0
  8. package/templates/app/.buildrc.ts +5 -0
  9. package/templates/app/.editorconfig +16 -0
  10. package/templates/app/.env.tpl +14 -0
  11. package/{src/resources/files → templates/app}/.eslintignore +0 -0
  12. package/{src/resources/files → templates/app}/.eslintrc +0 -0
  13. package/templates/app/.gitignore.tpl +19 -0
  14. package/{src/resources/files → templates/app}/.prettierignore +2 -1
  15. package/{src/resources/files → templates/app}/.prettierrc +0 -0
  16. package/{src/resources/files → templates/app}/jest.config.js +5 -3
  17. package/{src/resources/files → templates/app}/jest.setup.ts +0 -1
  18. package/{src/resources/files → templates/app}/lerna.json +1 -1
  19. package/templates/app/package.json.tpl +28 -0
  20. package/{src/resources/files/packages/plugins → templates/app/packages/app/client}/.gitkeep +0 -0
  21. package/templates/app/packages/app/server/.gitkeep +0 -0
  22. package/templates/app/packages/plugins/.gitkeep +0 -0
  23. package/templates/app/tsconfig.jest.json +13 -0
  24. package/{src/resources/files → templates/app}/tsconfig.json +3 -3
  25. package/templates/app/tsconfig.server.json +7 -0
  26. package/bin/create-nocobase-app.js +0 -3
  27. package/src/create-app.js +0 -170
  28. package/src/create-nocobase-app.js +0 -11
  29. package/src/resources/files/jest.cli.js +0 -23
  30. package/src/resources/files/packages/app/client/.umirc.ts +0 -35
  31. package/src/resources/files/packages/app/server/tsconfig.build.json +0 -9
  32. package/src/resources/files/packages/app/server/tsconfig.json +0 -5
  33. package/src/resources/files/pnpm-workspace.yaml +0 -2
  34. package/src/resources/files/storage/db/.gitignore +0 -2
  35. package/src/resources/files/storage/uploads/.gitignore +0 -2
  36. package/src/resources/files/tsconfig.build.json +0 -19
  37. package/src/resources/files/tsconfig.jest.json +0 -14
  38. package/src/resources/templates/client.package.json.js +0 -16
  39. package/src/resources/templates/env.js +0 -34
  40. package/src/resources/templates/env.template +0 -42
  41. package/src/resources/templates/package.json.js +0 -71
  42. package/src/resources/templates/server.package.json.js +0 -38
  43. package/src/utils.js +0 -39
package/bin/index.js ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env node
2
+
3
+ const cli = require('../src/cli');
4
+
5
+ cli.parse(process.argv);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-nocobase-app",
3
- "version": "0.7.0-alpha.34",
3
+ "version": "0.7.0-alpha.56",
4
4
  "main": "src/index.js",
5
5
  "license": "Apache-2.0",
6
6
  "licenses": [
@@ -10,21 +10,19 @@
10
10
  }
11
11
  ],
12
12
  "dependencies": {
13
- "@nocobase/utils": "^0.5.0-alpha.38",
13
+ "@umijs/utils": "^3.5.20",
14
14
  "axios": "^0.26.1",
15
15
  "chalk": "^4.1.1",
16
- "commander": "^8.2.0",
17
- "execa": "5",
18
- "fs-extra": "^10.0.1",
19
- "lodash": "^4.17.21",
20
- "ora": "^5.4.1",
21
- "tar": "^6.1.11"
16
+ "commander": "^9.2.0",
17
+ "tar": "6.1.11"
18
+ },
19
+ "bin": {
20
+ "create-nocobase-app": "./bin/index.js"
22
21
  },
23
- "bin": "./bin/create-nocobase-app.js",
24
22
  "repository": {
25
23
  "type": "git",
26
24
  "url": "git+https://github.com/nocobase/nocobase.git",
27
25
  "directory": "packages/core/create-nocobase-app"
28
26
  },
29
- "gitHead": "48b2b4bc7bbc39533e461d34d7f026a4ad1a9b5c"
27
+ "gitHead": "9a8c05e8fb26029f1d1ba68408a8bddac0e67a76"
30
28
  }
package/src/cli.js ADDED
@@ -0,0 +1,34 @@
1
+ const chalk = require('chalk');
2
+ const { resolve } = require('path');
3
+ const { Command } = require('commander');
4
+ const { AppGenerator } = require('./generator');
5
+ const { concat } = require('./util');
6
+ const packageJson = require('../package.json');
7
+
8
+ const cli = new Command('create-nocobase');
9
+
10
+ cli
11
+ .arguments('<name>', 'directory of new NocoBase app')
12
+ .option('--quickstart', 'quickstart app creation')
13
+ .option('--all-db-deps', 'install all database dialect dependencies')
14
+ .option('-d, --db-dialect <dbDialect>', 'database dialect, current support sqlite/mysql/postgres', 'sqlite')
15
+ .option('-e, --env <env>', 'environment variables write into .env file', concat, [])
16
+ .description('create a new application')
17
+ .action(async (name, options) => {
18
+ if (options.quickstart) {
19
+ console.log(`⚠️ ${chalk.yellow('quickstart option is deprecated')}`);
20
+ }
21
+
22
+ const generator = new AppGenerator({
23
+ cwd: resolve(process.cwd(), name),
24
+ args: options,
25
+ context: {
26
+ name,
27
+ version: packageJson.version,
28
+ },
29
+ });
30
+
31
+ await generator.run();
32
+ });
33
+
34
+ module.exports = cli;
@@ -0,0 +1,175 @@
1
+ const chalk = require('chalk');
2
+ const crypto = require('crypto');
3
+ const { existsSync } = require('fs');
4
+ const { join, resolve } = require('path');
5
+ const { Generator } = require('@umijs/utils');
6
+ const { downloadPackageFromNpm, updateJsonFile } = require('./util');
7
+
8
+ class AppGenerator extends Generator {
9
+ constructor(options) {
10
+ const { context = {}, ...opts } = options;
11
+ super(opts);
12
+ this.context = context;
13
+ this.env = this.parseEnvs();
14
+ }
15
+
16
+ parseEnvs() {
17
+ const envs = this.args.env;
18
+ const items = {};
19
+ for (const env of envs) {
20
+ const keys = env.split('=');
21
+ if (keys.length !== 2) {
22
+ console.log(`${chalk.red(env)} is not a valid environment value`);
23
+ process.exit(1);
24
+ }
25
+ items[keys[0]] = keys[1];
26
+ }
27
+ return items;
28
+ }
29
+
30
+ checkDbEnv() {
31
+ const dialect = this.args.dbDialect;
32
+ const env = this.env;
33
+ if (dialect === 'sqlite') {
34
+ return;
35
+ }
36
+ if (!env.DB_DATABASE || !env.DB_USER || !env.DB_PASSWORD) {
37
+ console.log(
38
+ chalk.red(
39
+ `Please set DB_HOST, DB_PORT, DB_DATABASE, DB_USER, DB_PASSWORD in .env file to complete database settings`,
40
+ ),
41
+ );
42
+ }
43
+ }
44
+
45
+ checkProjectPath() {
46
+ if (existsSync(this.cwd)) {
47
+ console.log(chalk.red('Project directory already exists'));
48
+ process.exit(1);
49
+ }
50
+ }
51
+
52
+ checkDialect() {
53
+ const dialect = this.args.dbDialect;
54
+ const supportDialects = ['mysql', 'sqlite', 'postgres'];
55
+ if (!supportDialects.includes(dialect)) {
56
+ console.log(
57
+ `dialect ${chalk.red(dialect)} is not supported, currently supported dialects are ${chalk.green(
58
+ supportDialects.join(','),
59
+ )}.`,
60
+ );
61
+ process.exit(1);
62
+ }
63
+ }
64
+
65
+ getContext() {
66
+ const env = this.env;
67
+ const envs = [];
68
+ const dependencies = [];
69
+ const { dbDialect, allDbDeps } = this.args;
70
+
71
+ if (allDbDeps) {
72
+ dependencies.push(`"mysql2": "^2.3.3"`);
73
+ dependencies.push(`"pg": "^8.7.3"`);
74
+ dependencies.push(`"pg-hstore": "^2.3.4"`);
75
+ dependencies.push(`"sqlite3": "^5.0.8"`);
76
+ }
77
+
78
+ switch (dbDialect) {
79
+ case 'sqlite':
80
+ if (!allDbDeps) {
81
+ dependencies.push(`"sqlite3": "^5.0.8"`);
82
+ }
83
+ envs.push(`DB_STORAGE=${env.DB_STORAGE || 'storages/db/nocobase.sqlite'}`);
84
+ break;
85
+ case 'mysql':
86
+ if (!allDbDeps) {
87
+ dependencies.push(`"mysql2": "^2.3.3"`);
88
+ }
89
+ envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
90
+ envs.push(`DB_PORT=${env.DB_PORT || 3306}`);
91
+ envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
92
+ envs.push(`DB_USER=${env.DB_USER || ''}`);
93
+ envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
94
+ break;
95
+ case 'postgres':
96
+ if (!allDbDeps) {
97
+ dependencies.push(`"pg": "^8.7.3"`);
98
+ dependencies.push(`"pg-hstore": "^2.3.4"`);
99
+ }
100
+ envs.push(`DB_HOST=${env.DB_HOST || 'localhost'}`);
101
+ envs.push(`DB_PORT=${env.DB_PORT || 5432}`);
102
+ envs.push(`DB_DATABASE=${env.DB_DATABASE || ''}`);
103
+ envs.push(`DB_USER=${env.DB_USER || ''}`);
104
+ envs.push(`DB_PASSWORD=${env.DB_PASSWORD || ''}`);
105
+ break;
106
+ }
107
+
108
+ return {
109
+ ...this.context,
110
+ dependencies: dependencies.join(`,\n `),
111
+ envs: envs.join(`\n`),
112
+ env: {
113
+ APP_PORT: 13000,
114
+ APP_ENV: 'development',
115
+ DB_DIALECT: dbDialect,
116
+ APP_KEY: crypto.randomBytes(256).toString('base64'),
117
+ ...env,
118
+ },
119
+ };
120
+ }
121
+
122
+ async downloadServerPackage() {
123
+ const { name } = this.context;
124
+ console.log('Download: @nocobase/app-server');
125
+ const serverPackageDir = resolve(this.cwd, 'packages/app/server');
126
+ await downloadPackageFromNpm('@nocobase/app-server', serverPackageDir);
127
+ await updateJsonFile(resolve(serverPackageDir, 'package.json'), (data) => {
128
+ data['name'] = `@${name}/server`;
129
+ data['version'] = '0.1.0';
130
+ return data;
131
+ });
132
+ }
133
+
134
+ async downloadClientPackage() {
135
+ const { name } = this.context;
136
+ console.log('Download: @nocobase/app-client');
137
+ const clientPackageDir = resolve(this.cwd, 'packages/app/client');
138
+ await downloadPackageFromNpm('@nocobase/app-client', clientPackageDir);
139
+ await updateJsonFile(resolve(clientPackageDir, 'package.json'), (data) => {
140
+ data['name'] = `@${name}/client`;
141
+ data['version'] = '0.1.0';
142
+ return data;
143
+ });
144
+ }
145
+
146
+ async writing() {
147
+ this.checkProjectPath();
148
+ this.checkDialect();
149
+
150
+ const { name } = this.context;
151
+
152
+ console.log(`Creating a new NocoBase application at ${chalk.green(name)}`);
153
+ console.log('Creating files');
154
+
155
+ this.copyDirectory({
156
+ context: this.getContext(),
157
+ path: join(__dirname, '../templates/app'),
158
+ target: this.cwd,
159
+ });
160
+
161
+ await this.downloadServerPackage();
162
+ await this.downloadClientPackage();
163
+
164
+ this.checkDbEnv();
165
+
166
+ console.log('');
167
+ console.log(chalk.green(`$ cd ${name}`));
168
+ console.log(chalk.green(`$ yarn install`));
169
+ console.log(chalk.green(`$ yarn nocobase install`));
170
+ console.log(chalk.green(`$ yarn dev`));
171
+ console.log('');
172
+ }
173
+ }
174
+
175
+ exports.AppGenerator = AppGenerator;
package/src/index.js CHANGED
File without changes
@@ -1,20 +1,18 @@
1
- const execa = require('execa');
2
- const axios = require('axios');
3
1
  const fs = require('fs');
4
- const fsP = require('fs').promises;
5
2
  const tar = require('tar');
6
- const { join } = require('path');
3
+ const axios = require('axios');
4
+ const chalk = require('chalk');
7
5
  const crypto = require('crypto');
6
+ const { join } = require('path');
7
+ const { execa } = require('@umijs/utils');
8
+ const { unlink, writeFile, readFile } = require('fs').promises;
8
9
 
9
- module.exports = async (packageName, target) => {
10
- const viewResult = await execa('npm', ['v', packageName, 'dist.tarball']);
11
- const url = viewResult['stdout'];
12
-
10
+ exports.downloadPackageFromNpm = async (packageName, target) => {
11
+ const { stdout } = await execa('npm', ['v', packageName, 'dist.tarball']);
13
12
  const tarballFile = join(target, '..', `${crypto.createHash('md5').update(packageName).digest('hex')}-tarball.gz`);
14
-
15
13
  const writer = fs.createWriteStream(tarballFile);
16
-
17
- await axios.get(url, { responseType: 'stream' }).then((response) => {
14
+ console.log(chalk.gray(`URL: ${stdout}`));
15
+ await axios.get(stdout, { responseType: 'stream' }).then((response) => {
18
16
  return new Promise((resolve, reject) => {
19
17
  response.data.pipe(writer);
20
18
 
@@ -34,7 +32,7 @@ module.exports = async (packageName, target) => {
34
32
  });
35
33
  });
36
34
 
37
- const result = await tar.x({
35
+ await tar.x({
38
36
  file: tarballFile,
39
37
  gzip: true,
40
38
  cwd: target,
@@ -45,5 +43,15 @@ module.exports = async (packageName, target) => {
45
43
  // },
46
44
  });
47
45
 
48
- await fsP.unlink(tarballFile);
46
+ await unlink(tarballFile);
47
+ };
48
+
49
+ exports.updateJsonFile = async (target, fn) => {
50
+ const content = await readFile(target, 'utf-8');
51
+ const json = JSON.parse(content);
52
+ await writeFile(target, JSON.stringify(fn(json), null, 2), 'utf-8');
53
+ };
54
+
55
+ exports.concat = (value, previous) => {
56
+ return previous.concat([value]);
49
57
  };
@@ -0,0 +1,5 @@
1
+ export default {
2
+ target: 'node',
3
+ cjs: { type: 'babel', lazy: true },
4
+ excludePkgs: ['app/client'],
5
+ };
@@ -0,0 +1,16 @@
1
+ # http://editorconfig.org
2
+ root = true
3
+
4
+ [*]
5
+ indent_style = space
6
+ indent_size = 2
7
+ end_of_line = lf
8
+ charset = utf-8
9
+ trim_trailing_whitespace = true
10
+ insert_final_newline = true
11
+
12
+ [*.md]
13
+ trim_trailing_whitespace = false
14
+
15
+ [Makefile]
16
+ indent_style = tab
@@ -0,0 +1,14 @@
1
+ APP_ENV={{{env.APP_ENV}}}
2
+ APP_KEY={{{env.APP_KEY}}}
3
+ APP_PORT={{{env.APP_PORT}}}
4
+
5
+ API_BASE_PATH=/api/
6
+ API_BASE_URL=
7
+
8
+ DB_LOGGING=off
9
+ DB_DIALECT={{{env.DB_DIALECT}}}
10
+ {{{envs}}}
11
+
12
+ INIT_ROOT_EMAIL=admin@nocobase.com
13
+ INIT_ROOT_PASSWORD=admin123
14
+ INIT_ROOT_NICKNAME=Super Admin
File without changes
@@ -0,0 +1,19 @@
1
+ node_modules/
2
+ lib/
3
+ esm/
4
+ es/
5
+ .env
6
+ .DS_Store
7
+ yarn-error.log
8
+ lerna-debug.log
9
+ /.vscode
10
+ /.idea
11
+ *.sqlite
12
+ coverage
13
+ .umi
14
+ /uploads
15
+ .env.test
16
+ docs-dist/
17
+ .npmrc
18
+ dist/
19
+ docker/**/storage
@@ -8,4 +8,5 @@ package.json
8
8
  .umi-test
9
9
  packages/**/lib/**
10
10
  packages/**/esm/**
11
- packages/**/node_modules/**
11
+ packages/**/node_modules/**
12
+ packages/core/client/src/locale/*
@@ -1,13 +1,15 @@
1
1
  const { pathsToModuleNameMapper } = require('ts-jest/utils');
2
- const { compilerOptions } = require('./tsconfig.jest.json');
2
+ const { compilerOptions } = require('./tsconfig.json');
3
+ const { resolve } = require('path');
3
4
 
4
5
  module.exports = {
6
+ rootDir: process.cwd(),
5
7
  collectCoverage: false,
6
8
  verbose: true,
7
9
  testEnvironment: 'jsdom',
8
10
  preset: 'ts-jest',
9
11
  testMatch: ['**/__tests__/**/*.test.[jt]s?(x)'],
10
- setupFilesAfterEnv: [require.resolve('jest-dom/extend-expect'), './jest.setup.ts'],
12
+ setupFilesAfterEnv: [require.resolve('jest-dom/extend-expect'), resolve(__dirname, './jest.setup.ts')],
11
13
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
12
14
  prefix: '<rootDir>/',
13
15
  }),
@@ -18,7 +20,7 @@ module.exports = {
18
20
  diagnostics: false,
19
21
  },
20
22
  },
21
- modulePathIgnorePatterns: ['/esm/', '/lib/'],
23
+ modulePathIgnorePatterns: ['/esm/', '/es/', '/dist/', '/lib/'],
22
24
  coveragePathIgnorePatterns: [
23
25
  '/node_modules/',
24
26
  '/__tests__/',
@@ -4,7 +4,6 @@ global['prettyFormat'] = prettyFormat;
4
4
 
5
5
  jest.setTimeout(300000);
6
6
 
7
- // 把 console.error 转换成 error,方便断言
8
7
  (() => {
9
8
  const spy = jest.spyOn(console, 'error');
10
9
  afterAll(() => {
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.6.0",
2
+ "version": "independent",
3
3
  "npmClient": "yarn",
4
4
  "useWorkspaces": true,
5
5
  "npmClientArgs": [
@@ -0,0 +1,28 @@
1
+ {
2
+ "name": "{{{name}}}",
3
+ "private": true,
4
+ "workspaces": [
5
+ "packages/*/*"
6
+ ],
7
+ "scripts": {
8
+ "nocobase": "nocobase",
9
+ "dev": "nocobase dev",
10
+ "start": "nocobase start",
11
+ "clean": "nocobase clean",
12
+ "build": "nocobase build",
13
+ "test": "nocobase test",
14
+ "postinstall": "nocobase postinstall",
15
+ "lint": "eslint ."
16
+ },
17
+ "resolutions": {
18
+ "@types/react": "^17.0.0",
19
+ "@types/react-dom": "^17.0.0"
20
+ },
21
+ "dependencies": {
22
+ "@nocobase/cli": "{{{version}}}",
23
+ {{{dependencies}}}
24
+ },
25
+ "devDependencies": {
26
+ "@nocobase/devtools": "{{{version}}}"
27
+ }
28
+ }
File without changes
File without changes
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES6",
5
+ "module": "CommonJS"
6
+ },
7
+ "exclude": [
8
+ "./packages/*/esm",
9
+ "./packages/*/es",
10
+ "./packages/*/dist",
11
+ "./packages/*/lib"
12
+ ]
13
+ }
@@ -3,9 +3,9 @@
3
3
  "esModuleInterop": true,
4
4
  "moduleResolution": "node",
5
5
  "jsx": "react",
6
- "module": "commonjs",
7
- "target": "es6",
8
- "allowJs": false,
6
+ "target": "esnext",
7
+ "module": "esnext",
8
+ "allowJs": true,
9
9
  "noUnusedLocals": false,
10
10
  "preserveConstEnums": true,
11
11
  "skipLibCheck": true,
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "target": "ES6",
5
+ "module": "CommonJS"
6
+ }
7
+ }
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('../src/create-nocobase-app');
package/src/create-app.js DELETED
@@ -1,170 +0,0 @@
1
- const chalk = require('chalk');
2
- const fse = require('fs-extra');
3
- const path = require('path');
4
- const { hasYarn, runInit, runInstall } = require('./utils');
5
- const ora = require('ora');
6
- const execa = require('execa');
7
- const { join, resolve } = require('path');
8
-
9
- const createEnvFile = require('./resources/templates/env');
10
- const createPackageJson = require('./resources/templates/package.json.js');
11
- const createServerPackageJson = require('./resources/templates/server.package.json.js');
12
- const createClientPackageJson = require('./resources/templates/client.package.json.js');
13
- const loadSrcFromNpm = require('./resources/templates/load-src-from-npm');
14
-
15
- let envs = undefined;
16
-
17
- const parseEnvs = (options) => {
18
- if (envs) {
19
- return envs;
20
- }
21
-
22
- for (const env of options.env) {
23
- if (!env.match(/\w+=\w+/)) {
24
- console.log(`${chalk.red(env)} is not a valid environment value`);
25
- process.exit(1);
26
- }
27
- }
28
-
29
- envs = options.env
30
- .map((env) => env.split('='))
31
- .reduce((carry, item) => {
32
- carry[item[0]] = item[1];
33
- return carry;
34
- }, {});
35
-
36
- return envs;
37
- };
38
-
39
- function checkDialect(dialect) {
40
- const supportDialects = ['mysql', 'sqlite', 'postgres'];
41
- if (!supportDialects.includes(dialect)) {
42
- console.log(
43
- `dialect ${chalk.red(dialect)} is not supported, currently supported dialects are ${chalk.green(
44
- supportDialects.join(','),
45
- )}.`,
46
- );
47
- process.exit(1);
48
- }
49
- }
50
-
51
- const getDatabaseOptionsFromCommandOptions = (commandOptions) => {
52
- const envs = parseEnvs(commandOptions);
53
-
54
- if (!commandOptions.dbDialect || commandOptions.dbDialect === 'sqlite' || envs['DB_STORAGE']) {
55
- return {
56
- dialect: 'sqlite',
57
- storage: envs['DB_STORAGE'] || 'storage/db/nocobase.sqlite',
58
- };
59
- }
60
-
61
- const databaseOptions = {
62
- dialect: commandOptions.dbDialect,
63
- host: envs['DB_HOST'],
64
- port: envs['DB_PORT'],
65
- database: envs['DB_DATABASE'],
66
- user: envs['DB_USER'],
67
- password: envs['DB_PASSWORD'],
68
- };
69
-
70
- const emptyValues = Object.entries(databaseOptions).filter((items) => !items[1]);
71
-
72
- if (emptyValues.length > 0) {
73
- console.log(
74
- chalk.red(
75
- `Please set ${emptyValues
76
- .map((i) => i[0])
77
- .map((i) => `DB_${i.toUpperCase()}`)
78
- .join(' ')} in .env file to complete database settings`,
79
- ),
80
- );
81
- }
82
-
83
- return databaseOptions;
84
- };
85
-
86
- async function createApp(directory, options) {
87
- const dbDialect = options.dbDialect || 'sqlite';
88
- checkDialect(dbDialect);
89
-
90
- if (options.quickstart) {
91
- console.log(`⚠️ ${chalk.yellow('quickstart option is deprecated')}`);
92
- }
93
-
94
- parseEnvs(options);
95
-
96
- console.log(`Creating a new NocoBase application at ${chalk.green(directory)}.`);
97
- console.log('Creating files.');
98
-
99
- const projectPath = path.join(process.cwd(), directory);
100
- const resourcePath = path.join(__dirname, 'resources');
101
-
102
- const dbOptions = getDatabaseOptionsFromCommandOptions(options);
103
-
104
- // copy files
105
- await fse.copy(path.join(resourcePath, 'files'), projectPath);
106
-
107
- console.log('download @nocobase/app-server');
108
- await loadSrcFromNpm('@nocobase/app-server', path.join(projectPath, 'packages/app/server'));
109
-
110
- console.log('download @nocobase/app-client');
111
- await loadSrcFromNpm('@nocobase/app-client', path.join(projectPath, 'packages/app/client'));
112
-
113
- // write .env file
114
- await fse.writeFile(join(projectPath, '.env'), createEnvFile({ dbOptions, envs: parseEnvs(options) }));
115
-
116
- // write root packages.json
117
- await fse.writeJson(
118
- join(projectPath, 'package.json'),
119
- createPackageJson({
120
- projectName: 'nocobase-app',
121
- }),
122
- {
123
- spaces: 2,
124
- },
125
- );
126
-
127
- // write server package.json
128
- await fse.writeJson(
129
- join(projectPath, 'packages/app/server/package.json'),
130
- createServerPackageJson({
131
- projectPath,
132
- dbOptions,
133
- }),
134
- {
135
- spaces: 2,
136
- },
137
- );
138
-
139
- // write client package.json
140
- await fse.writeJson(
141
- join(projectPath, 'packages/app/client/package.json'),
142
- createClientPackageJson({
143
- projectPath,
144
- }),
145
- {
146
- spaces: 2,
147
- },
148
- );
149
-
150
- // run install command
151
- console.log('finished');
152
- }
153
-
154
- function collect(value, previous) {
155
- return previous.concat([value]);
156
- }
157
-
158
- function setCommandOptions(command) {
159
- return command
160
- .arguments('<directory>', 'directory of new NocoBase app')
161
- .option('--quickstart', 'Quickstart app creation')
162
- .option('-d, --db-dialect <dbdialect>', 'Database dialect, current support sqlite/mysql/postgres')
163
- .option('-e, --env <envvalue>', 'environment variables write into .env file', collect, [])
164
- .description('create a new application');
165
- }
166
-
167
- module.exports = {
168
- setCommandOptions,
169
- createApp,
170
- };
@@ -1,11 +0,0 @@
1
- const { createApp, setCommandOptions } = require('./create-app');
2
-
3
- const { Command } = require('commander');
4
- const packageJson = require('../package.json');
5
- const program = new Command(packageJson.name);
6
-
7
- setCommandOptions(program);
8
-
9
- program.action((directory, options) => createApp(directory, options));
10
-
11
- program.parse(process.argv);
@@ -1,23 +0,0 @@
1
- const dotenv = require('dotenv');
2
- const { existsSync } = require('fs');
3
- const { resolve } = require('path')
4
- const yargs = require('yargs');
5
-
6
- const envFile = existsSync(resolve(__dirname, '.env.test')) ? '.env.test' : '.env';
7
-
8
- dotenv.config({
9
- path: resolve(__dirname, envFile),
10
- });
11
-
12
- if (yargs.argv.dbDialect) {
13
- process.env.DB_DIALECT = yargs.argv.dbDialect;
14
- }
15
-
16
- if (yargs.argv.dbPort) {
17
- process.env.DB_PORT = yargs.argv.dbPort;
18
- }
19
-
20
- console.log('DB_DIALECT:', process.env.DB_DIALECT);
21
- console.log('DB_PORT:', process.env.DB_PORT);
22
-
23
- require('jest-cli/bin/jest');
@@ -1,35 +0,0 @@
1
- import { getUmiConfig } from '@nocobase/utils/umiConfig';
2
- import dotenv from 'dotenv';
3
- import { resolve } from 'path';
4
- import { defineConfig } from 'umi';
5
-
6
- dotenv.config({
7
- path: resolve(__dirname, '../../../.env'),
8
- });
9
-
10
- process.env.MFSU_AD = 'none';
11
-
12
- const umiConfig = getUmiConfig();
13
-
14
- export default defineConfig({
15
- hash: true,
16
- define: {
17
- 'process.env.NOCOBASE_ENV': process.env.NOCOBASE_ENV,
18
- ...umiConfig.define,
19
- },
20
- // only proxy when using `umi dev`
21
- // if the assets are built, will not proxy
22
- proxy: {
23
- ...umiConfig.proxy,
24
- },
25
- nodeModulesTransform: {
26
- type: 'none',
27
- },
28
- routes: [{ path: '/', exact: false, component: '@/pages/index' }],
29
- // fastRefresh: {},
30
- chainWebpack(config) {
31
- const clientSrc = resolve(__dirname, '../../../node_modules/@nocobase/client/src');
32
- config.module.rules.get('ts-in-node_modules').include.add(clientSrc);
33
- config.resolve.alias.set('@nocobase/client', clientSrc);
34
- },
35
- });
@@ -1,9 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.build.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "declaration": true
6
- },
7
- "include": ["./src/**/*.ts", "./src/**/*.tsx"],
8
- "exclude": ["./src/__tests__/*", "./esm/*", "./lib/*"]
9
- }
@@ -1,5 +0,0 @@
1
- {
2
- "extends": "../../../tsconfig.json",
3
- "include": ["./src/**/*.ts", "./src/**/*.tsx"],
4
- "exclude": ["./esm/*", "./lib/*"]
5
- }
@@ -1,2 +0,0 @@
1
- packages:
2
- - packages/**
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore
@@ -1,2 +0,0 @@
1
- *
2
- !.gitignore
@@ -1,19 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "esModuleInterop": true,
4
- "resolveJsonModule": true,
5
- "moduleResolution": "node",
6
- "jsx": "react",
7
- "module": "commonjs",
8
- "target": "es6",
9
- "allowJs": false,
10
- "noUnusedLocals": false,
11
- "preserveConstEnums": true,
12
- "skipLibCheck": true,
13
- "sourceMap": true,
14
- "inlineSources": true,
15
- "declaration": true,
16
- "experimentalDecorators": true,
17
- "downlevelIteration": true,
18
- }
19
- }
@@ -1,14 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "jsx": "react",
5
- "esModuleInterop": true,
6
- "resolveJsonModule": true,
7
- "moduleResolution": "node",
8
- "allowJs": true,
9
- "module": "commonjs",
10
- "target": "es6",
11
- "paths": {}
12
- },
13
- "exclude": ["./packages/*/esm", "./packages/*/lib"]
14
- }
@@ -1,16 +0,0 @@
1
- const path = require('path');
2
-
3
- module.exports = (opts) => {
4
- const { projectPath } = opts;
5
- const templateJsonPath = path.join(projectPath, 'packages/app/client/package.json');
6
- const templateJson = require(templateJsonPath);
7
-
8
- return {
9
- ...templateJson,
10
- name: 'app-client',
11
- version: '0.1.0',
12
- dependencies: {
13
- ...templateJson.dependencies,
14
- },
15
- };
16
- };
@@ -1,34 +0,0 @@
1
- const fs = require('fs');
2
- const path = require('path');
3
- const crypto = require('crypto');
4
- const _ = require('lodash');
5
-
6
- const generateASecret = () => crypto.randomBytes(256).toString('base64');
7
-
8
- module.exports = (options) => {
9
- const { dbOptions, envs } = options;
10
- const tmpl = fs.readFileSync(path.join(__dirname, 'env.template'));
11
- const compile = _.template(tmpl);
12
-
13
- const dbEnvs = Object.keys(dbOptions)
14
- .map((keyName) => [`DB_${keyName.toUpperCase()}`, dbOptions[keyName]])
15
- .map((item) => `${item[0]}=${item[1] || ''}`)
16
- .join('\n');
17
-
18
- let envContent = compile({
19
- jwtSecret: generateASecret(),
20
- dbEnvs,
21
- });
22
-
23
- for (const env of Object.entries(envs)) {
24
- const [key, value] = env;
25
- const re = new RegExp(`^${key}=(.+)`, 'm');
26
- if (envContent.match(re)) {
27
- envContent = envContent.replace(re, `${key}=${value}`);
28
- } else {
29
- envContent = `${envContent}${key}=${value}\n`;
30
- }
31
- }
32
-
33
- return envContent;
34
- };
@@ -1,42 +0,0 @@
1
- ################# NOCOBASE APPLICATION #################
2
-
3
- NOCOBASE_ENV=development
4
- JWT_SECRET=<%= jwtSecret %>
5
-
6
- SERVER_HOST=0.0.0.0
7
- SERVER_PORT=3000
8
-
9
- # api base path endpoint for app(web)
10
- SERVER_BASE_PATH=/api/
11
-
12
- # api server access point for app(web when build)
13
- SERVER_BASE_URL=
14
-
15
- ################# DATABASE #################
16
-
17
- DB_LOG_SQL=off
18
- <%= dbEnvs %>
19
-
20
- ################# STORAGE (Initialization only) #################
21
-
22
- # local or ali-oss
23
- DEFAULT_STORAGE_TYPE=local
24
-
25
- # LOCAL STORAGE
26
- LOCAL_STORAGE_USE_STATIC_SERVER=true
27
- LOCAL_STORAGE_BASE_URL=
28
- LOCAL_STORAGE_DEST=storage/uploads
29
-
30
- # ALI OSS STORAGE
31
- ALI_OSS_STORAGE_BASE_URL=
32
- ALI_OSS_REGION=oss-cn-beijing
33
- ALI_OSS_ACCESS_KEY_ID=
34
- ALI_OSS_ACCESS_KEY_SECRET=
35
- ALI_OSS_BUCKET=
36
-
37
- # AWS
38
- AWS_ACCESS_KEY_ID=
39
- AWS_SECRET_ACCESS_KEY=
40
- AWS_S3_REGION=
41
- AWS_S3_BUCKET=
42
- AWS_S3_STORAGE_BASE_URL=
@@ -1,71 +0,0 @@
1
- module.exports = (opts) => {
2
- const { projectName } = opts;
3
- return {
4
- name: projectName,
5
- version: '0.1.0',
6
- private: true,
7
- workspaces: ['packages/app/*', 'packages/plugins/*'],
8
- license: 'MIT',
9
- scripts: {
10
- start: 'concurrently --kill-others "yarn start-server -s" "yarn start-client"',
11
- bootstrap: 'lerna bootstrap',
12
- clean: 'rimraf -rf packages/{app,plugins}/*/{lib,esm,dist} && lerna clean',
13
- nocobase:
14
- 'cross-env DOTENV_CONFIG_PATH=.env ts-node-dev -r dotenv/config -r tsconfig-paths/register ./packages/app/server/src/index.ts',
15
- 'nocobase-prod': 'cross-env DOTENV_CONFIG_PATH=.env node -r dotenv/config packages/app/server/lib/index.js',
16
- 'start-client': 'cd packages/app/client && yarn start',
17
- 'start-server': 'yarn nocobase start',
18
- 'start-pm2': 'pm2-runtime start --node-args="-r dotenv/config" packages/app/server/lib/index.js -- start',
19
- build: 'lerna run build',
20
- 'build-docs': 'dumi build',
21
- test: 'node ./jest.cli.js -i',
22
- lint: 'eslint .',
23
- },
24
- resolutions: {
25
- '@types/react': '^17.0.0',
26
- '@types/react-dom': '^17.0.0',
27
- },
28
- dependencies: {
29
- 'cross-env': '^7.0.3',
30
- dotenv: '^10.0.0',
31
- pm2: '^5.2.0',
32
- },
33
- devDependencies: {
34
- '@testing-library/react': '^12.1.2',
35
- '@types/jest': '^26.0.0',
36
- '@types/node': '^12.6.8',
37
- '@types/react': '^17.0.0',
38
- '@types/react-dom': '^17.0.0',
39
- '@typescript-eslint/eslint-plugin': '^4.9.1',
40
- '@typescript-eslint/parser': '^4.8.2',
41
- concurrently: '^7.0.0',
42
- eslint: '^7.14.0',
43
- 'eslint-config-prettier': '^7.0.0',
44
- 'eslint-plugin-import': '^2.13.0',
45
- 'eslint-plugin-markdown': '^2.0.1',
46
- 'eslint-plugin-node': '^11.1.0',
47
- 'eslint-plugin-prettier': '^3.1.0',
48
- 'eslint-plugin-promise': '^4.0.0',
49
- 'eslint-plugin-react': '^7.14.2',
50
- 'eslint-plugin-react-hooks': '^4.2.0',
51
- 'eslint-plugin-vue': '^7.0.1',
52
- jest: '^26.0.0',
53
- 'jest-codemods': '^0.19.1',
54
- 'jest-dom': '^3.1.2',
55
- 'jest-localstorage-mock': '^2.3.0',
56
- 'jest-styled-components': '6.3.3',
57
- 'jest-watch-lerna-packages': '^1.1.0',
58
- lerna: '^4.0.0',
59
- prettier: '^2.2.1',
60
- 'pretty-format': '^24.0.0',
61
- 'pretty-quick': '^3.1.0',
62
- rimraf: '^3.0.0',
63
- 'ts-jest': '^26.0.0',
64
- 'ts-loader': '^7.0.4',
65
- 'ts-node': '^9.1.1',
66
- 'ts-node-dev': '^1.1.8',
67
- 'tsconfig-paths': '^3.12.0',
68
- typescript: '^4.1.5',
69
- },
70
- };
71
- };
@@ -1,38 +0,0 @@
1
- const path = require('path');
2
- const dialectLib = (dialect) => {
3
- if (dialect === 'sqlite') {
4
- return {
5
- sqlite3: '^5.0.2',
6
- };
7
- }
8
-
9
- if (dialect === 'mysql') {
10
- return {
11
- mysql2: '^2.3.3',
12
- };
13
- }
14
-
15
- if (dialect === 'postgres') {
16
- return {
17
- pg: '^8.7.3',
18
- 'pg-hstore': '^2.3.4',
19
- };
20
- }
21
- };
22
-
23
- module.exports = (opts) => {
24
- const { dbOptions, projectPath } = opts;
25
- const templateJsonPath = path.join(projectPath, 'packages/app/server/package.json');
26
- const templateJson = require(templateJsonPath);
27
-
28
- return {
29
- ...templateJson,
30
- name: 'app-server',
31
- version: '0.1.0',
32
- main: 'index.js',
33
- dependencies: {
34
- ...templateJson.dependencies,
35
- ...dialectLib(dbOptions.dialect),
36
- },
37
- };
38
- };
package/src/utils.js DELETED
@@ -1,39 +0,0 @@
1
- const execa = require('execa');
2
-
3
- function hasYarn() {
4
- return (process.env.npm_config_user_agent || '').indexOf('yarn') === 0;
5
- }
6
-
7
- function runYarn(path, args) {
8
- if (hasYarn()) {
9
- return execa('yarn', args, {
10
- cwd: path,
11
- stdin: 'ignore',
12
- });
13
- }
14
-
15
- return execa('npm', args, { cwd: path, stdin: 'ignore' });
16
- }
17
-
18
- function runInstall(path) {
19
- return runYarn(path, ['install']);
20
- }
21
-
22
- function runStart(path) {
23
- return runYarn(path, ['run', 'start']);
24
- }
25
-
26
- function runInit(path, args = []) {
27
- if (!hasYarn()) {
28
- args.unshift('--');
29
- }
30
- console.log('run init', args);
31
- return runYarn(path, ['run', 'nocobase', 'init', ...args]);
32
- }
33
-
34
- module.exports = {
35
- runInit,
36
- runStart,
37
- runInstall,
38
- hasYarn,
39
- };