esa-cli 0.0.2-beta.0 → 0.0.2-beta.10

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.
@@ -9,43 +9,20 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import fs from 'fs-extra';
11
11
  import path from 'path';
12
+ import inquirer from 'inquirer';
13
+ import { exit } from 'process';
12
14
  import Template from '../../libs/templates/index.js';
13
15
  import { installGit } from '../../libs/git/index.js';
14
- import { descriptionInput } from '../../components/descriptionInput.js';
16
+ import multiLevelSelect from '../../components/mutiLevelSelect.js';
15
17
  import { generateConfigFile, getCliConfig, getProjectConfig, getTemplatesConfig, templateHubPath, updateProjectConfigFile } from '../../utils/fileUtils/index.js';
16
18
  import t from '../../i18n/index.js';
17
19
  import logger from '../../libs/logger.js';
18
- import SelectItems from '../../components/selectInput.js';
19
20
  import { quickDeploy } from '../deploy/index.js';
20
- import chalk from 'chalk';
21
21
  import { ApiService } from '../../libs/apiService.js';
22
- import { exit } from 'process';
23
22
  import { checkRoutineExist } from '../../utils/checkIsRoutineCreated.js';
24
- import { execSync } from 'child_process';
25
- import MultiLevelSelect from '../../components/mutiLevelSelect.js';
26
- import { getDirName } from '../../utils/fileUtils/base.js';
27
- import { yesNoPromptAndExecute } from '../deploy/helper.js';
28
23
  import { checkIsLoginSuccess } from '../utils.js';
29
- export const getTemplateInstances = (templateHubPath) => {
30
- return fs
31
- .readdirSync(templateHubPath)
32
- .filter((item) => {
33
- const itemPath = path.join(templateHubPath, item);
34
- return (fs.statSync(itemPath).isDirectory() &&
35
- !['.git', 'node_modules', 'lib'].includes(item));
36
- })
37
- .map((item) => {
38
- var _a;
39
- const projectPath = path.join(templateHubPath, item);
40
- const projectConfig = getProjectConfig(projectPath);
41
- const templateName = (_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '';
42
- return new Template(projectPath, templateName);
43
- });
44
- };
45
- const secondSetOfItems = [
46
- { label: 'Yes', value: 'yesInstall' },
47
- { label: 'No', value: 'noInstall' }
48
- ];
24
+ import chalk from 'chalk';
25
+ import { checkAndUpdatePackage, getTemplateInstances, preInstallDependencies, transferTemplatesToSelectItem } from './helper.js';
49
26
  const init = {
50
27
  command: 'init',
51
28
  describe: `📥 ${t('init_describe').d('Initialize a routine with a template')}`,
@@ -58,186 +35,141 @@ const init = {
58
35
  },
59
36
  handler: (argv) => __awaiter(void 0, void 0, void 0, function* () {
60
37
  yield handleInit(argv);
38
+ exit(0);
61
39
  })
62
40
  };
63
41
  export default init;
64
- export const preInstallDependencies = (targetPath) => __awaiter(void 0, void 0, void 0, function* () {
65
- const packageJsonPath = path.join(targetPath, 'package.json');
66
- if (fs.existsSync(packageJsonPath)) {
67
- logger.log(t('init_install_dependence').d('⌛️ Installing dependencies...'));
68
- execSync('npm install esa-template', {
69
- stdio: 'inherit',
70
- cwd: targetPath
71
- });
72
- logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
73
- logger.log(t('init_build_project').d('⌛️ Building project...'));
74
- execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
75
- logger.success(t('init_build_project_success').d('Project built successfully.'));
76
- }
77
- });
78
- export const transferTemplatesToSelectItem = (configs, templateInstanceList, lang) => {
79
- if (!configs)
80
- return [];
81
- return configs.map((config) => {
82
- var _a, _b;
83
- const name = config.Title_EN;
84
- const value = (_b = (_a = templateInstanceList.find((template) => {
85
- return name === template.title;
86
- })) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : '';
87
- const children = transferTemplatesToSelectItem(config.children, templateInstanceList);
88
- return {
89
- label: lang === 'en' ? config.Title_EN : config.Title_ZH,
90
- value: value,
91
- key: name,
92
- children
93
- };
94
- });
95
- };
96
- function checkAndUpdatePackage(packageName) {
42
+ export function promptProjectName() {
97
43
  return __awaiter(this, void 0, void 0, function* () {
98
- try {
99
- // 获取当前安装的版本
100
- const __dirname = getDirName(import.meta.url);
101
- const packageJsonPath = path.join(__dirname, '../../../');
102
- const versionInfo = execSync(`npm list ${packageName}`, {
103
- cwd: packageJsonPath
104
- }).toString();
105
- const match = versionInfo.match(new RegExp(`(${packageName})@([0-9.]+)`));
106
- const currentVersion = match ? match[2] : '';
107
- // 获取最新版本
108
- const latestVersion = execSync(`npm view ${packageName} version`)
109
- .toString()
110
- .trim();
111
- if (currentVersion !== latestVersion) {
112
- logger.log(t('display_current_esa_template_version').d(`Current esa-template version:`) +
113
- chalk.green(currentVersion) +
114
- ' ' +
115
- t('display_latest_esa_template_version').d(`Latest esa-template version:`) +
116
- chalk.green(latestVersion));
117
- yield yesNoPromptAndExecute(t('is_update_to_latest_version').d('Do you want to update templates to latest version?'), () => __awaiter(this, void 0, void 0, function* () {
118
- logger.log(t('updating_esa_template_to_latest_version', { packageName }).d(`Updating ${packageName} to the latest version...`));
119
- execSync(`rm -rf node_modules/${packageName} &&rm -rf package-lock.json &&npm install ${packageName}@latest`, {
120
- cwd: packageJsonPath
121
- });
122
- logger.log(t('updated_esa_template_to_latest_version', { packageName }).d(`${packageName} updated successfully`));
44
+ const { name } = yield inquirer.prompt([
45
+ {
46
+ type: 'input',
47
+ name: 'name',
48
+ message: `🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`,
49
+ validate: (input) => {
50
+ const regex = /^[a-z0-9-]{2,}$/;
51
+ if (!regex.test(input)) {
52
+ return t('init_name_error').d('Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.');
53
+ }
123
54
  return true;
124
- }));
55
+ }
125
56
  }
126
- else {
127
- logger.log(t('esa_template_is_latest_version', { packageName }).d(`${packageName} is latest.`));
57
+ ]);
58
+ return name;
59
+ });
60
+ }
61
+ export function prepareTemplateItems() {
62
+ var _a;
63
+ const templateInstanceList = getTemplateInstances(templateHubPath);
64
+ const templateConfig = getTemplatesConfig();
65
+ const cliConfig = getCliConfig();
66
+ const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
67
+ return transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
68
+ }
69
+ export function selectTemplate(items) {
70
+ return __awaiter(this, void 0, void 0, function* () {
71
+ const selectedTemplatePath = yield multiLevelSelect(items, 'Select a template:');
72
+ if (!selectedTemplatePath) {
73
+ logger.log(t('init_cancel').d('User canceled the operation.'));
74
+ return null;
75
+ }
76
+ return selectedTemplatePath;
77
+ });
78
+ }
79
+ export function initializeProject(selectedTemplatePath, name) {
80
+ return __awaiter(this, void 0, void 0, function* () {
81
+ const selectTemplate = new Template(selectedTemplatePath, name);
82
+ const projectConfig = getProjectConfig(selectedTemplatePath);
83
+ if (!projectConfig) {
84
+ logger.notInProject();
85
+ return null;
86
+ }
87
+ const targetPath = path.join(process.cwd(), name);
88
+ if (fs.existsSync(targetPath)) {
89
+ logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
90
+ return null;
91
+ }
92
+ yield fs.copy(selectedTemplatePath, targetPath);
93
+ projectConfig.name = name;
94
+ yield updateProjectConfigFile(projectConfig, targetPath);
95
+ yield preInstallDependencies(targetPath);
96
+ return { template: selectTemplate, targetPath };
97
+ });
98
+ }
99
+ export function handleGitInitialization(targetPath) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ const { initGit } = yield inquirer.prompt([
102
+ {
103
+ type: 'list',
104
+ name: 'initGit',
105
+ message: t('init_git').d('Do you want to init git in your project?'),
106
+ choices: ['Yes', 'No']
128
107
  }
108
+ ]);
109
+ if (initGit === 'Yes') {
110
+ installGit(targetPath);
111
+ }
112
+ else {
113
+ logger.log(t('init_skip_git').d('Git installation was skipped.'));
129
114
  }
130
- catch (error) {
131
- if (error instanceof Error) {
132
- logger.error('检测和更新包时发生错误,跳过更新模版');
115
+ });
116
+ }
117
+ export function handleDeployment(targetPath, projectConfig) {
118
+ return __awaiter(this, void 0, void 0, function* () {
119
+ var _a, _b, _c;
120
+ const isLoginSuccess = yield checkIsLoginSuccess();
121
+ if (!isLoginSuccess) {
122
+ logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
123
+ return;
124
+ }
125
+ const { deploy } = yield inquirer.prompt([
126
+ {
127
+ type: 'list',
128
+ name: 'deploy',
129
+ message: t('auto_deploy').d('Do you want to deploy your project?'),
130
+ choices: ['Yes', 'No']
133
131
  }
132
+ ]);
133
+ if (deploy === 'Yes') {
134
+ yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
135
+ yield quickDeploy(targetPath, projectConfig);
136
+ const service = yield ApiService.getInstance();
137
+ const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
138
+ const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
139
+ const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
140
+ logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
141
+ logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
134
142
  }
135
143
  });
136
144
  }
137
145
  export function handleInit(argv) {
138
146
  return __awaiter(this, void 0, void 0, function* () {
139
- var _a;
140
- const { config } = argv;
141
- // 更新template npm包
147
+ // Update the template package (currently commented out)
142
148
  yield checkAndUpdatePackage('esa-template');
143
- if (config !== undefined) {
149
+ // If config option is provided, generate config file and exit
150
+ const config = getCliConfig();
151
+ if (config === undefined) {
144
152
  yield generateConfigFile(String(config));
145
- return;
146
153
  }
147
- const name = yield descriptionInput(`🖊️ ${t('init_input_name').d('Enter the name of edgeRoutine:')}`, true);
148
- const regex = /^[a-z0-9-]{2,}$/;
149
- if (!regex.test(name)) {
150
- logger.error(t('init_name_error').d('Error: The project name must be at least 2 characters long and can only contain lowercase letters, numbers, and hyphens.'));
154
+ const name = yield promptProjectName();
155
+ const templateItems = prepareTemplateItems();
156
+ // Select a template
157
+ const selectedTemplatePath = yield selectTemplate(templateItems);
158
+ if (!selectedTemplatePath) {
151
159
  return;
152
160
  }
153
- const templateInstanceList = getTemplateInstances(templateHubPath);
154
- const templateConfig = getTemplatesConfig();
155
- const cliConfig = getCliConfig();
156
- const lang = (_a = cliConfig === null || cliConfig === void 0 ? void 0 : cliConfig.lang) !== null && _a !== void 0 ? _a : 'en';
157
- const firstSetOfItems = transferTemplatesToSelectItem(templateConfig, templateInstanceList, lang);
158
- let selectTemplate;
159
- let targetPath;
160
- let projectConfig;
161
- const preInstallDependencies = () => __awaiter(this, void 0, void 0, function* () {
162
- const packageJsonPath = path.join(targetPath, 'package.json');
163
- if (fs.existsSync(packageJsonPath)) {
164
- logger.log('Install dependencies');
165
- logger.log(t('init_install_dependence').d('⌛️ Installing dependencies...'));
166
- execSync('npm install', { stdio: 'inherit', cwd: targetPath });
167
- logger.success(t('init_install_dependencies_success').d('Dependencies installed successfully.'));
168
- logger.log(t('init_build_project').d('⌛️ Building project...'));
169
- execSync('npm run build', { stdio: 'inherit', cwd: targetPath });
170
- logger.success(t('init_build_project_success').d('Project built successfully.'));
171
- }
172
- });
173
- const handleFirstSelection = (item) => __awaiter(this, void 0, void 0, function* () {
174
- if (item.key === 'exit') {
175
- process.exit(0);
176
- }
177
- const configPath = item.value;
178
- selectTemplate = new Template(configPath, name);
179
- projectConfig = getProjectConfig(configPath);
180
- if (!projectConfig)
181
- return logger.notInProject();
182
- const newPath = process.cwd() + '/' + name;
183
- targetPath = newPath;
184
- if (fs.existsSync(newPath)) {
185
- logger.error(t('already_exist_file_error').d('Error: The project already exists. It looks like a folder named "<project-name>" is already present in the current directory. Please try the following options: 1. Choose a different project name. 2. Delete the existing folder if it\'s not needed: `rm -rf <project-name>` (use with caution!). 3. Move to a different directory before running the init command.'));
186
- exit(0);
187
- }
188
- yield fs.copy(configPath, newPath);
189
- projectConfig.name = name;
190
- updateProjectConfigFile(projectConfig, newPath);
191
- preInstallDependencies();
192
- logger.log(t('init_git').d('Do you want to init git in your project?'));
193
- SelectItems({
194
- items: secondSetOfItems,
195
- handleSelect: handleSecondSelection
196
- });
197
- });
198
- const handleSecondSelection = (item) => __awaiter(this, void 0, void 0, function* () {
199
- if (item.value === 'yesInstall') {
200
- installGit(targetPath);
201
- }
202
- else {
203
- logger.log(t('init_skip_git').d('Git installation was skipped.'));
204
- }
205
- const isLoginSuccess = yield checkIsLoginSuccess();
206
- if (!isLoginSuccess) {
207
- logger.log(chalk.yellow(t('not_login_auto_deploy').d('You are not logged in, automatic deployment cannot be performed. Please log in later and manually deploy.')));
208
- process.exit(0);
209
- }
210
- logger.log(t('auto_deploy').d('Do you want to deploy your project?'));
211
- SelectItems({
212
- items: secondSetOfItems,
213
- handleSelect: handleThirdSelection
214
- });
215
- });
216
- const handleThirdSelection = (item) => __awaiter(this, void 0, void 0, function* () {
217
- var _a, _b, _c;
218
- // 选择自动生成版本并发布
219
- if (item.value === 'yesInstall') {
220
- yield checkRoutineExist((_a = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _a !== void 0 ? _a : '', targetPath);
221
- projectConfig && (yield quickDeploy(targetPath, projectConfig));
222
- const service = yield ApiService.getInstance();
223
- const res = yield service.getRoutine({ Name: (_b = projectConfig === null || projectConfig === void 0 ? void 0 : projectConfig.name) !== null && _b !== void 0 ? _b : '' });
224
- const defaultUrl = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.DefaultRelatedRecord;
225
- const visitUrl = defaultUrl ? 'http://' + defaultUrl : '';
226
- logger.success(`${t('init_deploy_success').d('Project deployment completed. Visit: ')}${chalk.yellowBright(visitUrl)}`);
227
- logger.warn(t('deploy_url_warn').d('The domain may take some time to take effect, please try again later.'));
228
- }
229
- selectTemplate.printSummary();
230
- exit(0);
231
- });
232
- try {
233
- MultiLevelSelect({
234
- items: firstSetOfItems,
235
- handleSelect: handleFirstSelection
236
- });
237
- }
238
- catch (error) {
239
- logger.error(t('init_error').d('An error occurred while initializing.'));
240
- console.log(error);
161
+ // Initialize project files and configuration
162
+ const project = yield initializeProject(selectedTemplatePath, name);
163
+ if (!project) {
164
+ return;
241
165
  }
166
+ const { template, targetPath } = project;
167
+ // Handle Git initialization
168
+ yield handleGitInitialization(targetPath);
169
+ // Handle deployment
170
+ const projectConfig = getProjectConfig(targetPath);
171
+ yield handleDeployment(targetPath, projectConfig);
172
+ template.printSummary();
173
+ return;
242
174
  });
243
175
  }
@@ -7,63 +7,52 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useState } from 'react';
11
- import { render, Text, useApp } from 'ink';
12
- import SelectInput from 'ink-select-input';
13
- import Item from './selectItem.js';
14
- import t from '../i18n/index.js';
15
- const Indicator = ({ isSelected }) => {
16
- return React.createElement(Text, null, isSelected ? '👉 ' : ' ');
17
- };
18
- const EXIT_ITEM = {
19
- label: t('exit_select_init_template').d('Exit'),
20
- key: 'exit',
21
- value: '__exit__'
22
- };
23
- const RETURN_ITEM = {
24
- label: t('return_select_init_template').d('Return'),
25
- key: 'return',
26
- value: '__return__'
27
- };
28
- const MultiLevelSelect = ({ items, handleSelect, handleExit }) => {
29
- const { exit } = useApp();
30
- const [stack, setStack] = useState([[...items, EXIT_ITEM]]);
31
- const currentItems = stack[stack.length - 1];
32
- const onSelect = (item) => {
33
- if (item.value === '__return__') {
34
- if (stack.length > 1) {
35
- // 返回上一级菜单
36
- setStack(stack.slice(0, -1));
10
+ import inquirer from 'inquirer';
11
+ import logger from '../libs/logger.js';
12
+ /**
13
+ * Perform multi-level selection and return the final selected template path
14
+ * @param items Array of selection items (including categories and sub-templates)
15
+ * @param message Initial prompt message
16
+ * @returns Selected template path, or null if the user exits
17
+ */
18
+ export default function multiLevelSelect(items_1) {
19
+ return __awaiter(this, arguments, void 0, function* (items, message = 'Select a template:') {
20
+ let currentItems = items; // Current level options
21
+ const stack = []; // Stack to store previous level options for back navigation
22
+ let selectedPath = null;
23
+ while (selectedPath === null) {
24
+ const { choice } = yield inquirer.prompt([
25
+ {
26
+ type: 'list',
27
+ name: 'choice',
28
+ message,
29
+ pageSize: 10,
30
+ choices: [
31
+ ...currentItems.map((item) => ({ name: item.label, value: item })),
32
+ ...(stack.length > 0 ? [{ name: 'Back', value: 'back' }] : []), // Show "Back" if there’s a previous level
33
+ { name: 'Exit', value: 'exit' }
34
+ ]
35
+ }
36
+ ]);
37
+ if (choice === 'exit') {
38
+ logger.log('User canceled the operation.');
39
+ return null;
40
+ }
41
+ if (choice === 'back') {
42
+ currentItems = stack.pop(); // Return to the previous level
43
+ continue;
44
+ }
45
+ // If a category with children is selected
46
+ if (choice.children && choice.children.length > 0) {
47
+ stack.push(currentItems); // Save the current level
48
+ currentItems = choice.children; // Move to the next level
49
+ message = `Select a template under ${choice.label}:`;
37
50
  }
38
51
  else {
39
- // 顶层菜单,执行退出逻辑
40
- handleExit();
41
- exit();
52
+ // A leaf node (no children) is selected, end the selection
53
+ selectedPath = choice.value;
42
54
  }
43
- return;
44
- }
45
- if (item.children && item.children.length > 0) {
46
- setStack([...stack, [...item.children, RETURN_ITEM]]); // 在子层级中添加“退出”选项
47
55
  }
48
- else {
49
- handleSelect(item);
50
- exit();
51
- }
52
- };
53
- return (React.createElement(SelectInput, { items: currentItems, onSelect: onSelect, itemComponent: Item, indicatorComponent: Indicator, limit: 10 }));
54
- };
55
- export const MultiLevelSelectComponent = (props) => __awaiter(void 0, void 0, void 0, function* () {
56
- const { items, handleSelect, handleExit } = props;
57
- return new Promise((resolve) => {
58
- const { unmount } = render(React.createElement(MultiLevelSelect, { items: items, handleSelect: (item) => {
59
- unmount();
60
- handleSelect && handleSelect(item);
61
- resolve(item);
62
- }, handleExit: () => {
63
- unmount();
64
- handleExit && handleExit();
65
- resolve(null);
66
- } }));
56
+ return selectedPath;
67
57
  });
68
- });
69
- export default MultiLevelSelectComponent;
58
+ }
@@ -476,8 +476,8 @@
476
476
  "zh_CN": "route不合法"
477
477
  },
478
478
  "install_runtime_explain": {
479
- "en": "Under the beta phase, we are temporarily using Deno as the local development runtime. It needs to be installed first.",
480
- "zh_CN": "在Beta阶段,我们使用了Deno暂时作为本地开发运行时,需要先安装才可以dev。"
479
+ "en": "Our runtime does not yet support this OS. We are temporarily using Deno as the local development runtime, which needs to be installed first.",
480
+ "zh_CN": "我们的Runtime还不支持此操作系统,我们暂时使用Deno作为本地开发runtime,需要先安装。"
481
481
  },
482
482
  "install_runtime_tip": {
483
483
  "en": "🔔 Runtime must be installed to use esa dev. Installing...",
@@ -894,5 +894,45 @@
894
894
  "dev_url_invalid": {
895
895
  "en": "Invalid URL: ${url}. Please enter a valid URL.",
896
896
  "zh_CN": "不是正确的URL: ${url}. 请输入正确的URL."
897
+ },
898
+ "deno_download_failed": {
899
+ "en": "Download failed",
900
+ "zh_CN": "下载失败"
901
+ },
902
+ "deno_unzip_failed": {
903
+ "en": "Unzip failed",
904
+ "zh_CN": "解压失败"
905
+ },
906
+ "deno_add_path_failed": {
907
+ "en": "Add BinDir to Path failed",
908
+ "zh_CN": "添加环境变量失败"
909
+ },
910
+ "deno_install_success": {
911
+ "en": "Runtime install success!",
912
+ "zh_CN": "Runtime 安装成功!"
913
+ },
914
+ "deno_download_success": {
915
+ "en": "Download success",
916
+ "zh_CN": "下载成功"
917
+ },
918
+ "deno_install_success_tips": {
919
+ "en": "Please run ${dev} again",
920
+ "zh_CN": "请重新运行 ${dev}"
921
+ },
922
+ "no_build_script": {
923
+ "en": "No build script found in package.json, skipping build step.",
924
+ "zh_CN": "在 package.json 中未找到构建脚本,跳过构建步骤。"
925
+ },
926
+ "init_cancel": {
927
+ "en": "User canceled the operation.",
928
+ "zh_CN": "用户取消了操作。"
929
+ },
930
+ "routine_create_success": {
931
+ "en": "Routine created successfully.",
932
+ "zh_CN": "边缘函数创建成功"
933
+ },
934
+ "routine_create_fail": {
935
+ "en": "Routine created failed.",
936
+ "zh_CN": "边缘函数创建失败"
897
937
  }
898
938
  }
package/dist/index.js CHANGED
@@ -26,7 +26,6 @@ import { getCliConfig } from './utils/fileUtils/index.js';
26
26
  import { handleCheckVersion } from './utils/checkVersion.js';
27
27
  import t from './i18n/index.js';
28
28
  import site from './commands/site/index.js';
29
- import { quickDeployRoutine } from './libs/service.js';
30
29
  const main = () => __awaiter(void 0, void 0, void 0, function* () {
31
30
  const argv = hideBin(process.argv);
32
31
  const cliConfig = getCliConfig();
@@ -74,13 +73,6 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
74
73
  esa.command(logout);
75
74
  esa.command(config);
76
75
  esa.command(lang);
77
- esa.command('t', false, () => { }, (args) => __awaiter(void 0, void 0, void 0, function* () {
78
- const res = yield quickDeployRoutine({
79
- name: 'test',
80
- code: 'test'
81
- });
82
- // console.log(res);
83
- }));
84
76
  esa.group(['help', 'version'], 'Options:');
85
77
  esa.parse();
86
78
  });
@@ -10,7 +10,7 @@ import { getProjectConfig } from '../utils/fileUtils/index.js';
10
10
  const transport = new DailyRotateFile({
11
11
  filename: path.join(os.homedir(), '.esa-logs/esa-debug-%DATE%.log'),
12
12
  level: 'info',
13
- datePattern: 'YYYY-MM-DD-HH:mm:ss',
13
+ datePattern: 'YYYY-MM-DD-HH',
14
14
  zippedArchive: true,
15
15
  maxSize: '10m',
16
16
  maxFiles: '7d'
@@ -1,5 +1,6 @@
1
1
  import { getSummary } from '../../commands/common/constant.js';
2
2
  import chalk from 'chalk';
3
+ import logger from '../logger.js';
3
4
  export default class Template {
4
5
  constructor(path, title) {
5
6
  this.path = path;
@@ -10,7 +11,7 @@ export default class Template {
10
11
  list.forEach((summary) => {
11
12
  const title = chalk.bold(summary.title);
12
13
  const command = chalk.green(summary.command);
13
- console.log(`${title}: ${command}`);
14
+ logger.log(`${title}: ${command}`);
14
15
  });
15
16
  }
16
17
  }
@@ -51,11 +51,22 @@ export function checkRoutineExist(name, entry) {
51
51
  return acc;
52
52
  }, []);
53
53
  const spec = yield displaySelectSpec(specList);
54
- yield createEdgeRoutine({
54
+ console.log({
55
55
  name: name,
56
56
  specName: spec,
57
57
  code: code
58
58
  });
59
+ const res = yield createEdgeRoutine({
60
+ name: name,
61
+ specName: spec,
62
+ code: code
63
+ });
64
+ if (res) {
65
+ logger.success(t('routine_create_success').d('Routine created successfully.'));
66
+ }
67
+ else {
68
+ logger.error(t('routine_create_fail').d('Routine created failed.'));
69
+ }
59
70
  }
60
71
  });
61
72
  }
@@ -13,7 +13,7 @@ import path from 'path';
13
13
  export function handleCheckVersion() {
14
14
  return __awaiter(this, void 0, void 0, function* () {
15
15
  const __dirname = getDirName(import.meta.url);
16
- const packageJsonPath = path.join(__dirname, '..', 'package.json');
16
+ const packageJsonPath = path.join(__dirname, '..', '..', 'package.json');
17
17
  try {
18
18
  const jsonString = yield fs.readFile(packageJsonPath, 'utf-8');
19
19
  const packageJson = JSON.parse(jsonString);