@taole/deploy-helper 0.3.5 → 0.3.7

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/index.mjs CHANGED
@@ -6,6 +6,7 @@ import { join, basename, dirname } from "path";
6
6
  import { simpleGit } from 'simple-git';
7
7
  import { homedir } from 'os'
8
8
  import { runPipeline, checkYunxiaoToken, triggerPipeline } from './lib/pipelineApi.mjs';
9
+ import { setDebug, log } from './lib/util.mjs';
9
10
 
10
11
  const TEST_SERVER_HOST = "192.168.0.35";
11
12
  /**
@@ -18,7 +19,7 @@ async function loadConfig() {
18
19
  const configJson = JSON.parse(fs.readFileSync(configJsonPath, "utf-8"));
19
20
  return configJson;
20
21
  }
21
- console.log(`deploy.config.json不存在, 请先创建`);
22
+ log(`deploy.config.json不存在, 请先创建`);
22
23
  return null;
23
24
  }
24
25
 
@@ -26,7 +27,7 @@ async function initConfigJson() {
26
27
  // check if deploy.config.json exists
27
28
  const configJsonPath = join(process.cwd(), "deploy.config.json");
28
29
  if (fs.existsSync(configJsonPath)) {
29
- console.log(`deploy.config.json已存在, 请勿重复创建`);
30
+ log(`deploy.config.json已存在, 请勿重复创建`);
30
31
  return;
31
32
  }
32
33
 
@@ -52,7 +53,7 @@ async function initConfigJson() {
52
53
  }
53
54
  }`;
54
55
  fs.writeFileSync(configJsonPath, content, { encoding: "utf-8" });
55
- console.log(`deploy.config.json创建成功`);
56
+ log(`deploy.config.json创建成功`);
56
57
  process.exit(0);
57
58
  }
58
59
 
@@ -72,7 +73,7 @@ async function getScpClient() {
72
73
  if (fs.existsSync(sshKeyPath)) {
73
74
  scpClientConfig.privateKey = fs.readFileSync(sshKeyPath, "utf-8");
74
75
  } else {
75
- console.log(`${sshKeyPath}不存在, 建议配置本机ssh免密登录, 参考地址:https://foochane.cn/article/2019061601.html`);
76
+ log(`${sshKeyPath}不存在, 建议配置本机ssh免密登录, 参考地址:https://foochane.cn/article/2019061601.html`);
76
77
  }
77
78
  scpClient = await Client(scpClientConfig);
78
79
  return scpClient;
@@ -83,8 +84,14 @@ async function getScpClient() {
83
84
 
84
85
  async function main() {
85
86
 
87
+ // process.argv.includes("--debug") ||
88
+ // 默认开启debug debug目前只是打印日志的时候额外打印时间
89
+ setDebug(true);
90
+
91
+ log("deploy-helper start");
92
+
86
93
  // await devTest();
87
- // console.log(`process.argv: ${process.argv[2]} ${process.argv[3]} ${process.argv[4]}`);
94
+ // log(`process.argv: ${process.argv[2]} ${process.argv[3]} ${process.argv[4]}`);
88
95
 
89
96
  // return;
90
97
  // other commands
@@ -103,7 +110,7 @@ async function main() {
103
110
  console.log(`command: scp {file} {dest} 复制文件{file}到OfficialSite测试服务器{dest}`);
104
111
  console.log(`command: scpevt {file} 复制文件{file}到events测试服务器{file}`);
105
112
  console.log(`command: scpevt {file} {dest} 复制文件{file}到events测试服务器{dest}`);
106
- console.log(`command: pipeline {pipelineName|pipelineId} 触发流水线{pipelineName|pipelineId}`);
113
+ log(`command: pipeline {pipelineName|pipelineId} 触发流水线{pipelineName|pipelineId}`);
107
114
  process.exit(0);
108
115
  } else if (command === "init") {
109
116
  await initConfigJson();
@@ -111,18 +118,18 @@ async function main() {
111
118
  } else if (["scp", "scpevt"].includes(command)) {
112
119
  const file = process.argv[3];
113
120
  if (!file) {
114
- console.log(`file参数不能为空`);
121
+ log(`file参数不能为空`);
115
122
  process.exit(1);
116
123
  }
117
124
  const workDir = process.cwd(); // 当前项目根目录
118
125
 
119
126
  const srcFilePath = join(workDir, file);
120
127
  if (!fs.existsSync(srcFilePath)) {
121
- console.log(`${srcFilePath}不存在`);
128
+ log(`${srcFilePath}不存在`);
122
129
  process.exit(1);
123
130
  }
124
131
  if (fs.statSync(srcFilePath).isDirectory()) {
125
- console.log(`${srcFilePath}是目录, 不支持scp目录`);
132
+ log(`${srcFilePath}是目录, 不支持scp目录`);
126
133
  process.exit(1);
127
134
  }
128
135
  // 获取srcFilePath的目录
@@ -130,33 +137,33 @@ async function main() {
130
137
  const fileName = basename(srcFilePath);
131
138
  const dest = process.argv[4] || fileName;
132
139
  if (dest.includes("/") || dest.includes("\\")) {
133
- console.log(`dest不能包含/或\\`);
140
+ log(`dest不能包含/或\\`);
134
141
  process.exit(1);
135
142
  }
136
143
 
137
144
  if (workDir !== fileDir) {
138
- console.log(`仅支持scp当前目录下的文件(不带子目录)`);
145
+ log(`仅支持scp当前目录下的文件(不带子目录)`);
139
146
  process.exit(1);
140
147
  }
141
148
 
142
149
  const destPath = "/home/web/website/tuwan_www/templets/static/play/" + (command === 'scp' ? '' : 'events/') + dest;
143
150
 
144
151
  const scpClient = await getScpClient();
145
- console.log(`scp: ${srcFilePath} -> ${TEST_SERVER_HOST}:${destPath}`);
152
+ log(`scp: ${srcFilePath} -> ${TEST_SERVER_HOST}:${destPath}`);
146
153
  await scpClient.uploadFile(srcFilePath, destPath);
147
- console.log(`scp done.`);
154
+ log(`scp done.`);
148
155
  process.exit(0);
149
156
  } else if (command === "pipeline") {
150
157
  const pipelineName = process.argv[3];
151
158
  if (!pipelineName) {
152
- console.log(`pipeline参数不能为空`);
159
+ log(`pipeline参数不能为空`);
153
160
  process.exit(1);
154
161
  }
155
162
  try {
156
163
  await triggerPipeline(pipelineName);
157
164
  process.exit(0);
158
165
  } catch (error) {
159
- console.log(`触发流水线失败: ${error}`);
166
+ log(`触发流水线失败: ${error}`);
160
167
  process.exit(1);
161
168
  }
162
169
 
@@ -164,22 +171,22 @@ async function main() {
164
171
  try {
165
172
  const workDir = process.cwd(); // 当前项目根目录
166
173
  const mode = process.argv[2] === 'prod' ? 'prod' : 'test'; // 部署环境
167
- console.log(`deploy mode: ${mode}`);
168
- console.log(`workDir: ${workDir}`);
174
+ log(`deploy mode: ${mode}`);
175
+ log(`workDir: ${workDir}`);
169
176
 
170
177
  // 读取配置
171
178
  const config = await loadConfig();
172
- // console.log(`config`, config);
179
+ // log(`config`, config);
173
180
 
174
181
  // 检查配置格式
175
182
  if (!config.assets || !config.assets.dest || !config.entry || !config.entry.dest) {
176
- console.log(`配置格式错误, 请检查deploy.config.js或deploy.config.json`);
183
+ log(`配置格式错误, 请检查deploy.config.js或deploy.config.json`);
177
184
  return;
178
185
  }
179
186
 
180
187
  const result = hasChangeMe(JSON.stringify(config));
181
188
  if (result) {
182
- console.log(`配置中存在默认值(CHANGE_ME), 请先修改配置`);
189
+ log(`配置中存在默认值(CHANGE_ME), 请先修改配置`);
183
190
  process.exit(1);
184
191
  }
185
192
 
@@ -201,12 +208,12 @@ async function main() {
201
208
  const assetsDest = join(workDir, config.assets.dest);
202
209
  const entryDest = join(workDir, config.entry.dest);
203
210
  if (!fs.existsSync(assetsDest)) {
204
- console.log(`assets.dest路径不存在: ${assetsDest}, 请先创建`);
211
+ log(`assets.dest路径不存在: ${assetsDest}, 请先创建`);
205
212
  return;
206
213
  }
207
214
  // entry.dest
208
215
  if (needHandleEntry && !fs.existsSync(entryDest)) {
209
- console.log(`entry.dest路径不存在: ${entryDest}, 请先创建`);
216
+ log(`entry.dest路径不存在: ${entryDest}, 请先创建`);
210
217
  return;
211
218
  }
212
219
 
@@ -214,7 +221,7 @@ async function main() {
214
221
  const assetsGit = simpleGit(assetsDest);
215
222
  let assetsStatus = await assetsGit.status();
216
223
  if (!assetsStatus.isClean()) {
217
- console.log(`${assetsDest}目前有未提交内容, 请先处理`);
224
+ log(`${assetsDest}目前有未提交内容, 请先处理`);
218
225
  return;
219
226
  }
220
227
 
@@ -224,7 +231,7 @@ async function main() {
224
231
  entryGit = simpleGit(entryDest);
225
232
  entryStatus = await entryGit.status();
226
233
  if (!entryStatus.isClean()) {
227
- console.log(`${entryDest}目前有未提交内容, 请先处理`);
234
+ log(`${entryDest}目前有未提交内容, 请先处理`);
228
235
  return;
229
236
  }
230
237
  }
@@ -234,11 +241,11 @@ async function main() {
234
241
  // const currentGit = simpleGit(workDir);
235
242
  // const currentStatus = await currentGit.status();
236
243
  // if (!currentStatus.isClean()) {
237
- // console.log(`当前项目有未提交内容, 请先处理`);
244
+ // log(`当前项目有未提交内容, 请先处理`);
238
245
  // process.exit(1);
239
246
  // }
240
247
  // if (currentStatus.branch !== currentProdBranch) {
241
- // console.log(`当前项目分支${currentStatus.branch}不是${currentProdBranch}分支, 请切换至${currentProdBranch}分支再执行prod命令`);
248
+ // log(`当前项目分支${currentStatus.branch}不是${currentProdBranch}分支, 请切换至${currentProdBranch}分支再执行prod命令`);
242
249
  // process.exit(1);
243
250
  // }
244
251
  // }
@@ -246,20 +253,24 @@ async function main() {
246
253
  // 3. 检查assets项目分支,并切换至master分支
247
254
  // assets项目固定使用master分支
248
255
  if (assetsStatus.current !== "master") {
249
- console.log(`${assetsDest}当前分支不是master, 切换至master分支`);
256
+ log(`${assetsDest}当前分支不是master, 切换至master分支`);
250
257
  await assetsGit.checkout("master");
251
- console.log(`${assetsDest}切换至master分支成功`);
258
+ log(`${assetsDest}切换至master分支成功`);
252
259
  }
253
260
  if (needHandleEntry && entryStatus.current !== entryTargetBranch) {
254
- console.log(`${entryDest}当前分支不是${entryTargetBranch}, 切换至${entryTargetBranch}分支`);
261
+ log(`${entryDest}当前分支不是${entryTargetBranch}, 切换至${entryTargetBranch}分支`);
255
262
  await entryGit.checkout(entryTargetBranch);
256
- console.log(`${entryDest}切换至${entryTargetBranch}分支成功`);
263
+ log(`${entryDest}切换至${entryTargetBranch}分支成功`);
257
264
  }
258
265
 
259
266
  // 4. 执行git pull
267
+ log(`${assetsDest}执行git pull`);
260
268
  await assetsGit.pull();
269
+ log(`${assetsDest} git pull done`);
261
270
  if (entryGit) {
271
+ log(`${entryDest}执行git pull`);
262
272
  await entryGit.pull();
273
+ log(`${entryDest} git pull done`);
263
274
  }
264
275
 
265
276
  // 5. 复制构建产物
@@ -269,7 +280,7 @@ async function main() {
269
280
  for (const [src, dest] of Object.entries(assetsFiles)) {
270
281
  const srcPath = join(workDir, src);
271
282
  if (!fs.existsSync(srcPath)) {
272
- console.log(`${srcPath}不存在,请确认构建产物是否正确`);
283
+ log(`${srcPath}不存在,请确认构建产物是否正确`);
273
284
  return;
274
285
  }
275
286
  const destPath = join(assetsDest, dest);
@@ -278,28 +289,28 @@ async function main() {
278
289
  } else {
279
290
  fs.copyFileSync(srcPath, destPath);
280
291
  }
281
- console.log(`assets copy: ${srcPath} -> ${destPath}`);
292
+ log(`assets copy: ${srcPath} -> ${destPath}`);
282
293
  assetsFilesCount++;
283
294
  }
284
- // console.log(`assets copy done.`);
295
+ // log(`assets copy done.`);
285
296
  // 5.2 复制entry
286
297
  if (needHandleEntry) {
287
298
  const entryFiles = config.entry.files;
288
299
  for (const [src, dest] of Object.entries(entryFiles)) {
289
300
  const srcPath = join(workDir, src);
290
301
  if (!fs.existsSync(srcPath)) {
291
- console.log(`${srcPath}不存在,请确认构建产物是否正确`);
302
+ log(`${srcPath}不存在,请确认构建产物是否正确`);
292
303
  return;
293
304
  }
294
305
  if (fs.statSync(srcPath).isDirectory()) {
295
- console.log(`entry: ${srcPath}是目录,不支持entry为目录的部署`);
306
+ log(`entry: ${srcPath}是目录,不支持entry为目录的部署`);
296
307
  return;
297
308
  }
298
309
  const destPath = join(entryDest, dest);
299
310
  fs.copyFileSync(srcPath, destPath);
300
- console.log(`entry copy: ${srcPath} -> ${destPath}`);
311
+ log(`entry copy: ${srcPath} -> ${destPath}`);
301
312
  }
302
- // console.log(`entry copy done.`);
313
+ // log(`entry copy done.`);
303
314
  }
304
315
 
305
316
  // 6. 提交
@@ -311,10 +322,10 @@ async function main() {
311
322
  await assetsGit.add(".");
312
323
  const assetsCommit = `${config.assets.commit || "feat:部署资源文件"} by deploy-helper`;
313
324
  const assetsCommitResult = await assetsGit.commit(assetsCommit);
314
- console.log(`assets commit: ${assetsCommit}`);
315
- console.log(`assets commit: ${JSON.stringify(assetsCommitResult.summary)}`);
325
+ log(`assets commit: ${assetsCommit}`);
326
+ log(`assets commit: ${JSON.stringify(assetsCommitResult.summary)}`);
316
327
  } else {
317
- console.log(`${assetsDest} 未发现修改内容,跳过提交`);
328
+ log(`${assetsDest} 未发现修改内容,跳过提交`);
318
329
  }
319
330
 
320
331
  if (needHandleEntry) {
@@ -324,10 +335,10 @@ async function main() {
324
335
  await entryGit.add(".");
325
336
  const entryCommit = `${config.entry.commit || "feat:部署入口文件"} by deploy-helper`;
326
337
  const entryCommitResult = await entryGit.commit(entryCommit);
327
- console.log(`entry commit: ${entryCommit}`);
328
- console.log(`entry commit: ${JSON.stringify(entryCommitResult.summary)}`);
338
+ log(`entry commit: ${entryCommit}`);
339
+ log(`entry commit: ${JSON.stringify(entryCommitResult.summary)}`);
329
340
  } else {
330
- console.log(`${entryDest} 未发现修改内容,跳过提交`);
341
+ log(`${entryDest} 未发现修改内容,跳过提交`);
331
342
  }
332
343
  }
333
344
 
@@ -338,7 +349,7 @@ async function main() {
338
349
  } catch (error) {
339
350
  await assetsGit.push();
340
351
  }
341
- console.log(`assets push done.`);
352
+ log(`assets push done.`);
342
353
  }
343
354
  if (canPushEntry) {
344
355
  try {
@@ -346,7 +357,7 @@ async function main() {
346
357
  } catch (error) {
347
358
  await entryGit.push();
348
359
  }
349
- console.log(`entry push done.`);
360
+ log(`entry push done.`);
350
361
  }
351
362
 
352
363
  try {
@@ -357,15 +368,15 @@ async function main() {
357
368
  for (const [src, dest] of Object.entries(syncTestFiles)) {
358
369
  const srcPath = join(workDir, src);
359
370
  const destPath = "/home/web/website/tuwan_www/templets/static/play/" + dest;
360
- console.log(`scp: ${srcPath} -> ${TEST_SERVER_HOST}:${destPath}`);
371
+ log(`scp: ${srcPath} -> ${TEST_SERVER_HOST}:${destPath}`);
361
372
  await scpClient.uploadFile(srcPath, destPath)
362
373
  }
363
374
  }
364
375
  } catch (error) {
365
- console.log(`scp error: ${error}`);
366
- console.log(`复制文件到测试环境服务器失败, 建议配置本机ssh免密登录, 参考地址:https://foochane.cn/article/2019061601.html`);
376
+ log(`scp error: ${error}`);
377
+ log(`复制文件到测试环境服务器失败, 建议配置本机ssh免密登录, 参考地址:https://foochane.cn/article/2019061601.html`);
367
378
  if (assetsFilesCount > 0) {
368
- console.log(`不过请放心,构建产物的assets已经处理完成,只要手动处理index.html文件即可。`);
379
+ log(`不过请放心,构建产物的assets已经处理完成,只要手动处理index.html文件即可。`);
369
380
  }
370
381
  process.exit(1);
371
382
  }
@@ -374,11 +385,11 @@ async function main() {
374
385
  // 处理触发流水线的任务
375
386
  await runPipeline(config, mode);
376
387
 
377
- console.log(`deploy-helper deploy done.`);
388
+ log(`deploy-helper deploy done.`);
378
389
  process.exit(0);
379
390
 
380
391
  } catch (error) {
381
- console.log(`error occurred in deploy-helper`, error);
392
+ log(`error occurred in deploy-helper`, error);
382
393
  process.exit(1);
383
394
  }
384
395
  }
@@ -2,6 +2,7 @@ import { homedir } from 'node:os';
2
2
  import { join } from 'node:path';
3
3
  import fs from 'node:fs';
4
4
  import simpleGit from 'simple-git';
5
+ import { log, isDebug } from './util.mjs';
5
6
 
6
7
  import { createPipelineRunFunc, listPipelinesFunc, getPipelineFunc } from '../modules/alibabacloud-devops-mcp-server/dist/operations/flow/pipeline.js'
7
8
 
@@ -35,7 +36,7 @@ export function getYunxiaoToken(pipelineConfig) {
35
36
  if (devToken) {
36
37
  if (isFirstFoundToken) {
37
38
  isFirstFoundToken = false;
38
- console.log(`将使用devToken`);
39
+ log(`将使用devToken`);
39
40
  }
40
41
  return devToken;
41
42
  }
@@ -45,7 +46,7 @@ export function getYunxiaoToken(pipelineConfig) {
45
46
  if (token) {
46
47
  if (isFirstFoundToken) {
47
48
  isFirstFoundToken = false;
48
- console.log(`将使用来自环境变量YUNXIAO_ACCESS_TOKEN的云效token`);
49
+ log(`将使用来自环境变量YUNXIAO_ACCESS_TOKEN的云效token`);
49
50
  }
50
51
  return token;
51
52
  }
@@ -62,7 +63,7 @@ export function getYunxiaoToken(pipelineConfig) {
62
63
  if (token) {
63
64
  if (isFirstFoundToken) {
64
65
  isFirstFoundToken = false;
65
- console.log(`将使用来自${userDeployHelperDir}的云效token`);
66
+ log(`将使用来自${userDeployHelperDir}的云效token`);
66
67
  }
67
68
  return token;
68
69
  }
@@ -109,7 +110,7 @@ export async function triggerPipeline(pipelineName) {
109
110
  }
110
111
  const runId = await createPipelineRunFunc(organizationId, pipelineID, {});
111
112
  const pipelineRunDetailUrl = `https://flow.aliyun.com/pipelines/${pipelineID}/builds/${runId}`;
112
- console.log(`流水线${name}[${pipelineID}]触发成功,流水线执行id: ${runId}, 流水线执行详情: ${pipelineRunDetailUrl}`);
113
+ log(`流水线${name}[${pipelineID}]触发成功,流水线执行id: ${runId}, 流水线执行详情: ${pipelineRunDetailUrl}`);
113
114
  }
114
115
 
115
116
 
@@ -145,14 +146,14 @@ export function checkYunxiaoToken(config, mode) {
145
146
  }
146
147
 
147
148
  async function runSinglePipeline(pipeline, index, total) {
148
- console.log(`开始处理流水线: ${pipeline.name}, 当前是第${index + 1}个, 总共${total}个`);
149
+ log(`开始处理流水线: ${pipeline.name}, 当前是第${index + 1}个, 总共${total}个`);
149
150
  let pipelineId = pipeline.id || "";
150
151
  if (!pipelineId) {
151
152
  // 获取流水线信息
152
153
  const pipelineInfo = await getPipelineInfoByName(pipeline.name);
153
154
  pipelineId = pipelineInfo.id;
154
155
  }
155
- console.log(`流水线${pipeline.name}的id: ${pipelineId}`);
156
+ log(`流水线${pipeline.name}的id: ${pipelineId}`);
156
157
 
157
158
  // 处理分支强推的问题
158
159
  const force2Branch = pipeline.force2Branch;
@@ -160,32 +161,32 @@ async function runSinglePipeline(pipeline, index, total) {
160
161
  let repo = pipeline.repo || "./";
161
162
  repo = join(process.cwd(), repo);
162
163
  if (!fs.existsSync(repo)) {
163
- console.log(`仓库${repo}有未提交的修改, 跳过流水线处理`);
164
+ log(`仓库${repo}有未提交的修改, 跳过流水线处理`);
164
165
  return;
165
166
  }
166
167
  // 强推到指定分支
167
168
  const git = simpleGit(repo);
168
169
  const gitStatus = await git.status();
169
170
  if (!gitStatus.isClean()) {
170
- console.log(`仓库${repo}有未提交的修改, 跳过流水线处理`);
171
+ log(`仓库${repo}有未提交的修改, 跳过流水线处理`);
171
172
  return;
172
173
  }
173
174
  if (gitStatus.current !== force2Branch.src) {
174
- console.log(`仓库${repo}当前分支不是${force2Branch.src}, 切换到${force2Branch.src}`);
175
+ log(`仓库${repo}当前分支不是${force2Branch.src}, 切换到${force2Branch.src}`);
175
176
  await git.checkout(force2Branch.src);
176
- console.log(`仓库${repo}切换到${force2Branch.src}完成`);
177
+ log(`仓库${repo}切换到${force2Branch.src}完成`);
177
178
  }
178
179
  await git.pull();
179
180
  await git.push();
180
181
  // git push origin master-test-0513:test --force
181
182
  await git.raw("push", "origin", `${force2Branch.src}:${force2Branch.dest}`, "--force");
182
- console.log(`仓库${repo}强推${force2Branch.src}到${force2Branch.dest}完成`);
183
+ log(`仓库${repo}强推${force2Branch.src}到${force2Branch.dest}完成`);
183
184
  }
184
185
  // TODO: PERF: 获取流水线信息后, 可以缓存下来, 避免每次都重新获取
185
186
  // TODO: 触发流水线时, 可以传入参数, 比如分支, 比如环境, 但是不知道为什么覆盖不了。这里先不传了
186
187
  const runId = await createPipelineRunFunc(organizationId, pipelineId, {});
187
188
  const piplineRunDetailUrl = `https://flow.aliyun.com/pipelines/${pipelineId}/builds/${runId}`;
188
- console.log(`流水线${pipeline.name}触发成功,流水线执行id: ${runId}, 流水线执行详情: ${piplineRunDetailUrl}`);
189
+ log(`流水线${pipeline.name}触发成功,流水线执行id: ${runId}, 流水线执行详情: ${piplineRunDetailUrl}`);
189
190
  }
190
191
 
191
192
  export async function runPipeline(config, mode) {
@@ -196,7 +197,7 @@ export async function runPipeline(config, mode) {
196
197
  }
197
198
  const token = getYunxiaoToken(pipelineConfig);
198
199
  if (!token) {
199
- console.log(`未设置云效token, 此次流水线未自动执行: ${JSON.stringify(pipelineConfig)}`);
200
+ log(`未设置云效token, 此次流水线未自动执行: ${JSON.stringify(pipelineConfig)}`);
200
201
  }
201
202
  process.env.YUNXIAO_ACCESS_TOKEN = token;
202
203
 
package/lib/util.mjs ADDED
@@ -0,0 +1,17 @@
1
+ let _isDebug = false;
2
+ export function setDebug(debug) {
3
+ _isDebug = debug;
4
+ }
5
+
6
+ export function isDebug() {
7
+ return _isDebug;
8
+ }
9
+
10
+ export function log(...args) {
11
+ if (_isDebug) {
12
+ // 打印时间
13
+ console.log(`[${new Date().toLocaleTimeString()}]`, ...args);
14
+ } else {
15
+ console.log(...args);
16
+ }
17
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taole/deploy-helper",
3
- "version": "0.3.5",
3
+ "version": "0.3.7",
4
4
  "description": "脚本部署工具,用于将项目部署到测试环境或生产环境",
5
5
  "main": "index.mjs",
6
6
  "type": "module",