@nocobase/cli 1.7.0-beta.4 → 1.7.0-beta.6

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nocobase/cli",
3
- "version": "1.7.0-beta.4",
3
+ "version": "1.7.0-beta.6",
4
4
  "description": "",
5
5
  "license": "AGPL-3.0",
6
6
  "main": "./src/index.js",
@@ -8,7 +8,7 @@
8
8
  "nocobase": "./bin/index.js"
9
9
  },
10
10
  "dependencies": {
11
- "@nocobase/app": "1.7.0-beta.4",
11
+ "@nocobase/app": "1.7.0-beta.6",
12
12
  "@types/fs-extra": "^11.0.1",
13
13
  "@umijs/utils": "3.5.20",
14
14
  "chalk": "^4.1.1",
@@ -25,12 +25,12 @@
25
25
  "tsx": "^4.19.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@nocobase/devtools": "1.7.0-beta.4"
28
+ "@nocobase/devtools": "1.7.0-beta.6"
29
29
  },
30
30
  "repository": {
31
31
  "type": "git",
32
32
  "url": "git+https://github.com/nocobase/nocobase.git",
33
33
  "directory": "packages/core/cli"
34
34
  },
35
- "gitHead": "bf1fbeef48ab69fb3d417f4d75bf3f22031e29f8"
35
+ "gitHead": "4f1d3fa20b508322cc063b424588123e4ecc1c5f"
36
36
  }
@@ -18,6 +18,7 @@ module.exports = (cli) => {
18
18
  generateAppDir();
19
19
  require('./global')(cli);
20
20
  require('./create-nginx-conf')(cli);
21
+ require('./locale')(cli);
21
22
  require('./build')(cli);
22
23
  require('./tar')(cli);
23
24
  require('./dev')(cli);
@@ -0,0 +1,122 @@
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 methods = [
11
+ 'atX0SecondsPastTheMinuteGt20',
12
+ 'atX0MinutesPastTheHourGt20',
13
+ 'commaMonthX0ThroughMonthX1',
14
+ 'commaYearX0ThroughYearX1',
15
+ 'use24HourTimeFormatByDefault',
16
+ 'anErrorOccuredWhenGeneratingTheExpressionD',
17
+ 'everyMinute',
18
+ 'everyHour',
19
+ 'atSpace',
20
+ 'everyMinuteBetweenX0AndX1',
21
+ 'at',
22
+ 'spaceAnd',
23
+ 'everySecond',
24
+ 'everyX0Seconds',
25
+ 'secondsX0ThroughX1PastTheMinute',
26
+ 'atX0SecondsPastTheMinute',
27
+ 'everyX0Minutes',
28
+ 'minutesX0ThroughX1PastTheHour',
29
+ 'atX0MinutesPastTheHour',
30
+ 'everyX0Hours',
31
+ 'betweenX0AndX1',
32
+ 'atX0',
33
+ 'commaEveryDay',
34
+ 'commaEveryX0DaysOfTheWeek',
35
+ 'commaX0ThroughX1',
36
+ 'commaAndX0ThroughX1',
37
+ 'first',
38
+ 'second',
39
+ 'third',
40
+ 'fourth',
41
+ 'fifth',
42
+ 'commaOnThe',
43
+ 'spaceX0OfTheMonth',
44
+ 'lastDay',
45
+ 'commaOnTheLastX0OfTheMonth',
46
+ 'commaOnlyOnX0',
47
+ 'commaAndOnX0',
48
+ 'commaEveryX0Months',
49
+ 'commaOnlyInX0',
50
+ 'commaOnTheLastDayOfTheMonth',
51
+ 'commaOnTheLastWeekdayOfTheMonth',
52
+ 'commaDaysBeforeTheLastDayOfTheMonth',
53
+ 'firstWeekday',
54
+ 'weekdayNearestDayX0',
55
+ 'commaOnTheX0OfTheMonth',
56
+ 'commaEveryX0Days',
57
+ 'commaBetweenDayX0AndX1OfTheMonth',
58
+ 'commaOnDayX0OfTheMonth',
59
+ 'commaEveryHour',
60
+ 'commaEveryX0Years',
61
+ 'commaStartingX0',
62
+ 'daysOfTheWeek',
63
+ 'monthsOfTheYear',
64
+ ];
65
+
66
+ const langs = {
67
+ af: 'af',
68
+ ar: 'ar',
69
+ be: 'be',
70
+ ca: 'ca',
71
+ cs: 'cs',
72
+ da: 'da',
73
+ de: 'de',
74
+ 'en-US': 'en',
75
+ es: 'es',
76
+ fa: 'fa',
77
+ fi: 'fi',
78
+ fr: 'fr',
79
+ he: 'he',
80
+ hu: 'hu',
81
+ id: 'id',
82
+ it: 'it',
83
+ 'ja-JP': 'ja',
84
+ ko: 'ko',
85
+ nb: 'nb',
86
+ nl: 'nl',
87
+ pl: 'pl',
88
+ pt_BR: 'pt_BR',
89
+ pt_PT: 'pt_PT',
90
+ ro: 'ro',
91
+ 'ru-RU': 'ru',
92
+ sk: 'sk',
93
+ sl: 'sl',
94
+ sv: 'sv',
95
+ sw: 'sw',
96
+ 'th-TH': 'th',
97
+ 'tr-TR': 'tr',
98
+ uk: 'uk',
99
+ 'zh-CN': 'zh_CN',
100
+ 'zh-TW': 'zh_TW',
101
+ };
102
+
103
+ exports.getCronstrueLocale = (lang) => {
104
+ const lng = langs[lang] || 'en';
105
+ const Locale = require(`cronstrue/locales/${lng}`);
106
+ let locale;
107
+ if (Locale?.default) {
108
+ locale = Locale.default.locales[lng];
109
+ } else {
110
+ const L = Locale[lng];
111
+ locale = new L();
112
+ }
113
+ const items = {};
114
+ for (const method of methods) {
115
+ try {
116
+ items[method] = locale[method]();
117
+ } catch (error) {
118
+ // empty
119
+ }
120
+ }
121
+ return items;
122
+ };
@@ -0,0 +1,75 @@
1
+ {
2
+ "everyText": "every",
3
+ "emptyMonths": "every month",
4
+ "emptyMonthDays": "every day of the month",
5
+ "emptyMonthDaysShort": "day of the month",
6
+ "emptyWeekDays": "every day of the week",
7
+ "emptyWeekDaysShort": "day of the week",
8
+ "emptyHours": "every hour",
9
+ "emptyMinutes": "every minute",
10
+ "emptyMinutesForHourPeriod": "every",
11
+ "yearOption": "year",
12
+ "monthOption": "month",
13
+ "weekOption": "week",
14
+ "dayOption": "day",
15
+ "hourOption": "hour",
16
+ "minuteOption": "minute",
17
+ "rebootOption": "reboot",
18
+ "prefixPeriod": "Every",
19
+ "prefixMonths": "in",
20
+ "prefixMonthDays": "on",
21
+ "prefixWeekDays": "on",
22
+ "prefixWeekDaysForMonthAndYearPeriod": "and",
23
+ "prefixHours": "at",
24
+ "prefixMinutes": ":",
25
+ "prefixMinutesForHourPeriod": "at",
26
+ "suffixMinutesForHourPeriod": "minute(s)",
27
+ "errorInvalidCron": "Invalid cron expression",
28
+ "clearButtonText": "Clear",
29
+ "weekDays": [
30
+ "Sunday",
31
+ "Monday",
32
+ "Tuesday",
33
+ "Wednesday",
34
+ "Thursday",
35
+ "Friday",
36
+ "Saturday"
37
+ ],
38
+ "months": [
39
+ "January",
40
+ "February",
41
+ "March",
42
+ "April",
43
+ "May",
44
+ "June",
45
+ "July",
46
+ "August",
47
+ "September",
48
+ "October",
49
+ "November",
50
+ "December"
51
+ ],
52
+ "altWeekDays": [
53
+ "SUN",
54
+ "MON",
55
+ "TUE",
56
+ "WED",
57
+ "THU",
58
+ "FRI",
59
+ "SAT"
60
+ ],
61
+ "altMonths": [
62
+ "JAN",
63
+ "FEB",
64
+ "MAR",
65
+ "APR",
66
+ "MAY",
67
+ "JUN",
68
+ "JUL",
69
+ "AUG",
70
+ "SEP",
71
+ "OCT",
72
+ "NOV",
73
+ "DEC"
74
+ ]
75
+ }
@@ -0,0 +1,17 @@
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
+ exports.getReactJsCron = (lang) => {
11
+ const langs = {
12
+ 'en-US': require('./en-US.json'),
13
+ 'zh-CN': require('./zh-CN.json'),
14
+ 'z-TW': require('./zh-TW.json'),
15
+ }
16
+ return langs[lang] || langs['en-US'];
17
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "everyText": "每",
3
+ "emptyMonths": "每月",
4
+ "emptyMonthDays": "每日(月)",
5
+ "emptyMonthDaysShort": "每日",
6
+ "emptyWeekDays": "每天(周)",
7
+ "emptyWeekDaysShort": "每天(周)",
8
+ "emptyHours": "每小时",
9
+ "emptyMinutes": "每分钟",
10
+ "emptyMinutesForHourPeriod": "每",
11
+ "yearOption": "年",
12
+ "monthOption": "月",
13
+ "weekOption": "周",
14
+ "dayOption": "天",
15
+ "hourOption": "小时",
16
+ "minuteOption": "分钟",
17
+ "rebootOption": "重启",
18
+ "prefixPeriod": "每",
19
+ "prefixMonths": "的",
20
+ "prefixMonthDays": "的",
21
+ "prefixWeekDays": "的",
22
+ "prefixWeekDaysForMonthAndYearPeriod": "或者",
23
+ "prefixHours": "的",
24
+ "prefixMinutes": ":",
25
+ "prefixMinutesForHourPeriod": "的",
26
+ "suffixMinutesForHourPeriod": "分钟",
27
+ "errorInvalidCron": "不符合 cron 规则的表达式",
28
+ "clearButtonText": "清空",
29
+ "weekDays": ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
30
+ "months": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
31
+ "altWeekDays": ["周日", "周一", "周二", "周三", "周四", "周五", "周六"],
32
+ "altMonths": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
33
+ }
@@ -0,0 +1,33 @@
1
+ {
2
+ "everyText": "每",
3
+ "emptyMonths": "每月",
4
+ "emptyMonthDays": "每日(月)",
5
+ "emptyMonthDaysShort": "每日",
6
+ "emptyWeekDays": "每天(週)",
7
+ "emptyWeekDaysShort": "每天(週)",
8
+ "emptyHours": "每小時",
9
+ "emptyMinutes": "每分鐘",
10
+ "emptyMinutesForHourPeriod": "每",
11
+ "yearOption": "年",
12
+ "monthOption": "月",
13
+ "weekOption": "週",
14
+ "dayOption": "天",
15
+ "hourOption": "小時",
16
+ "minuteOption": "分鐘",
17
+ "rebootOption": "重啟",
18
+ "prefixPeriod": "每",
19
+ "prefixMonths": "的",
20
+ "prefixMonthDays": "的",
21
+ "prefixWeekDays": "的",
22
+ "prefixWeekDaysForMonthAndYearPeriod": "或者",
23
+ "prefixHours": "的",
24
+ "prefixMinutes": ":",
25
+ "prefixMinutesForHourPeriod": "的",
26
+ "suffixMinutesForHourPeriod": "分鐘",
27
+ "errorInvalidCron": "不符合 cron 規則的表示式",
28
+ "clearButtonText": "清空",
29
+ "weekDays": ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
30
+ "months": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
31
+ "altWeekDays": ["週日", "週一", "週二", "週三", "週四", "週五", "週六"],
32
+ "altMonths": ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"]
33
+ }
@@ -0,0 +1,81 @@
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 fg = require('fast-glob');
12
+ const fs = require('fs-extra');
13
+ const path = require('path');
14
+ const _ = require('lodash');
15
+ const deepmerge = require('deepmerge');
16
+ const { getCronstrueLocale } = require('./locale/cronstrue');
17
+ const { getReactJsCron } = require('./locale/react-js-cron');
18
+
19
+ function sortJSON(json) {
20
+ if (Array.isArray(json)) {
21
+ return json.map(sortJSON);
22
+ } else if (typeof json === 'object' && json !== null) {
23
+ const sortedKeys = Object.keys(json).sort();
24
+ const sortedObject = {};
25
+ sortedKeys.forEach((key) => {
26
+ sortedObject[key] = sortJSON(json[key]);
27
+ });
28
+ return sortedObject;
29
+ }
30
+ return json;
31
+ }
32
+
33
+ /**
34
+ *
35
+ * @param {Command} cli
36
+ */
37
+ module.exports = (cli) => {
38
+ const locale = cli.command('locale');
39
+ locale.command('generate').action(async (options) => {
40
+ const cwd = path.resolve(process.cwd(), 'node_modules', '@nocobase');
41
+ const files = await fg('./*/src/locale/*.json', {
42
+ cwd,
43
+ });
44
+ let locales = {};
45
+ await fs.mkdirp(path.resolve(process.cwd(), 'storage/locales'));
46
+ for (const file of files) {
47
+ const locale = path.basename(file, '.json');
48
+ const pkg = path.basename(path.dirname(path.dirname(path.dirname(file))));
49
+ _.set(locales, [locale.replace(/_/g, '-'), `@nocobase/${pkg}`], await fs.readJSON(path.resolve(cwd, file)));
50
+ if (locale.includes('_')) {
51
+ await fs.rename(
52
+ path.resolve(cwd, file),
53
+ path.resolve(cwd, path.dirname(file), `${locale.replace(/_/g, '-')}.json`),
54
+ );
55
+ }
56
+ }
57
+ const zhCN = locales['zh-CN'];
58
+ const enUS = locales['en-US'];
59
+ for (const key1 in zhCN) {
60
+ for (const key2 in zhCN[key1]) {
61
+ if (!_.get(enUS, [key1, key2])) {
62
+ _.set(enUS, [key1, key2], key2);
63
+ }
64
+ }
65
+ }
66
+ for (const locale of Object.keys(locales)) {
67
+ locales[locale] = deepmerge(enUS, locales[locale]);
68
+ locales[locale]['cronstrue'] = getCronstrueLocale(locale);
69
+ locales[locale]['react-js-cron'] = getReactJsCron(locale);
70
+ }
71
+ locales = sortJSON(locales);
72
+ for (const locale of Object.keys(locales)) {
73
+ await fs.writeFile(
74
+ path.resolve(process.cwd(), 'storage/locales', `${locale}.json`),
75
+ JSON.stringify(sortJSON(locales[locale]), null, 2),
76
+ );
77
+ }
78
+ });
79
+
80
+ locale.command('sync').action(async (options) => {});
81
+ };