Skip to content
This repository was archived by the owner on May 6, 2025. It is now read-only.

Commit aee98e5

Browse files
committed
fix hosting delete directory fail
1 parent f946cbf commit aee98e5

9 files changed

Lines changed: 231 additions & 263 deletions

File tree

lib/commands/hosting.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
1414
Object.defineProperty(exports, "__esModule", { value: true });
1515
const chalk_1 = __importDefault(require("chalk"));
1616
const commander_1 = __importDefault(require("commander"));
17+
const inquirer_1 = __importDefault(require("inquirer"));
1718
const hosting_1 = require("../hosting");
1819
const error_1 = require("../error");
1920
const utils_1 = require("../utils");
@@ -74,20 +75,32 @@ commander_1.default
7475
commander_1.default
7576
.command('hosting:delete [cloudPath]')
7677
.option('-e, --envId [envId]', '环境 Id')
77-
.option('-d, --dir', '删除文件夹')
78-
.description('删除静态网站文件/文件夹')
78+
.option('-d, --dir', '删除目标是否为文件夹')
79+
.description('删除静态网站文件/文件夹,文件夹需指定 --dir 选项')
7980
.action((cloudPath = '', options) => __awaiter(void 0, void 0, void 0, function* () {
8081
const { parent: { configFile }, envId } = options;
81-
const { dir } = options;
82-
const fileText = dir ? '文件夹' : '文件';
82+
let isDir = options.dir;
83+
if (cloudPath === '') {
84+
const { confirm } = yield inquirer_1.default.prompt({
85+
type: 'confirm',
86+
name: 'confirm',
87+
message: '指定云端路径为空,将会删除所有文件,是否继续',
88+
default: false
89+
});
90+
if (!confirm) {
91+
throw new error_1.CloudBaseError('操作终止!');
92+
}
93+
isDir = true;
94+
}
95+
const fileText = isDir ? '文件夹' : '文件';
8396
const assignEnvId = yield utils_1.getEnvId(envId, configFile);
8497
const loading = utils_1.loadingFactory();
8598
loading.start(`删除${fileText}中...`);
8699
try {
87100
yield hosting_1.hostingDelete({
101+
isDir,
88102
cloudPath,
89-
envId: assignEnvId,
90-
isDir: dir
103+
envId: assignEnvId
91104
});
92105
loading.succeed(`删除${fileText}成功!`);
93106
}

lib/hosting.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,12 +141,12 @@ function hostingDeploy(options) {
141141
const { bucket, regoin } = hosting;
142142
const storageService = yield getStorageService(envId);
143143
if (utils_1.isDirectory(resolvePath)) {
144-
storageService.uploadDirectoryCustom(resolvePath, cloudPath, bucket, regoin, {
144+
yield storageService.uploadDirectoryCustom(resolvePath, cloudPath, bucket, regoin, {
145145
onProgress
146146
});
147147
}
148148
else {
149-
storageService.uploadFileCustom(resolvePath, cloudPath, bucket, regoin, {
149+
yield storageService.uploadFileCustom(resolvePath, cloudPath, bucket, regoin, {
150150
onProgress
151151
});
152152
}
@@ -160,10 +160,10 @@ function hostingDelete(options) {
160160
const { bucket, regoin } = hosting;
161161
const storageService = yield getStorageService(envId);
162162
if (isDir) {
163-
storageService.deleteDirectoryCustom(cloudPath, bucket, regoin);
163+
yield storageService.deleteDirectoryCustom(cloudPath, bucket, regoin);
164164
}
165165
else {
166-
storageService.deleteFileCustom([cloudPath], bucket, regoin);
166+
yield storageService.deleteFileCustom([cloudPath], bucket, regoin);
167167
}
168168
});
169169
}

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"author": "",
2626
"license": "ISC",
2727
"dependencies": {
28-
"@cloudbase/manager-node": "^1.3.0-beta",
28+
"@cloudbase/manager-node": "^1.3.0-beta.1",
2929
"@sentry/node": "^5.7.1",
3030
"address": "^1.1.2",
3131
"archiver": "^3.1.1",

src/commands/hosting.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import chalk from 'chalk'
22
import program from 'commander'
3+
import inquirer from 'inquirer'
34
import { getHostingInfo, hostingDeploy, hostingDelete, hostingList } from '../hosting'
45
import { CloudBaseError } from '../error'
56
import {
@@ -85,15 +86,30 @@ program
8586
program
8687
.command('hosting:delete [cloudPath]')
8788
.option('-e, --envId [envId]', '环境 Id')
88-
.option('-d, --dir', '删除文件夹')
89-
.description('删除静态网站文件/文件夹')
89+
.option('-d, --dir', '删除目标是否为文件夹')
90+
.description('删除静态网站文件/文件夹,文件夹需指定 --dir 选项')
9091
.action(async (cloudPath = '', options: any) => {
9192
const {
9293
parent: { configFile },
9394
envId
9495
} = options
95-
const { dir } = options
96-
const fileText = dir ? '文件夹' : '文件'
96+
97+
let isDir = options.dir
98+
99+
// 删除所有文件,危险操作,需要提示
100+
if (cloudPath === '') {
101+
const { confirm } = await inquirer.prompt({
102+
type: 'confirm',
103+
name: 'confirm',
104+
message: '指定云端路径为空,将会删除所有文件,是否继续',
105+
default: false
106+
})
107+
if (!confirm) {
108+
throw new CloudBaseError('操作终止!')
109+
}
110+
isDir = true
111+
}
112+
const fileText = isDir ? '文件夹' : '文件'
97113

98114
const assignEnvId = await getEnvId(envId, configFile)
99115

@@ -102,9 +118,9 @@ program
102118

103119
try {
104120
await hostingDelete({
121+
isDir,
105122
cloudPath,
106-
envId: assignEnvId,
107-
isDir: dir
123+
envId: assignEnvId
108124
})
109125
loading.succeed(`删除${fileText}成功!`)
110126
} catch (e) {

src/hosting.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,11 +166,11 @@ export async function hostingDeploy(options: IHostingFileOptions) {
166166
const storageService = await getStorageService(envId)
167167

168168
if (isDirectory(resolvePath)) {
169-
storageService.uploadDirectoryCustom(resolvePath, cloudPath, bucket, regoin, {
169+
await storageService.uploadDirectoryCustom(resolvePath, cloudPath, bucket, regoin, {
170170
onProgress
171171
})
172172
} else {
173-
storageService.uploadFileCustom(resolvePath, cloudPath, bucket, regoin, {
173+
await storageService.uploadFileCustom(resolvePath, cloudPath, bucket, regoin, {
174174
onProgress
175175
})
176176
}
@@ -184,8 +184,8 @@ export async function hostingDelete(options: IHostingCloudOptions) {
184184
const storageService = await getStorageService(envId)
185185

186186
if (isDir) {
187-
storageService.deleteDirectoryCustom(cloudPath, bucket, regoin)
187+
await storageService.deleteDirectoryCustom(cloudPath, bucket, regoin)
188188
} else {
189-
storageService.deleteFileCustom([cloudPath], bucket, regoin)
189+
await storageService.deleteFileCustom([cloudPath], bucket, regoin)
190190
}
191191
}

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export interface ICloudFunctionConfig {
9292
runtime?: string
9393
vpc?: IFunctionVPC
9494
l5?: boolean
95-
installDependency: boolean
95+
installDependency?: boolean
9696
}
9797

9898
export interface ICloudFunctionTrigger {

0 commit comments

Comments
 (0)