@nocobase/cli 2.1.0-beta.14 → 2.1.0-beta.16

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 (132) hide show
  1. package/LICENSE.txt +107 -0
  2. package/README.md +307 -63
  3. package/README.zh-CN.md +332 -0
  4. package/bin/run.cmd +3 -0
  5. package/bin/run.js +114 -0
  6. package/dist/commands/api/resource/create.js +15 -0
  7. package/dist/commands/api/resource/destroy.js +15 -0
  8. package/dist/commands/api/resource/get.js +15 -0
  9. package/dist/commands/api/resource/index.js +20 -0
  10. package/dist/commands/api/resource/list.js +16 -0
  11. package/dist/commands/api/resource/query.js +15 -0
  12. package/dist/commands/api/resource/update.js +15 -0
  13. package/dist/commands/build.js +57 -0
  14. package/dist/commands/db/logs.js +85 -0
  15. package/dist/commands/db/ps.js +60 -0
  16. package/dist/commands/db/shared.js +81 -0
  17. package/dist/commands/db/start.js +70 -0
  18. package/dist/commands/db/stop.js +70 -0
  19. package/dist/commands/dev.js +149 -0
  20. package/dist/commands/down.js +193 -0
  21. package/dist/commands/download.js +743 -0
  22. package/dist/commands/env/add.js +327 -0
  23. package/dist/commands/env/auth.js +62 -0
  24. package/dist/commands/env/list.js +41 -0
  25. package/dist/commands/env/remove.js +65 -0
  26. package/dist/commands/env/update.js +73 -0
  27. package/dist/commands/env/use.js +36 -0
  28. package/dist/commands/init.js +806 -0
  29. package/dist/commands/install.js +1840 -0
  30. package/dist/commands/logs.js +90 -0
  31. package/dist/commands/pm/disable.js +63 -0
  32. package/dist/commands/pm/enable.js +63 -0
  33. package/dist/commands/pm/list.js +54 -0
  34. package/dist/commands/prompts-stages.js +150 -0
  35. package/dist/commands/prompts-test.js +181 -0
  36. package/dist/commands/ps.js +116 -0
  37. package/dist/commands/scaffold/migration.js +38 -0
  38. package/dist/commands/scaffold/plugin.js +37 -0
  39. package/dist/commands/start.js +211 -0
  40. package/dist/commands/stop.js +90 -0
  41. package/dist/commands/upgrade.js +583 -0
  42. package/dist/generated/command-registry.js +133 -0
  43. package/dist/help/runtime-help.js +20 -0
  44. package/dist/lib/api-client.js +243 -0
  45. package/dist/lib/app-runtime.js +142 -0
  46. package/dist/lib/auth-store.js +241 -0
  47. package/dist/lib/bootstrap.js +387 -0
  48. package/dist/lib/build-config.js +10 -0
  49. package/dist/lib/cli-home.js +30 -0
  50. package/dist/lib/cli-locale.js +115 -0
  51. package/dist/lib/command-discovery.js +39 -0
  52. package/dist/lib/env-auth.js +872 -0
  53. package/dist/lib/generated-command.js +142 -0
  54. package/dist/lib/naming.js +70 -0
  55. package/dist/lib/openapi.js +62 -0
  56. package/dist/lib/post-processors.js +23 -0
  57. package/dist/lib/prompt-catalog.js +574 -0
  58. package/dist/lib/prompt-validators.js +185 -0
  59. package/dist/lib/prompt-web-ui.js +2061 -0
  60. package/dist/lib/resource-command.js +335 -0
  61. package/dist/lib/resource-request.js +104 -0
  62. package/dist/lib/run-npm.js +123 -0
  63. package/dist/lib/runtime-generator.js +419 -0
  64. package/dist/lib/runtime-store.js +56 -0
  65. package/dist/lib/ui.js +175 -0
  66. package/dist/locale/en-US.json +282 -0
  67. package/dist/locale/zh-CN.json +282 -0
  68. package/dist/post-processors/data-modeling.js +66 -0
  69. package/dist/post-processors/data-source-manager.js +114 -0
  70. package/dist/post-processors/index.js +19 -0
  71. package/nocobase-ctl.config.json +287 -0
  72. package/package.json +52 -25
  73. package/LICENSE +0 -201
  74. package/bin/index.js +0 -39
  75. package/nocobase.conf.tpl +0 -95
  76. package/src/cli.js +0 -19
  77. package/src/commands/benchmark.js +0 -73
  78. package/src/commands/build.js +0 -49
  79. package/src/commands/clean.js +0 -30
  80. package/src/commands/client.js +0 -166
  81. package/src/commands/create-nginx-conf.js +0 -37
  82. package/src/commands/create-plugin.js +0 -33
  83. package/src/commands/dev.js +0 -200
  84. package/src/commands/doc.js +0 -76
  85. package/src/commands/e2e.js +0 -265
  86. package/src/commands/global.js +0 -43
  87. package/src/commands/index.js +0 -45
  88. package/src/commands/instance-id.js +0 -47
  89. package/src/commands/locale/cronstrue.js +0 -122
  90. package/src/commands/locale/react-js-cron/en-US.json +0 -75
  91. package/src/commands/locale/react-js-cron/index.js +0 -17
  92. package/src/commands/locale/react-js-cron/zh-CN.json +0 -33
  93. package/src/commands/locale/react-js-cron/zh-TW.json +0 -33
  94. package/src/commands/locale.js +0 -81
  95. package/src/commands/p-test.js +0 -88
  96. package/src/commands/perf.js +0 -63
  97. package/src/commands/pkg.js +0 -321
  98. package/src/commands/pm2.js +0 -37
  99. package/src/commands/postinstall.js +0 -88
  100. package/src/commands/start.js +0 -148
  101. package/src/commands/tar.js +0 -36
  102. package/src/commands/test-coverage.js +0 -55
  103. package/src/commands/test.js +0 -107
  104. package/src/commands/umi.js +0 -33
  105. package/src/commands/update-deps.js +0 -72
  106. package/src/commands/upgrade.js +0 -47
  107. package/src/commands/view-license-key.js +0 -44
  108. package/src/index.js +0 -14
  109. package/src/license.js +0 -76
  110. package/src/logger.js +0 -75
  111. package/src/plugin-generator.js +0 -80
  112. package/src/util.js +0 -517
  113. package/templates/bundle-status.html +0 -338
  114. package/templates/create-app-package.json +0 -39
  115. package/templates/plugin/.npmignore.tpl +0 -2
  116. package/templates/plugin/README.md.tpl +0 -1
  117. package/templates/plugin/client.d.ts +0 -2
  118. package/templates/plugin/client.js +0 -1
  119. package/templates/plugin/package.json.tpl +0 -11
  120. package/templates/plugin/server.d.ts +0 -2
  121. package/templates/plugin/server.js +0 -1
  122. package/templates/plugin/src/client/client.d.ts +0 -249
  123. package/templates/plugin/src/client/index.tsx.tpl +0 -1
  124. package/templates/plugin/src/client/locale.ts +0 -21
  125. package/templates/plugin/src/client/models/index.ts +0 -12
  126. package/templates/plugin/src/client/plugin.tsx.tpl +0 -10
  127. package/templates/plugin/src/index.ts +0 -2
  128. package/templates/plugin/src/locale/en-US.json +0 -1
  129. package/templates/plugin/src/locale/zh-CN.json +0 -1
  130. package/templates/plugin/src/server/collections/.gitkeep +0 -0
  131. package/templates/plugin/src/server/index.ts.tpl +0 -1
  132. package/templates/plugin/src/server/plugin.ts.tpl +0 -19
@@ -1,107 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const { Command } = require('commander');
11
- const { run, checkDBDialect } = require('../util');
12
- const path = require('path');
13
-
14
- /**
15
- *
16
- * @param {String} name
17
- * @param {Command} cli
18
- */
19
- function addTestCommand(name, cli) {
20
- return cli
21
- .command(name)
22
- .option('-w, --watch')
23
- .option('--run')
24
- .option('--allowOnly')
25
- .option('--bail')
26
- .option('--coverage')
27
- .option('-h, --help')
28
- .option('--single-thread [singleThread]')
29
- .arguments('[paths...]')
30
- .allowUnknownOption()
31
- .action(async (paths, opts) => {
32
- checkDBDialect();
33
- if (name === 'test:server') {
34
- process.env.TEST_ENV = 'server-side';
35
- } else if (name === 'test:client') {
36
- process.env.TEST_ENV = 'client-side';
37
- }
38
- if (opts.server) {
39
- process.env.TEST_ENV = 'server-side';
40
- process.argv.splice(process.argv.indexOf('--server'), 1);
41
- }
42
-
43
- if (opts.client) {
44
- process.env.TEST_ENV = 'client-side';
45
- process.argv.splice(process.argv.indexOf('--client'), 1);
46
- }
47
-
48
- process.env.NODE_ENV = 'test';
49
-
50
- if (!opts.watch && !opts.run) {
51
- process.argv.push('--run');
52
- }
53
-
54
- const first = paths?.[0];
55
- if (!process.env.TEST_ENV && first) {
56
- const key = first.split(path.sep).join('/');
57
- if (key.includes('/client/') || key.includes('/client-v2/') || key.includes('/flow-engine/')) {
58
- process.env.TEST_ENV = 'client-side';
59
- } else {
60
- process.env.TEST_ENV = 'server-side';
61
- }
62
- }
63
-
64
- if (process.env.TEST_ENV === 'server-side' && opts.singleThread !== 'false') {
65
- process.argv.push('--poolOptions.threads.singleThread=true');
66
- }
67
-
68
- if (opts.singleThread === 'false') {
69
- process.argv.splice(process.argv.indexOf('--single-thread=false'), 1);
70
- }
71
-
72
- const cliArgs = ['--max_old_space_size=14096', './node_modules/vitest/vitest.mjs', ...process.argv.slice(3)];
73
-
74
- if (process.argv.includes('-h') || process.argv.includes('--help')) {
75
- await run('node', cliArgs);
76
- return;
77
- }
78
-
79
- if (process.env.TEST_ENV) {
80
- console.log('process.env.TEST_ENV', process.env.TEST_ENV, cliArgs);
81
- await run('node', cliArgs);
82
- } else {
83
- await Promise.all([
84
- run('node', cliArgs, {
85
- env: {
86
- TEST_ENV: 'client-side',
87
- },
88
- }),
89
- run('node', cliArgs, {
90
- env: {
91
- TEST_ENV: 'server-side',
92
- },
93
- }),
94
- ]);
95
- }
96
- });
97
- }
98
-
99
- /**
100
- *
101
- * @param {Command} cli
102
- */
103
- module.exports = (cli) => {
104
- addTestCommand('test:server', cli);
105
- addTestCommand('test:client', cli);
106
- addTestCommand('test', cli).option('--client').option('--server');
107
- };
@@ -1,33 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { Command } = require('commander');
12
- const { run, isDev } = require('../util');
13
-
14
- /**
15
- *
16
- * @param {Command} cli
17
- */
18
- module.exports = (cli) => {
19
- const { APP_PACKAGE_ROOT } = process.env;
20
- cli
21
- .command('umi')
22
- .allowUnknownOption()
23
- .action(() => {
24
- if (!isDev()) {
25
- return;
26
- }
27
- run('umi', process.argv.slice(3), {
28
- env: {
29
- APP_ROOT: `${APP_PACKAGE_ROOT}/client`,
30
- },
31
- });
32
- });
33
- };
@@ -1,72 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { Command } = require('commander');
12
- const { resolve } = require('path');
13
- const { run, promptForTs, runAppCommand, hasCorePackages, downloadPro, hasTsNode, checkDBDialect } = require('../util');
14
- const { existsSync, rmSync } = require('fs');
15
- const { readJSON, writeJSON } = require('fs-extra');
16
- const deepmerge = require('deepmerge');
17
-
18
- const rmAppDir = () => {
19
- // If ts-node is not installed, do not do the following
20
- const appDevDir = resolve(process.cwd(), './storage/.app-dev');
21
- if (existsSync(appDevDir)) {
22
- rmSync(appDevDir, { recursive: true, force: true });
23
- }
24
- };
25
-
26
- /**
27
- *
28
- * @param {Command} cli
29
- */
30
- module.exports = (cli) => {
31
- cli
32
- .command('update-deps')
33
- .option('--force')
34
- .allowUnknownOption()
35
- .action(async (options) => {
36
- if (hasCorePackages() || !hasTsNode()) {
37
- await downloadPro();
38
- return;
39
- }
40
- const pkg = require('../../package.json');
41
- let distTag = 'latest';
42
- if (pkg.version.includes('alpha')) {
43
- distTag = 'alpha';
44
- } else if (pkg.version.includes('beta')) {
45
- distTag = 'beta';
46
- }
47
- const { stdout } = await run('npm', ['info', `@nocobase/cli@${distTag}`, 'version'], {
48
- stdio: 'pipe',
49
- });
50
- if (!options.force && pkg.version === stdout) {
51
- await downloadPro();
52
- rmAppDir();
53
- return;
54
- }
55
- const descPath = resolve(process.cwd(), 'package.json');
56
- const descJson = await readJSON(descPath, 'utf8');
57
- const sourcePath = resolve(__dirname, '../../templates/create-app-package.json');
58
- const sourceJson = await readJSON(sourcePath, 'utf8');
59
- if (descJson['dependencies']?.['@nocobase/cli']) {
60
- descJson['dependencies']['@nocobase/cli'] = stdout;
61
- }
62
- if (descJson['devDependencies']?.['@nocobase/devtools']) {
63
- descJson['devDependencies']['@nocobase/devtools'] = stdout;
64
- }
65
- descJson['resolutions'] = sourceJson['resolutions'];
66
- const json = deepmerge(descJson, sourceJson);
67
- await writeJSON(descPath, json, { spaces: 2, encoding: 'utf8' });
68
- await run('yarn', ['install']);
69
- await downloadPro();
70
- rmAppDir();
71
- });
72
- };
@@ -1,47 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { Command } = require('commander');
12
- const { resolve } = require('path');
13
- const { run, promptForTs, runAppCommand, hasCorePackages, downloadPro, hasTsNode, checkDBDialect } = require('../util');
14
- const { existsSync, rmSync } = require('fs');
15
- const { readJSON, writeJSON } = require('fs-extra');
16
- const deepmerge = require('deepmerge');
17
-
18
- async function updatePackage() {
19
- const sourcePath = resolve(__dirname, '../../templates/create-app-package.json');
20
- const descPath = resolve(process.cwd(), 'package.json');
21
- const sourceJson = await readJSON(sourcePath, 'utf8');
22
- const descJson = await readJSON(descPath, 'utf8');
23
- const json = deepmerge(descJson, sourceJson);
24
- await writeJSON(descPath, json, { spaces: 2, encoding: 'utf8' });
25
- }
26
-
27
- /**
28
- *
29
- * @param {Command} cli
30
- */
31
- module.exports = (cli) => {
32
- cli
33
- .command('upgrade')
34
- .allowUnknownOption()
35
- .option('--raw')
36
- .option('--next')
37
- .option('-S|--skip-code-update')
38
- .action(async (options) => {
39
- checkDBDialect();
40
- if (options.skipCodeUpdate) {
41
- await runAppCommand('upgrade');
42
- } else {
43
- await run('nocobase', ['update-deps']);
44
- await run('nocobase', ['upgrade', '--skip-code-update']);
45
- }
46
- });
47
- };
@@ -1,44 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { Command } = require('commander');
12
- const { keyDecrypt } = require('@nocobase/license-kit');
13
- const path = require('path');
14
- const fs = require('fs');
15
-
16
- /**
17
- *
18
- * @param {Command} cli
19
- */
20
- module.exports = (cli) => {
21
- cli
22
- .command('view-license-key')
23
- .description('View License Key')
24
- .action(async (options) => {
25
- const dir = path.resolve(process.cwd(), 'storage/.license');
26
- const filePath = path.resolve(dir, 'license-key');
27
- if (!fs.existsSync(filePath)) {
28
- console.log('License key not found at ' + filePath);
29
- return;
30
- }
31
- const key = fs.readFileSync(filePath, 'utf-8');
32
- let keyDataStr;
33
- try {
34
- keyDataStr = keyDecrypt(key);
35
- } catch (e) {
36
- console.log('License key decrypt failed', e);
37
- return;
38
- }
39
- const keyData = JSON.parse(keyDataStr);
40
- const { accessKeyId, accessKeySecret } = keyData;
41
- console.log(chalk.greenBright(`Access Key ID: ${accessKeyId}`));
42
- console.log(chalk.greenBright(`Access Key Secret: ${accessKeySecret}`));
43
- });
44
- };
package/src/index.js DELETED
@@ -1,14 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const util = require('./util');
11
-
12
- module.exports = {
13
- ...util,
14
- };
package/src/license.js DELETED
@@ -1,76 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { resolve } = require('path');
12
- const fs = require('fs-extra');
13
- const { keyDecrypt, getEnvAsync } = require('@nocobase/license-kit');
14
- const { isEnvMatch } = require('@nocobase/plugin-license/utils/env');
15
- const { logger } = require('./logger');
16
- const { pick } = require('lodash');
17
-
18
- exports.getAccessKeyPair = async function () {
19
- const keyFile = resolve(process.cwd(), 'storage/.license/license-key');
20
- if (!fs.existsSync(keyFile)) {
21
- logger.info('License key not found');
22
- return {};
23
- }
24
- logger.info('License key found');
25
- let keyData = {};
26
- try {
27
- const str = fs.readFileSync(keyFile, 'utf-8');
28
- const keyDataStr = keyDecrypt(str);
29
- keyData = JSON.parse(keyDataStr);
30
- } catch (error) {
31
- showLicenseInfo(LicenseKeyError.parseFailed);
32
- throw new Error(LicenseKeyError.parseFailed.title);
33
- }
34
- const env = await getEnvAsync();
35
- const isEnvMatched = await isEnvMatch(env, keyData);
36
- if (!isEnvMatched) {
37
- showLicenseInfo({
38
- ...LicenseKeyError.notMatch,
39
- env,
40
- });
41
- throw new Error(LicenseKeyError.notMatch.title);
42
- }
43
- const { accessKeyId, accessKeySecret } = keyData;
44
- return { accessKeyId, accessKeySecret };
45
- };
46
-
47
- const LicenseKeyError = {
48
- notExist: {
49
- title: 'License key not found',
50
- content:
51
- 'Please go to the license settings page to obtain the Instance ID for the current environment, and then generate the license key on the service platform.',
52
- },
53
- parseFailed: {
54
- title: 'Invalid license key format',
55
- content: 'Please check your license key, or regenerate the license key on the service platform.',
56
- },
57
- notMatch: {
58
- title: 'License key not match current environment',
59
- content:
60
- 'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
61
- },
62
- notValid: {
63
- title: 'Invalid license key',
64
- content:
65
- 'Please go to the license settings page to obtain the Instance ID for the current environment, and then regenerate the license key on the service platform.',
66
- },
67
- };
68
-
69
- exports.LicenseKeyError = LicenseKeyError;
70
-
71
- function showLicenseInfo({ title, content, env }) {
72
- logger.error(title + '. ' + content);
73
- logger.error('Current environment', pick(env, ['sys', 'osVer', 'db']));
74
- }
75
-
76
- exports.showLicenseInfo = showLicenseInfo;
package/src/logger.js DELETED
@@ -1,75 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const fs = require('fs');
11
- const path = require('path');
12
- const winston = require('winston');
13
- require('winston-daily-rotate-file');
14
-
15
- function ensureDir(dir) {
16
- if (!fs.existsSync(dir)) {
17
- fs.mkdirSync(dir, { recursive: true });
18
- }
19
- }
20
-
21
- function createSystemLogger({ dirname, filename, defaultMeta = {} }) {
22
- ensureDir(dirname);
23
-
24
- const commonFormat = winston.format.combine(
25
- winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
26
- winston.format.printf((info) => {
27
- const meta = info.meta ? JSON.stringify(info.meta) : '';
28
- return `${info.timestamp} [${info.level}] ${info.message} ${meta}`;
29
- }),
30
- );
31
-
32
- const consoleFormat = winston.format.combine(winston.format.colorize(), commonFormat);
33
-
34
- const fileTransport = new winston.transports.DailyRotateFile({
35
- dirname,
36
- filename: `${filename}_%DATE%.log`,
37
- datePattern: 'YYYY-MM-DD',
38
- zippedArchive: false,
39
- format: commonFormat,
40
- });
41
-
42
- const consoleTransport = new winston.transports.Console({
43
- format: consoleFormat,
44
- });
45
-
46
- const logger = winston.createLogger({
47
- level: 'info',
48
- transports: [consoleTransport, fileTransport],
49
- defaultMeta,
50
- });
51
-
52
- const wrap = (level) => (message, meta) => {
53
- logger.log({ level, message, meta });
54
- return logger;
55
- };
56
-
57
- return {
58
- info: wrap('info'),
59
- warn: wrap('warn'),
60
- error: wrap('error'),
61
- };
62
- }
63
-
64
- const getLoggerFilePath = (...paths) => {
65
- return path.resolve(process.env.LOGGER_BASE_PATH || path.resolve(process.cwd(), 'storage', 'logs'), ...paths);
66
- };
67
-
68
- const logger = createSystemLogger({
69
- dirname: getLoggerFilePath('main'),
70
- filename: 'system',
71
- });
72
-
73
- module.exports = {
74
- logger,
75
- };
@@ -1,80 +0,0 @@
1
- /**
2
- * This file is part of the NocoBase (R) project.
3
- * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
- * Authors: NocoBase Team.
5
- *
6
- * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
- * For more information, please refer to: https://www.nocobase.com/agreement.
8
- */
9
-
10
- const chalk = require('chalk');
11
- const { existsSync } = require('fs');
12
- const { join, resolve } = require('path');
13
- const { Generator } = require('@umijs/utils');
14
- const { readFile, writeFile } = require('fs').promises;
15
- const { genTsConfigPaths } = require('./util');
16
-
17
- const execa = require('execa');
18
-
19
- function camelize(str) {
20
- return str.trim().replace(/[-_\s]+(.)?/g, (match, c) => c.toUpperCase());
21
- }
22
-
23
- function capitalize(string) {
24
- return string.charAt(0).toUpperCase() + string.slice(1);
25
- }
26
-
27
- async function getProjectName() {
28
- const content = await readFile(resolve(process.cwd(), 'package.json'), 'utf-8');
29
- const json = JSON.parse(content);
30
- return json.name;
31
- }
32
-
33
- async function getProjectVersion() {
34
- const content = await readFile(resolve(process.cwd(), 'lerna.json'), 'utf-8');
35
- const json = JSON.parse(content);
36
- return json.version || '0.1.0';
37
- }
38
-
39
- class PluginGenerator extends Generator {
40
- constructor(options) {
41
- const { log, context = {}, ...opts } = options;
42
- super(opts);
43
- this.context = context;
44
- this.log = log || console.log;
45
- }
46
-
47
- async getContext() {
48
- const { name } = this.context;
49
- const nocobaseVersion = require('@nocobase/server/package.json').version;
50
- const packageVersion = await getProjectVersion();
51
- return {
52
- ...this.context,
53
- packageName: name,
54
- packageVersion,
55
- nocobaseVersion,
56
- pascalCaseName: capitalize(camelize(name.split('/').pop())),
57
- };
58
- }
59
-
60
- async writing() {
61
- const { name } = this.context;
62
- const target = resolve(process.cwd(), 'packages/plugins/', name);
63
- if (existsSync(target)) {
64
- this.log(chalk.red(`[${name}] plugin already exists.`));
65
- return;
66
- }
67
- this.log('Creating plugin');
68
- this.copyDirectory({
69
- target,
70
- context: await this.getContext(),
71
- path: join(__dirname, '../templates/plugin'),
72
- });
73
- this.log('');
74
- genTsConfigPaths();
75
- execa.sync('yarn', ['postinstall'], { shell: true, stdio: 'inherit' });
76
- this.log(`The plugin folder is in ${chalk.green(`packages/plugins/${name}`)}`);
77
- }
78
- }
79
-
80
- exports.PluginGenerator = PluginGenerator;