Skip to content

Commit 389a983

Browse files
authored
Merge pull request #32 from aliyun/feat-optional-esa-cli
Feat optional esa cli
2 parents 7afd875 + 8569da6 commit 389a983

File tree

11 files changed

+73
-26
lines changed

11 files changed

+73
-26
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Changelog
22

3+
## [1.0.6] - 2026-01-20
4+
5+
### Added
6+
7+
- Update template version to latest
8+
- Support to skip install esa-cli when init a project
9+
10+
### Fixed
11+
12+
- Fix init command error in Windows
13+
314
## [1.0.5] - 2026-01-13
415

516
### Fixed
@@ -18,6 +29,8 @@
1829
### Fixed
1930

2031
- Fix mock KV storage issues in development environment
32+
- Fix mock cache error in the top of workers code
33+
- Fix API update config bug
2134

2235
## [1.0.2] - 2025-11-19
2336

package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "esa-cli",
3-
"version": "1.0.5",
3+
"version": "1.0.6",
44
"description": "A CLI for operating Alibaba Cloud ESA Functions and Pages.",
55
"main": "bin/enter.cjs",
66
"type": "module",
@@ -15,7 +15,7 @@
1515
"README.md"
1616
],
1717
"scripts": {
18-
"build": "rm -rf ./dist && rm -rf ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
18+
"build": "rimraf ./dist ./build && node ./genLocale.cjs && tsc && node ./copy.cjs",
1919
"dev": "tsc --watch",
2020
"eslint": "eslint src/ --ext .js,.jsx,.ts,.tsx",
2121
"prepare": "husky install",
@@ -64,9 +64,6 @@
6464
"jsdom": "^25.0.1",
6565
"lint-staged": "^15.0.2",
6666
"prettier": "^3.0.3",
67-
"react": "^18.2.0",
68-
"react-dom": "^18.2.0",
69-
"rimraf": "^6.0.1",
7067
"tsc-files": "^1.1.4",
7168
"typescript": "^5.2.2",
7269
"vitest": "^2.0.4"
@@ -86,7 +83,7 @@
8683
"chokidar": "^3.5.3",
8784
"cli-table3": "^0.6.5",
8885
"cross-spawn": "^7.0.3",
89-
"esa-template": "^0.0.9",
86+
"esa-template": "^0.0.10",
9087
"esbuild": "^0.21.1",
9188
"esbuild-plugin-less": "^1.3.8",
9289
"form-data": "^4.0.0",
@@ -106,7 +103,10 @@
106103
"portscanner": "^2.2.0",
107104
"winston": "^3.11.0",
108105
"winston-daily-rotate-file": "^5.0.0",
109-
"yargs": "^17.7.2"
106+
"yargs": "^17.7.2",
107+
"react": "^18.2.0",
108+
"react-dom": "^18.2.0",
109+
"rimraf": "^6.0.1"
110110
},
111111
"lint-staged": {
112112
"src/**/*.{ts,tsx,js,jsx}": [

src/commands/config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import fs from 'fs';
2+
import os from 'os';
23

34
import spawn from 'cross-spawn';
45
import { CommandModule, ArgumentsCamelCase, Argv } from 'yargs';
@@ -7,8 +8,20 @@ import t from '../i18n/index.js';
78
import logger from '../libs/logger.js';
89
import { projectConfigPath, cliConfigPath } from '../utils/fileUtils/index.js';
910

11+
const getDefaultEditor = (): string => {
12+
// Use environment variable if set
13+
if (process.env.EDITOR) {
14+
return process.env.EDITOR;
15+
}
16+
// Platform-specific default editors
17+
if (os.platform() === 'win32') {
18+
return 'notepad';
19+
}
20+
return 'vi';
21+
};
22+
1023
const editConfigFile = (configPath: string) => {
11-
const editor = process.env.EDITOR || 'vi';
24+
const editor = getDefaultEditor();
1225
spawn(editor, [configPath], {
1326
stdio: 'inherit'
1427
});

src/commands/dev/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ const dev: CommandModule = {
236236
if (path.includes('.dev')) {
237237
if (userFileRepacking) {
238238
userFileRepacking = false;
239-
return;
240239
}
241-
worker.restart(devPack);
242240
return;
243241
}
244242
logger.info('Dev repack');

src/commands/init/helper.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { execSync } from 'child_process';
2+
import os from 'os';
23
import path from 'path';
34
import { exit } from 'process';
45

@@ -148,9 +149,8 @@ export async function checkAndUpdatePackage(
148149
spinner.text = t('template_updating').d(
149150
'Updating templates to latest...'
150151
);
151-
execSync(`rm -rf node_modules/${packageName}`, {
152-
cwd: packageJsonPath
153-
});
152+
// Cross-platform: use fs-extra.removeSync instead of rm -rf
153+
fs.removeSync(path.join(packageJsonPath, 'node_modules', packageName));
154154
execSync(`npm install ${packageName}@latest`, {
155155
cwd: packageJsonPath,
156156
stdio: 'inherit'
@@ -196,12 +196,9 @@ export async function checkAndUpdatePackage(
196196
spinner.start(
197197
t('template_updating').d('Updating templates to latest...')
198198
);
199-
execSync(`rm -rf node_modules/${packageName}`, {
200-
cwd: packageJsonPath
201-
});
202-
execSync(`rm -rf package-lock.json`, {
203-
cwd: packageJsonPath
204-
});
199+
// Cross-platform: use fs-extra.removeSync instead of rm -rf
200+
fs.removeSync(path.join(packageJsonPath, 'node_modules', packageName));
201+
fs.removeSync(path.join(packageJsonPath, 'package-lock.json'));
205202
execSync(`npm install ${packageName}@latest`, {
206203
cwd: packageJsonPath,
207204
stdio: 'inherit'
@@ -277,6 +274,7 @@ export function getInitParamsFromArgv(argv: ArgumentsCamelCase): initParams {
277274
params.framework = undefined;
278275
params.language = undefined;
279276
params.yes = true;
277+
params.installEsaCli = false;
280278
}
281279

282280
if (typeof a.name === 'string') params.name = a.name;
@@ -298,6 +296,8 @@ export function getInitParamsFromArgv(argv: ArgumentsCamelCase): initParams {
298296
}
299297
if (typeof a.git === 'boolean') params.git = Boolean(a.git);
300298
if (typeof a.deploy === 'boolean') params.deploy = Boolean(a.deploy);
299+
if (typeof a['install-esa-cli'] === 'boolean')
300+
params.installEsaCli = Boolean(a['install-esa-cli']);
301301

302302
return params;
303303
}
@@ -593,6 +593,20 @@ export const applyFileEdits = async (
593593
};
594594

595595
export const installESACli = async (initParams: initParams) => {
596+
if (!initParams.installEsaCli) {
597+
const install = (await promptParameter<boolean>({
598+
type: 'confirm',
599+
question: 'Do you want to install esa-cli as a dev dependency?',
600+
label: 'Install ESA CLI',
601+
defaultValue: false
602+
})) as boolean;
603+
initParams.installEsaCli = install;
604+
}
605+
606+
if (!initParams.installEsaCli) {
607+
return;
608+
}
609+
596610
const targetPath = path.join(process.cwd(), initParams.name);
597611
const res = await execCommand(['npm', 'install', '-D', 'esa-cli'], {
598612
cwd: targetPath,
@@ -859,6 +873,9 @@ export async function initializeProject(
859873

860874
const targetPath = path.join(process.cwd(), name);
861875
if (fs.existsSync(targetPath)) {
876+
// Cross-platform delete command hint
877+
const isWindows = os.platform() === 'win32';
878+
const deleteCmd = isWindows ? `rmdir /s /q "${name}"` : `rm -rf "${name}"`;
862879
logger.block();
863880
logger.tree([
864881
`${chalk.bgRed(' ERROR ')} ${chalk.bold.red(
@@ -871,7 +888,7 @@ export async function initializeProject(
871888
chalk.gray(t('try').d('Try one of the following:')),
872889
`- ${chalk.white(t('try_diff_name').d('Choose a different project name'))}`,
873890
`- ${chalk.white(t('try_remove').d('Remove the directory:'))} ${chalk.yellow(
874-
`rm -rf "${name}”`
891+
deleteCmd
875892
)}`,
876893
`- ${chalk.white(
877894
t('try_another_dir').d('Run the command in another directory')

src/commands/init/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ const init: CommandModule = {
6666
alias: 'd',
6767
describe: 'Deploy after initialization',
6868
type: 'boolean'
69+
})
70+
.option('install-esa-cli', {
71+
describe: 'Install esa-cli as a dev dependency',
72+
type: 'boolean',
73+
default: false
6974
});
7075
},
7176
handler: async (argv: ArgumentsCamelCase) => {

src/commands/init/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface initParams {
1212
category?: 'framework' | 'template';
1313
yes?: boolean;
1414
skip?: boolean;
15+
installEsaCli?: boolean;
1516
}
1617

1718
export type FileEdit = {

src/commands/routine/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import routineList from './list.js';
88
let yargsIns: Argv;
99
const routineCommand: CommandModule<{}> = {
1010
command: 'project [script]',
11-
aliases: ['routine'],
12-
describe: `🧭 ${t('routine_describe').d('Manage your project')}`,
11+
aliases: ['Functions & Pages'],
12+
describe: `🧭 ${t('routine_describe').d('Manage your Functions & Pages project')}`,
1313
builder: (yargs) => {
1414
yargsIns = yargs;
1515
return yargs

src/i18n/locales.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@
468468
"zh_CN": "用这个命令登录:${namedCommand}"
469469
},
470470
"routine_describe": {
471-
"en": "Manage your project",
471+
"en": "Manage your Functions & Pages project",
472472
"zh_CN": "管理函数和Pages"
473473
},
474474
"route_input": {

src/utils/command.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const execCommand = async (
4242
transformOutput,
4343
fallbackOutput,
4444
errorMessage,
45-
shell = false
45+
shell = isWindows
4646
} = options;
4747

4848
// Determine stdio mode based on options

0 commit comments

Comments
 (0)