@seayoo-web/scripts 1.3.15 → 2.0.1
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/dist/{git-Bd789okO.js → git-w5-27jZ7.js} +15 -14
- package/dist/index.js +1 -1
- package/dist/node.js +7 -7
- package/package.json +1 -1
- package/types/node.d.ts +1 -1
- package/types/src/destroy.d.ts +3 -0
- package/types/src/git.d.ts +2 -2
- package/types/src/postcss.d.ts +0 -7
|
@@ -34,8 +34,8 @@ async function getRepos(project) {
|
|
|
34
34
|
const projectDir = path.join(root, project);
|
|
35
35
|
const dirs = await fs.readdir(projectDir);
|
|
36
36
|
const repos = dirs.filter((item) => fs.statSync(path.join(projectDir, item)).isDirectory());
|
|
37
|
-
const
|
|
38
|
-
return repos.map((dir, index) => ({ id: dir, desc:
|
|
37
|
+
const descArr = await Promise.all(repos.map((repo) => getRepoDesc(project, repo)));
|
|
38
|
+
return repos.map((dir, index) => ({ id: dir, desc: descArr[index] })).filter((item) => item.desc !== null);
|
|
39
39
|
}
|
|
40
40
|
async function getRepoDesc(project, dir) {
|
|
41
41
|
const root = await getMonorepoRoot();
|
|
@@ -59,9 +59,9 @@ async function getProjects(returnAll) {
|
|
|
59
59
|
return [];
|
|
60
60
|
}
|
|
61
61
|
async function getProjectName(project) {
|
|
62
|
-
const
|
|
63
|
-
if (await fs.exists(
|
|
64
|
-
const name = await fs.readFile(
|
|
62
|
+
const nameOfFile = path.join(project, ".name");
|
|
63
|
+
if (await fs.exists(nameOfFile)) {
|
|
64
|
+
const name = await fs.readFile(nameOfFile, "utf8");
|
|
65
65
|
return name.trim().replace(/\n[\d\D]+/g, "");
|
|
66
66
|
}
|
|
67
67
|
return project;
|
|
@@ -127,7 +127,7 @@ function fillZ(a) {
|
|
|
127
127
|
const MainBranchName = "main";
|
|
128
128
|
const DeployTagPrefix = "deploy_";
|
|
129
129
|
const BackupTagPrefix = "backup_";
|
|
130
|
-
function
|
|
130
|
+
function convertToDeployTagName(deployTo) {
|
|
131
131
|
return `${DeployTagPrefix}${deployTo.toLowerCase().replace(/(?:^https?:\/\/|\/*$)/gi, "").replace(/\//g, "_")}`;
|
|
132
132
|
}
|
|
133
133
|
async function execCmd(cmd, ignoreWarning = false) {
|
|
@@ -162,7 +162,7 @@ async function getCommitInfo(command, mode, page, deployTo) {
|
|
|
162
162
|
console.error(`正式环境部署需要在 ${`${MainBranchName}分支`.bgRed} 操作!`.red);
|
|
163
163
|
process.exit(1);
|
|
164
164
|
}
|
|
165
|
-
const unCommitChanges = await
|
|
165
|
+
const unCommitChanges = await countUnSubmitChanges(MainBranchName);
|
|
166
166
|
if (unCommitChanges > 0) {
|
|
167
167
|
console.error("正式环境部署需要先将代码同步到服务器!".red, `发现 ${unCommitChanges} 个 commit 差异`.red);
|
|
168
168
|
process.exit(1);
|
|
@@ -175,11 +175,11 @@ async function getCommitInfo(command, mode, page, deployTo) {
|
|
|
175
175
|
async function getLastDeployTag(deployTo) {
|
|
176
176
|
await fetchTags();
|
|
177
177
|
const deployTags = await getDeployTags();
|
|
178
|
-
const tag =
|
|
178
|
+
const tag = convertToDeployTagName(deployTo);
|
|
179
179
|
return deployTags.includes(tag) ? tag : "";
|
|
180
180
|
}
|
|
181
181
|
async function createPageDeployTag(page, deployTo, finderUser) {
|
|
182
|
-
const tagName =
|
|
182
|
+
const tagName = convertToDeployTagName(deployTo);
|
|
183
183
|
const gitUser = await execCmd(`git config user.email`).catch(() => "");
|
|
184
184
|
const user = (gitUser || finderUser).replace(/@.+/g, "");
|
|
185
185
|
await execCmd(
|
|
@@ -208,6 +208,7 @@ async function getCommitLogs(branchOrCommit, sinceCommit, codePath) {
|
|
|
208
208
|
const cmd = [
|
|
209
209
|
"git log",
|
|
210
210
|
sinceCommit ? `${sinceCommit}..${branchOrCommit || "HEAD"}` : branchOrCommit || "",
|
|
211
|
+
/** spell-checker:disable-next-line */
|
|
211
212
|
`--oneline --pretty=format:"[%cd][%h] %s" --date=short -n 60`,
|
|
212
213
|
`-- ${codePath}`
|
|
213
214
|
].filter((f) => !!f).join(" ");
|
|
@@ -218,11 +219,11 @@ async function hasUncommittedChanges() {
|
|
|
218
219
|
const result = await execCmd("git status --porcelain");
|
|
219
220
|
return result !== "";
|
|
220
221
|
}
|
|
221
|
-
async function
|
|
222
|
+
async function countUnSubmitChanges(branch) {
|
|
222
223
|
const result = await execCmd(`git rev-list --count ${branch} "^origin/${branch}"`);
|
|
223
224
|
return parseInt(result, 10);
|
|
224
225
|
}
|
|
225
|
-
async function
|
|
226
|
+
async function checkGitStatusBeforeDestroy() {
|
|
226
227
|
if (await hasUncommittedChanges()) {
|
|
227
228
|
console.error(`在销毁前需要提交所有代码!`.red);
|
|
228
229
|
process.exit(1);
|
|
@@ -231,7 +232,7 @@ async function checkGitStatusBeforeDestory() {
|
|
|
231
232
|
console.error(`销毁操作需要在 ${`${MainBranchName}分支`.bgRed} 进行!`.red);
|
|
232
233
|
process.exit(1);
|
|
233
234
|
}
|
|
234
|
-
const unCommitChanges = await
|
|
235
|
+
const unCommitChanges = await countUnSubmitChanges(MainBranchName);
|
|
235
236
|
if (unCommitChanges > 0) {
|
|
236
237
|
console.error("销毁操作需要先将代码同步到服务器!".red, `发现 ${unCommitChanges} 个 commit 差异`.red);
|
|
237
238
|
process.exit(1);
|
|
@@ -241,7 +242,7 @@ async function createBackupTag(action, info) {
|
|
|
241
242
|
const tagName = `${BackupTagPrefix}${action}_${info.replace(/\//g, "-")}`;
|
|
242
243
|
const gitUser = await execCmd(`git config user.email`).catch(() => "");
|
|
243
244
|
const user = (gitUser || "unknown").replace(/@.+/g, "");
|
|
244
|
-
await execCmd(`git tag -f ${tagName} -m "${getNowTime()} destroyed by ${user}`);
|
|
245
|
+
await execCmd(`git tag -f ${tagName} -m "${getNowTime()} destroyed by ${user}"`);
|
|
245
246
|
try {
|
|
246
247
|
await execCmd(`git push origin -f ${tagName}`, true);
|
|
247
248
|
} catch (e) {
|
|
@@ -262,7 +263,7 @@ export {
|
|
|
262
263
|
getNowTime as g,
|
|
263
264
|
getProjects as h,
|
|
264
265
|
getTemplates as i,
|
|
265
|
-
|
|
266
|
+
checkGitStatusBeforeDestroy as j,
|
|
266
267
|
createBackupTag as k,
|
|
267
268
|
getRepos as l,
|
|
268
269
|
removeProjectFromWorkspace as r,
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import vueDevTools from "vite-plugin-vue-devtools";
|
|
|
7
7
|
import { existsSync, readFileSync } from "fs";
|
|
8
8
|
import { loadEnv } from "vite";
|
|
9
9
|
import "colors";
|
|
10
|
-
import { g as getNowTime, a as getCommitInfo, c as createPageDeployTag } from "./git-
|
|
10
|
+
import { g as getNowTime, a as getCommitInfo, c as createPageDeployTag } from "./git-w5-27jZ7.js";
|
|
11
11
|
import skipFormatting from "@vue/eslint-config-prettier/skip-formatting";
|
|
12
12
|
import { vueTsConfigs, defineConfigWithVueTs } from "@vue/eslint-config-typescript";
|
|
13
13
|
import { flatConfigs } from "eslint-plugin-import";
|
package/dist/node.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Command } from "commander";
|
|
|
5
5
|
import fs from "fs-extra";
|
|
6
6
|
import inquirer from "inquirer";
|
|
7
7
|
import ora from "ora";
|
|
8
|
-
import { b as getMonorepoRoot, d as addProjectToWorkspace, e as copyTemplate, f as copyGlobalFiles, h as getProjects, i as getTemplates, j as
|
|
8
|
+
import { b as getMonorepoRoot, d as addProjectToWorkspace, e as copyTemplate, f as copyGlobalFiles, h as getProjects, i as getTemplates, j as checkGitStatusBeforeDestroy, k as createBackupTag, r as removeProjectFromWorkspace, s as submitAllDeletionChanges, l as getRepos } from "./git-w5-27jZ7.js";
|
|
9
9
|
const commitRE = /^(?:revert: )?(?:feat|fix|docs|style|refactor|test|build|chore|debug|tweak|improve)(?:\(.+\))?: .{1,100}/;
|
|
10
10
|
function checkCommit() {
|
|
11
11
|
const msgPath = process.argv[2];
|
|
@@ -170,7 +170,7 @@ async function createRepo() {
|
|
|
170
170
|
program$1.action(startCreateJob$1);
|
|
171
171
|
const program = new Command();
|
|
172
172
|
program.version("1.0.0").argument("<target>");
|
|
173
|
-
function
|
|
173
|
+
function runDestroyScript() {
|
|
174
174
|
program.parse(process.argv);
|
|
175
175
|
}
|
|
176
176
|
async function startCreateJob(target) {
|
|
@@ -204,7 +204,7 @@ async function initProjectQuestions() {
|
|
|
204
204
|
}
|
|
205
205
|
async function destroyProject() {
|
|
206
206
|
const root = await getMonorepoRoot();
|
|
207
|
-
await
|
|
207
|
+
await checkGitStatusBeforeDestroy();
|
|
208
208
|
const questions = await initProjectQuestions();
|
|
209
209
|
const answers = await inquirer.prompt(questions);
|
|
210
210
|
if (!answers.confirm) {
|
|
@@ -218,7 +218,7 @@ async function destroyProject() {
|
|
|
218
218
|
spinner.text = "调整配置文件...";
|
|
219
219
|
await removeProjectFromWorkspace(answers.project);
|
|
220
220
|
spinner.text = "提交代码中...";
|
|
221
|
-
await submitAllDeletionChanges(`chore:
|
|
221
|
+
await submitAllDeletionChanges(`chore: destroy project ${answers.project}`);
|
|
222
222
|
spinner.succeed("项目已经销毁!".green);
|
|
223
223
|
}
|
|
224
224
|
async function initRepoQuestions() {
|
|
@@ -261,7 +261,7 @@ async function initRepoQuestions() {
|
|
|
261
261
|
}
|
|
262
262
|
async function destroyRepo() {
|
|
263
263
|
const root = await getMonorepoRoot();
|
|
264
|
-
await
|
|
264
|
+
await checkGitStatusBeforeDestroy();
|
|
265
265
|
const questions = await initRepoQuestions();
|
|
266
266
|
const answers = await inquirer.prompt(questions);
|
|
267
267
|
if (!answers.confirm) {
|
|
@@ -273,12 +273,12 @@ async function destroyRepo() {
|
|
|
273
273
|
const pageDir = path.join(root, answers.project, answers.page);
|
|
274
274
|
await fs.removeSync(pageDir);
|
|
275
275
|
spinner.text = "提交代码中...";
|
|
276
|
-
await submitAllDeletionChanges(`chore:
|
|
276
|
+
await submitAllDeletionChanges(`chore: destroy page ${answers.project}/${answers.page}`);
|
|
277
277
|
spinner.succeed("页面已经销毁!".green);
|
|
278
278
|
}
|
|
279
279
|
program.action(startCreateJob);
|
|
280
280
|
export {
|
|
281
281
|
checkCommit,
|
|
282
282
|
runCreateScript,
|
|
283
|
-
|
|
283
|
+
runDestroyScript
|
|
284
284
|
};
|
package/package.json
CHANGED
package/types/node.d.ts
CHANGED
package/types/src/git.d.ts
CHANGED
|
@@ -36,11 +36,11 @@ export declare function hasUncommittedChanges(): Promise<boolean>;
|
|
|
36
36
|
/**
|
|
37
37
|
* 检查尚未同步服务器的提交数量
|
|
38
38
|
*/
|
|
39
|
-
export declare function
|
|
39
|
+
export declare function countUnSubmitChanges(branch: string): Promise<number>;
|
|
40
40
|
/**
|
|
41
41
|
* 在删除工程或目录前检查 git 状态
|
|
42
42
|
*/
|
|
43
|
-
export declare function
|
|
43
|
+
export declare function checkGitStatusBeforeDestroy(): Promise<void>;
|
|
44
44
|
/**
|
|
45
45
|
* 创建备份 tag
|
|
46
46
|
*/
|