cross-release-cli 0.0.1-alpha.4 → 0.1.0-alpha.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/README.md +40 -41
- package/bin/{cross-release.js → cross-release.mjs} +2 -1
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +1 -0
- package/package.json +13 -11
- package/dist/index.mjs +0 -401
package/README.md
CHANGED
|
@@ -22,9 +22,9 @@ yarn add cross-release --global
|
|
|
22
22
|
|
|
23
23
|
```json
|
|
24
24
|
{
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
"scripts": {
|
|
26
|
+
"release": "cross-release"
|
|
27
|
+
}
|
|
28
28
|
}
|
|
29
29
|
```
|
|
30
30
|
|
|
@@ -36,17 +36,17 @@ pnpm run release
|
|
|
36
36
|
|
|
37
37
|
## Command line
|
|
38
38
|
|
|
39
|
-
| short | long | description
|
|
40
|
-
| ----- | --------------- |
|
|
41
|
-
| -
|
|
42
|
-
| -
|
|
43
|
-
| -
|
|
44
|
-
| -
|
|
45
|
-
| -c | --commit | Commit current changes
|
|
46
|
-
| -p | --push | Push the project to remote
|
|
47
|
-
| -t | --tag | Create a tag for current version
|
|
48
|
-
| -e | --exclude [dir] | Folders to exclude from search
|
|
49
|
-
| -y | --yes | Answer yes to all prompts
|
|
39
|
+
| short | long | description | default |
|
|
40
|
+
| ----- | --------------- | --------------------------------------------------- | -------------------------- |
|
|
41
|
+
| -m | --main | Main project language e.g. java / javascript / rust | `false` |
|
|
42
|
+
| -r | --recursive | Run the command for each project in the workspace | `false` |
|
|
43
|
+
| -d | --dry | Dry run | `false` |
|
|
44
|
+
| -D | --dir [dir] | Set working directory | `project root` |
|
|
45
|
+
| -c | --commit | Commit current changes | `false` |
|
|
46
|
+
| -p | --push | Push the project to remote | `false` |
|
|
47
|
+
| -t | --tag | Create a tag for current version | `false` |
|
|
48
|
+
| -e | --exclude [dir] | Folders to exclude from search | `["node_modules", ".git"]` |
|
|
49
|
+
| -y | --yes | Answer yes to all prompts | `false` |
|
|
50
50
|
|
|
51
51
|
## Configuration
|
|
52
52
|
|
|
@@ -54,34 +54,33 @@ You can specify various runtime settings by using the "package.json" file. Here
|
|
|
54
54
|
|
|
55
55
|
```json
|
|
56
56
|
{
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
"...": "...",
|
|
58
|
+
"cross-release": {
|
|
59
59
|
// show the help message
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
60
|
+
"showHelp": false,
|
|
61
|
+
// show the version about cross-release
|
|
62
|
+
"showVersion": false,
|
|
63
|
+
"version": "",
|
|
64
|
+
"isAllYes": false,
|
|
65
|
+
"isDry": false,
|
|
66
|
+
"isRecursive": false,
|
|
67
|
+
"shouldCommit": false,
|
|
68
|
+
"shouldPush": false,
|
|
69
|
+
"shouldTag": false,
|
|
70
|
+
// default exclude folders are `["node_modules", ".git"]`, your config will be append within it
|
|
71
|
+
"excludes": ["path/to/exclude"],
|
|
72
|
+
"dir": "/path/to/run",
|
|
73
|
+
"commit": {
|
|
74
|
+
// Whether to invoke git pre-commit and commit-msg hook
|
|
75
|
+
"shouldVerify": true,
|
|
76
|
+
// Whether to stage all un-staged files or stage only changed files
|
|
77
|
+
"shouldStageAll": false,
|
|
78
|
+
// the symbol '%s' will be replace to the version number that you specified
|
|
79
|
+
"template": "chore: release v%s"
|
|
80
|
+
},
|
|
81
|
+
"push": {
|
|
82
|
+
"shouldFollowTags": false
|
|
83
|
+
}
|
|
84
84
|
}
|
|
85
|
-
}
|
|
86
85
|
}
|
|
87
86
|
```
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import W from"node:path";import F from"node:process";import{cancel as X,confirm as Z,intro as ee,isCancel as te,log as D,outro as se}from"@clack/prompts";import{findProjectFiles as T,getProjectVersion as oe,isVersionValid as ie,upgradeProjectVersion as re}from"cross-bump";import ae from"is-unicode-supported";import v from"picocolors";import N from"node:process";import U from"cac";import{getGitignores as I}from"cross-bump";import{defu as E}from"defu";import{loadConfig as K}from"unconfig";var O="0.1.0-alpha.1";import C from"node:process";var c={commit:{stageAll:!0,template:"chore: release v%s",verify:!0},cwd:C.cwd(),dry:!1,main:"javascript",push:{followTags:!1},recursive:!1,showVersion:!1,tag:{template:"v%s"},version:"",yes:!1};import G from"debug";function g(i){return G(`cross-release-cli:${i}`)}var k=g("cmd");async function Q(i){let{config:e}=await K({sources:[{files:"cross-release.config"},{extensions:["json"],files:"package",rewrite(t){return t["cross-release"]}}]});return k("load user config",e),E(e,i)}async function P(){let i=U("cross-release");i.version(O).usage("[version] [options]").option("-D, --dry",`Dry run (default: ${c.dry})`).option("-d, --dir [dir]","Set working directory (default: project root)").option("-e, --exclude [dir]","Folders to exclude from search").option("-m, --main",`Base project language (e.g. java, rust, javascript default: ${c.main})`).option("-r, --recursive",`Run the command for each project in the workspace (default: ${c.recursive})`).option("-y, --yes",`Answer yes to all prompts (default: ${c.yes})`).option("--no-commit","Skip committing changes").option("--no-push","Skip pushing").option("--no-tag","Skip tagging").help().parse();let{args:e,options:t}=i,r=await Q({...t,commit:t.commit??c.commit,cwd:t.dir??c.cwd,dry:t.dry??c.dry,main:t.main??c.main,recursive:t.recursive??c.recursive,showVersion:t.version,tag:t.tag??c.tag,version:e[0],yes:t.yes??c.yes}),a=await I(r.cwd);for(let s of r.excludes)a.add(s);return r.excludes=[...a],k("parsedArgs:",r),i.options.help&&N.exit(0),r}import{log as B,spinner as w}from"@clack/prompts";import{execa as _}from"execa";import f from"picocolors";var h=g("git"),y=_({reject:!1});async function j(i){let{del:e=!1,dry:t=!1,force:r=!1,message:a,tagName:s}=i??{},o=w();o.start("creating tag...");let n=[];if(e?n.push("--delete"):!a||a?.length===0?B.warn("no message provided, is recommended to provide a message for create an annotated tag"):n.push("--annotate","--message",a),r&&n.push("--force"),n.push(s),h(`command: git tag ${n.join(" ")}`),!t){let{exitCode:l,failed:p,shortMessage:u,stderr:m,stdout:d}=await y("git",["tag",...n]);if(h("git tag stdout:",d,m),p)return o.stop(f.red(u),l),!1}return o.stop(`create git tag: ${f.blue(s)}`),!0}async function R(i){let{dry:e=!1,message:t,modifiedFiles:r=[],stageAll:a,verify:s}=i??{},o=w();o.start("committing...");let n=[];n.push("--message",t),!a&&r.length>0?n.push("--",...r):n.push("--all"),e&&n.push("--dry-run"),!s&&n.push("--no-verify"),h(`command: git commit ${n.join(" ")}`);let{exitCode:l,failed:p,shortMessage:u,stderr:m,stdout:d}=await y("git",["commit",...n]);return h("git commit stdout:",d,m),p?(o.stop(f.red(u),l),!1):(o.stop(`commit message: ${f.green(t)}`),!0)}async function $(i={}){let{branch:e,dry:t,followTags:r=!0,remote:a}=i,s=w();s.start("pushing...");let o=[];a&&(o.push(a),e&&o.push(e)),r&&o.push("--follow-tags"),t&&o.push("--dry-run"),h(`command: git push ${o.join(" ")}`);let{exitCode:n,failed:l,shortMessage:p,stderr:u,stdout:m}=await y("git",["push",...o]);if(h("git push stdout:",m,u),l)return s.stop(f.red(p),n),!1;let d=await H();return s.stop(`pushed to repo ${f.underline(d)}`),!0}async function H(){return(await y("git",["remote","get-url","origin"])).stdout.trim()}import{select as L,text as q}from"@clack/prompts";import{getNextVersions as Y,isVersionValid as z,parseVersion as J}from"cross-bump";async function A(i){let e=J(i),{nextMajor:t,nextMinor:r,nextPatch:a,nextPreMajor:s,nextPreMinor:o,nextPrePatch:n,nextRelease:l}=Y(e??void 0),p="custom",u=[{label:"custom...",value:p},{label:`next (${l})`,value:l},{label:`keep (${i})`,value:i??""},{label:`patch (${a})`,value:a},{label:`minor (${r})`,value:r},{label:`major (${t})`,value:t},{label:`pre-patch (${n})`,value:n},{label:`pre-minor (${o})`,value:o},{label:`pre-major (${s})`,value:s}],m=await L({initialValue:u[1].value??p,message:`Pick a project version. (current: ${i})`,options:u});return!m||m===p?await q({message:"Input your custom version number",placeholder:"version number",validate:d=>{if(!z(d))return"Invalid"}}):m}function b(i,e,t){let r=i[e],a=t??{};return typeof r=="boolean"?r?a:{}:{...a,...r}}var V=g("app");function ne(i){let e=ae()?"\u2502":"|";console.log(`${v.gray(e)} ${i}`)}function S(i){return te(i)&&(X("User cancel"),F.exit(2)),i}var x=class i{static async create(){let e=await P();return new i(e)}currentVersion="";modifiedFiles=[];nextVersion="";options;taskQueue=[];taskStatus="pending";constructor(e){this.options=e}formatMessageString(e,t){return e?.includes("%s")?e.replaceAll("%s",t):e+t}async run(){this.#n(),await this.#r(),await this.#a(),await this.#o(),V("taskQueue:",this.taskQueue);for await(let e of this.taskQueue){if(this.taskStatus==="failed")break;await e.exec()}this.#i()}#t(e){let t=this.taskQueue.length+1;return this.taskQueue.push(e)===t}#e(e){e||(this.taskStatus="failed")}#s(){this.options.dry&&(D.message(v.bgBlue(" DRY RUN ")),F.env.DRY="true")}async#o(){let{dry:e,yes:t}=this.options,r=async(s,o,n)=>{if(t)this.options[s]=!0;else if(this.options[s]){let l=await Z({message:o});this.options[s]=S(l)}this.options[s]&&this.#t({exec:n,name:s})},a;if(this.options.commit){let{stageAll:s,template:o,verify:n}=b(this.options,"commit",c.commit);a=this.formatMessageString(o,this.nextVersion),await r("commit","should commit?",async()=>{this.#e(await R({dry:e,message:a,modifiedFiles:this.modifiedFiles,stageAll:s,verify:n}))})}if(this.options.tag&&a!==void 0){let{template:s}=b(this.options,"tag",c.tag);await r("tag","should create tag?",async()=>{let o=this.formatMessageString(s,this.nextVersion);this.#e(await j({dry:e,message:a,tagName:o}))})}if(this.options.push){let{followTags:s}=b(this.options,"push",c.push);await r("push","should push to remote?",async()=>{this.#e(await $({dry:e,followTags:s}))})}}#i(){se("Done"),this.taskStatus="finished"}async#r(){let{cwd:e,excludes:t,main:r,version:a}=this.options,s=await T(e,t);if(s.length===0)throw new Error("can't found any project file in the project root");let o=s.find(l=>l.category===r);if(!o)throw new Error(`can't found ${r} project file in the project root`);let n=await oe(o);if(this.currentVersion=n??"",ie(a))this.nextVersion=a;else{let l=await A(this.currentVersion);this.nextVersion=S(l)}}async#a(){let{nextVersion:e,options:{cwd:t,excludes:r,recursive:a}}=this,s=await T(t,r,a);V(`found ${s.length} project files`),this.#t({exec:async()=>{await Promise.all(s.map(async o=>{try{await re(e,o),this.modifiedFiles.push(o.path),ne(`upgrade to ${v.blue(e)} for ${v.gray(W.relative(t,o.path))}`)}catch(n){this.taskStatus="failed",D.error(String(n))}}))},name:"upgradeVersion"})}#n(){ee("Cross release"),this.#s(),this.taskStatus="running"}},ce=await x.create();await ce.run();
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(n){return n}export{e as defineConfig};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cross-release-cli",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.0-alpha.1",
|
|
4
5
|
"description": "command line app for cross language bump utility",
|
|
5
6
|
"author": {
|
|
6
7
|
"name": "rainbowatcher",
|
|
@@ -16,26 +17,27 @@
|
|
|
16
17
|
"bugs": {
|
|
17
18
|
"url": "https://github.com/rainbowatcher/cross-release/issues"
|
|
18
19
|
},
|
|
19
|
-
"main": "dist/index.
|
|
20
|
+
"main": "dist/index.js",
|
|
20
21
|
"bin": {
|
|
21
22
|
"cross-release": "./bin/cross-release.js"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
|
-
"
|
|
25
|
-
"
|
|
25
|
+
"bin",
|
|
26
|
+
"dist"
|
|
26
27
|
],
|
|
27
28
|
"dependencies": {
|
|
28
29
|
"@clack/prompts": "^0.7.0",
|
|
29
30
|
"cac": "^6.7.14",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
31
|
+
"debug": "^4.3.5",
|
|
32
|
+
"defu": "^6.1.4",
|
|
33
|
+
"execa": "^9.3.0",
|
|
34
|
+
"is-unicode-supported": "^2.0.0",
|
|
35
|
+
"picocolors": "^1.0.1",
|
|
36
|
+
"unconfig": "^0.5.5",
|
|
37
|
+
"cross-bump": "0.1.0-alpha.1"
|
|
36
38
|
},
|
|
37
39
|
"scripts": {
|
|
38
40
|
"clean": "rimraf dist/*",
|
|
39
|
-
"build": "
|
|
41
|
+
"build": "tsup-node"
|
|
40
42
|
}
|
|
41
43
|
}
|
package/dist/index.mjs
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
import path$1 from 'path';
|
|
2
|
-
import { spinner, log, isCancel, intro, outro, cancel, select, text, confirm } from '@clack/prompts';
|
|
3
|
-
import { findProjectFiles, getProjectVersion, isVersionValid, upgradeProjectVersion, parseVersion, getNextVersions } from 'cross-bump';
|
|
4
|
-
import { red, blue, green, gray, bgBlue } from 'colorette';
|
|
5
|
-
import isUnicodeSupported from 'is-unicode-supported';
|
|
6
|
-
import * as path from 'node:path';
|
|
7
|
-
import * as fs from 'node:fs';
|
|
8
|
-
import cac from 'cac';
|
|
9
|
-
import { defu } from 'defu';
|
|
10
|
-
import { execa } from 'execa';
|
|
11
|
-
import debug$1 from 'debug';
|
|
12
|
-
|
|
13
|
-
var version = "0.0.1-alpha.4";
|
|
14
|
-
|
|
15
|
-
const configDefaults = {
|
|
16
|
-
showHelp: false,
|
|
17
|
-
showVersion: false,
|
|
18
|
-
version: "",
|
|
19
|
-
isAllYes: false,
|
|
20
|
-
isDry: false,
|
|
21
|
-
isRecursive: false,
|
|
22
|
-
shouldCommit: false,
|
|
23
|
-
shouldPublish: false,
|
|
24
|
-
shouldPush: false,
|
|
25
|
-
shouldTag: false,
|
|
26
|
-
excludes: ["node_modules", ".git"],
|
|
27
|
-
dir: process.cwd(),
|
|
28
|
-
commit: {
|
|
29
|
-
shouldVerify: true,
|
|
30
|
-
shouldStageAll: true,
|
|
31
|
-
template: "chore: release v%s"
|
|
32
|
-
},
|
|
33
|
-
push: {
|
|
34
|
-
shouldFollowTags: false
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
function loadUserConfig(overrides) {
|
|
38
|
-
const file = fs.readFileSync(path.resolve(process.cwd(), "package.json"), "utf-8");
|
|
39
|
-
const userConfig = JSON.parse(file)["cross-release"];
|
|
40
|
-
return defu(overrides, userConfig, configDefaults);
|
|
41
|
-
}
|
|
42
|
-
function parseOptions() {
|
|
43
|
-
const cli = cac("cross-release").version(version).usage("[flags] version").option("-r, --recursive", "Run the command for each project in the workspace (default: false)").option("-d, --dry", "Dry run (default: false)").option("-D, --dir [dir]", "Set working directory (default: project root)").option("-p, --publish", "Publish the project (default: false)").option("-c, --commit", "Commit current changes (default: false)").option("-p, --push", "Push the project to remote (default: false)").option("-t, --tag", "Create a tag for current version (default: false)").option("-e, --exclude [dir]", "Folders to exclude from search (default: [node_modules, .git])").option("-y, --yes", "Answer yes to all prompts (default: false)").help().parse();
|
|
44
|
-
const { args, options } = cli;
|
|
45
|
-
const parsedArgs = loadUserConfig({
|
|
46
|
-
dir: options.dir,
|
|
47
|
-
excludes: options.exclude,
|
|
48
|
-
isRecursive: options.recursive,
|
|
49
|
-
isDry: options.dry,
|
|
50
|
-
isAllYes: options.yes,
|
|
51
|
-
showHelp: options.help,
|
|
52
|
-
showVersion: options.version,
|
|
53
|
-
shouldCommit: options.commit,
|
|
54
|
-
shouldPublish: options.publish,
|
|
55
|
-
shouldPush: options.push,
|
|
56
|
-
shouldTag: options.tag,
|
|
57
|
-
version: args[0]
|
|
58
|
-
});
|
|
59
|
-
return parsedArgs;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function createDebug(ns) {
|
|
63
|
-
return debug$1(`cross-release-cli:${ns}`);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const debug = createDebug("git");
|
|
67
|
-
async function gitTag(tagName, options) {
|
|
68
|
-
const s = spinner();
|
|
69
|
-
s.start("creating tag");
|
|
70
|
-
const { isForce = false, isDel = false, message } = options || {};
|
|
71
|
-
const args = [];
|
|
72
|
-
if (isDel) {
|
|
73
|
-
args.push("--delete");
|
|
74
|
-
} else {
|
|
75
|
-
if (!message || message?.length === 0) {
|
|
76
|
-
log.warn("no message provided, is recommended to provide a message for create an annotated tag");
|
|
77
|
-
} else {
|
|
78
|
-
args.push(
|
|
79
|
-
// Create an annotated tag, which is recommended for releases.
|
|
80
|
-
// See https://git-scm.com/docs/git-tag
|
|
81
|
-
"--annotate",
|
|
82
|
-
// Use the same commit message for the tag
|
|
83
|
-
"--message",
|
|
84
|
-
// formatMessageString(template, nextVersion),
|
|
85
|
-
message
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (isForce)
|
|
90
|
-
args.push("--force");
|
|
91
|
-
args.push(tagName);
|
|
92
|
-
if (!process.env.DRY) {
|
|
93
|
-
try {
|
|
94
|
-
const { command } = await execa("git", ["tag", ...args]);
|
|
95
|
-
debug(`command: ${command}`);
|
|
96
|
-
} catch (e) {
|
|
97
|
-
s.stop(red(e.shortMessage));
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
s.stop(`create git tag: ${blue(tagName)}`);
|
|
102
|
-
return true;
|
|
103
|
-
}
|
|
104
|
-
async function gitCommit(message, options) {
|
|
105
|
-
const s = spinner();
|
|
106
|
-
s.start("committing");
|
|
107
|
-
const { modifiedFiles = [], shouldStageAll, shouldVerify } = options || {};
|
|
108
|
-
const args = [];
|
|
109
|
-
if (process.env.DRY) {
|
|
110
|
-
args.push("--dry-run");
|
|
111
|
-
}
|
|
112
|
-
args.push("--message", message);
|
|
113
|
-
if (!shouldStageAll && modifiedFiles.length) {
|
|
114
|
-
args.push("--", ...modifiedFiles);
|
|
115
|
-
} else {
|
|
116
|
-
args.push("--all");
|
|
117
|
-
}
|
|
118
|
-
if (!shouldVerify) {
|
|
119
|
-
args.push("--no-verify");
|
|
120
|
-
}
|
|
121
|
-
try {
|
|
122
|
-
const { command } = await execa("git", ["commit", ...args]);
|
|
123
|
-
debug(`command: ${command}`);
|
|
124
|
-
s.stop(`commit message: ${green(message)}`);
|
|
125
|
-
} catch (e) {
|
|
126
|
-
s.stop(red(e.shortMessage));
|
|
127
|
-
return false;
|
|
128
|
-
}
|
|
129
|
-
return true;
|
|
130
|
-
}
|
|
131
|
-
async function gitPush(options) {
|
|
132
|
-
const { shouldFollowTags = true, remote, branch } = options || {};
|
|
133
|
-
const s = spinner();
|
|
134
|
-
s.start("pushing");
|
|
135
|
-
const originUrl = await gitOriginUrl();
|
|
136
|
-
const args = [];
|
|
137
|
-
if (shouldFollowTags) {
|
|
138
|
-
args.push("--follow-tags");
|
|
139
|
-
}
|
|
140
|
-
if (remote) {
|
|
141
|
-
args.push(remote);
|
|
142
|
-
if (branch) {
|
|
143
|
-
args.push(branch);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
if (process.env.DRY) {
|
|
147
|
-
args.push("--dry-run");
|
|
148
|
-
}
|
|
149
|
-
try {
|
|
150
|
-
const { command } = await execa("git", ["push", ...args]);
|
|
151
|
-
debug(`command: ${command}`);
|
|
152
|
-
s.stop(`pushed to repo: ${gray(originUrl)}`);
|
|
153
|
-
} catch (e) {
|
|
154
|
-
s.stop(red(e.shortMessage));
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
async function gitOriginUrl() {
|
|
160
|
-
return (await execa("git", ["remote", "get-url", "origin"])).stdout.trim();
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
var ExitCode = /* @__PURE__ */ ((ExitCode2) => {
|
|
164
|
-
ExitCode2[ExitCode2["Success"] = 0] = "Success";
|
|
165
|
-
ExitCode2[ExitCode2["FatalError"] = 1] = "FatalError";
|
|
166
|
-
ExitCode2[ExitCode2["InvalidArgument"] = 9] = "InvalidArgument";
|
|
167
|
-
return ExitCode2;
|
|
168
|
-
})(ExitCode || {});
|
|
169
|
-
|
|
170
|
-
var __accessCheck = (obj, member, msg) => {
|
|
171
|
-
if (!member.has(obj))
|
|
172
|
-
throw TypeError("Cannot " + msg);
|
|
173
|
-
};
|
|
174
|
-
var __privateAdd = (obj, member, value) => {
|
|
175
|
-
if (member.has(obj))
|
|
176
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
177
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
178
|
-
};
|
|
179
|
-
var __privateMethod = (obj, member, method) => {
|
|
180
|
-
__accessCheck(obj, member, "access private method");
|
|
181
|
-
return method;
|
|
182
|
-
};
|
|
183
|
-
var _checkDryRun, checkDryRun_fn, _getNextVersion, getNextVersion_fn, _getProjects, getProjects_fn, _confirmReleaseOptions, confirmReleaseOptions_fn, _addTask, addTask_fn, _start, start_fn, _done, done_fn, _check, check_fn;
|
|
184
|
-
function message(msg) {
|
|
185
|
-
const bar = isUnicodeSupported() ? "\u2502" : "|";
|
|
186
|
-
console.log(`${gray(bar)} ${msg}`);
|
|
187
|
-
}
|
|
188
|
-
function handleUserCancel() {
|
|
189
|
-
cancel("User cancel");
|
|
190
|
-
process.exit(ExitCode.InvalidArgument);
|
|
191
|
-
}
|
|
192
|
-
async function chooseVersion(currentVersion) {
|
|
193
|
-
const versionObj = parseVersion(currentVersion);
|
|
194
|
-
const {
|
|
195
|
-
nextMajor,
|
|
196
|
-
nextMinor,
|
|
197
|
-
nextPatch,
|
|
198
|
-
nextRelease,
|
|
199
|
-
nextPreMajor,
|
|
200
|
-
nextPreMinor,
|
|
201
|
-
nextPrePatch
|
|
202
|
-
} = getNextVersions(versionObj ?? void 0);
|
|
203
|
-
const C_CUSTOM = "custom";
|
|
204
|
-
const versions = [
|
|
205
|
-
{ label: "custom...", value: C_CUSTOM },
|
|
206
|
-
{ label: `next (${nextRelease})`, value: nextRelease },
|
|
207
|
-
{ label: `keep (${currentVersion})`, value: currentVersion || "" },
|
|
208
|
-
{ label: `patch (${nextPatch})`, value: nextPatch },
|
|
209
|
-
{ label: `minor (${nextMinor})`, value: nextMinor },
|
|
210
|
-
{ label: `major (${nextMajor})`, value: nextMajor },
|
|
211
|
-
{ label: `pre-patch (${nextPrePatch})`, value: nextPrePatch },
|
|
212
|
-
{ label: `pre-minor (${nextPreMinor})`, value: nextPreMinor },
|
|
213
|
-
{ label: `pre-major (${nextPreMajor})`, value: nextPreMajor }
|
|
214
|
-
];
|
|
215
|
-
const selectedValue = await select({
|
|
216
|
-
message: `Pick a project version. (current: ${currentVersion})`,
|
|
217
|
-
options: versions,
|
|
218
|
-
initialValue: versions[1].value ?? C_CUSTOM
|
|
219
|
-
});
|
|
220
|
-
if (!selectedValue || selectedValue === C_CUSTOM) {
|
|
221
|
-
return await text({
|
|
222
|
-
message: "Input your custom version number",
|
|
223
|
-
placeholder: "version number",
|
|
224
|
-
validate: (value) => {
|
|
225
|
-
if (!isVersionValid(value)) {
|
|
226
|
-
return "Invalid";
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
} else {
|
|
231
|
-
return selectedValue;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
class App {
|
|
235
|
-
constructor() {
|
|
236
|
-
__privateAdd(this, _checkDryRun);
|
|
237
|
-
__privateAdd(this, _getNextVersion);
|
|
238
|
-
__privateAdd(this, _getProjects);
|
|
239
|
-
__privateAdd(this, _confirmReleaseOptions);
|
|
240
|
-
__privateAdd(this, _addTask);
|
|
241
|
-
__privateAdd(this, _start);
|
|
242
|
-
__privateAdd(this, _done);
|
|
243
|
-
__privateAdd(this, _check);
|
|
244
|
-
this.currentVersion = "";
|
|
245
|
-
this.nextVersion = "";
|
|
246
|
-
this.modifiedFiles = [];
|
|
247
|
-
this.taskQueue = [];
|
|
248
|
-
this.taskStatus = "pending";
|
|
249
|
-
this.options = parseOptions();
|
|
250
|
-
}
|
|
251
|
-
async run() {
|
|
252
|
-
__privateMethod(this, _start, start_fn).call(this);
|
|
253
|
-
await __privateMethod(this, _getNextVersion, getNextVersion_fn).call(this);
|
|
254
|
-
await __privateMethod(this, _getProjects, getProjects_fn).call(this);
|
|
255
|
-
await __privateMethod(this, _confirmReleaseOptions, confirmReleaseOptions_fn).call(this);
|
|
256
|
-
for await (const task of this.taskQueue) {
|
|
257
|
-
if (this.taskStatus === "failed") {
|
|
258
|
-
break;
|
|
259
|
-
} else {
|
|
260
|
-
await task.exec();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
__privateMethod(this, _done, done_fn).call(this);
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Accepts a message string template (e.g. "release %s" or "This is the %s release").
|
|
267
|
-
* If the template contains any "%s" placeholders, then they are replaced with the version number;
|
|
268
|
-
* otherwise, the version number is appended to the string.
|
|
269
|
-
*/
|
|
270
|
-
formatMessageString(template, nextVersion) {
|
|
271
|
-
if (template.includes("%s")) {
|
|
272
|
-
return template.replace(/%s/g, nextVersion);
|
|
273
|
-
} else {
|
|
274
|
-
return template + nextVersion;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
_checkDryRun = new WeakSet();
|
|
279
|
-
checkDryRun_fn = function() {
|
|
280
|
-
if (this.options.isDry) {
|
|
281
|
-
log.message(bgBlue(" DRY RUN "));
|
|
282
|
-
process.env.DRY = "true";
|
|
283
|
-
}
|
|
284
|
-
};
|
|
285
|
-
_getNextVersion = new WeakSet();
|
|
286
|
-
getNextVersion_fn = async function() {
|
|
287
|
-
const { dir, excludes, version } = this.options;
|
|
288
|
-
const projectFile = await findProjectFiles(dir, excludes);
|
|
289
|
-
if (!projectFile.length) {
|
|
290
|
-
throw new Error("can't found any project file in the project root");
|
|
291
|
-
}
|
|
292
|
-
const projectVersion = await getProjectVersion(projectFile[0]);
|
|
293
|
-
this.currentVersion = projectVersion || "";
|
|
294
|
-
if (isVersionValid(version)) {
|
|
295
|
-
this.nextVersion = version;
|
|
296
|
-
} else {
|
|
297
|
-
const nextVersion = await chooseVersion(this.currentVersion);
|
|
298
|
-
if (isCancel(nextVersion)) {
|
|
299
|
-
handleUserCancel();
|
|
300
|
-
} else {
|
|
301
|
-
this.nextVersion = nextVersion;
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
_getProjects = new WeakSet();
|
|
306
|
-
getProjects_fn = async function() {
|
|
307
|
-
const { options: { dir, excludes, isRecursive }, nextVersion } = this;
|
|
308
|
-
const projectFiles = await findProjectFiles(dir, excludes, isRecursive);
|
|
309
|
-
__privateMethod(this, _addTask, addTask_fn).call(this, {
|
|
310
|
-
name: "upgradeVersion",
|
|
311
|
-
exec: () => {
|
|
312
|
-
return Promise.all(projectFiles.map(async (projectFile) => {
|
|
313
|
-
try {
|
|
314
|
-
await upgradeProjectVersion(nextVersion, projectFile);
|
|
315
|
-
this.modifiedFiles.push(projectFile.path);
|
|
316
|
-
message(`upgrade to ${blue(nextVersion)} for ${gray(path$1.relative(dir, projectFile.path))}`);
|
|
317
|
-
} catch (e) {
|
|
318
|
-
this.taskStatus = "failed";
|
|
319
|
-
log.error(String(e));
|
|
320
|
-
}
|
|
321
|
-
}));
|
|
322
|
-
}
|
|
323
|
-
});
|
|
324
|
-
};
|
|
325
|
-
_confirmReleaseOptions = new WeakSet();
|
|
326
|
-
confirmReleaseOptions_fn = async function() {
|
|
327
|
-
const { isAllYes, commit } = this.options;
|
|
328
|
-
const confirmAndSet = async (optionName, message3, taskName, execFn) => {
|
|
329
|
-
if (isAllYes) {
|
|
330
|
-
this.options[optionName] = true;
|
|
331
|
-
} else if (!this.options[optionName]) {
|
|
332
|
-
const confirmation = await confirm({ message: message3 });
|
|
333
|
-
if (!isCancel(confirmation)) {
|
|
334
|
-
this.options[optionName] = confirmation;
|
|
335
|
-
} else {
|
|
336
|
-
handleUserCancel();
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
if (this.options[optionName]) {
|
|
340
|
-
__privateMethod(this, _addTask, addTask_fn).call(this, {
|
|
341
|
-
name: taskName,
|
|
342
|
-
exec: execFn
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
const message2 = this.formatMessageString(commit.template, this.nextVersion);
|
|
347
|
-
await confirmAndSet(
|
|
348
|
-
"shouldCommit",
|
|
349
|
-
"should commit?",
|
|
350
|
-
"commit",
|
|
351
|
-
async () => {
|
|
352
|
-
__privateMethod(this, _check, check_fn).call(this, await gitCommit(message2, {
|
|
353
|
-
modifiedFiles: this.modifiedFiles,
|
|
354
|
-
shouldStageAll: commit.shouldStageAll,
|
|
355
|
-
shouldVerify: commit.shouldVerify
|
|
356
|
-
}));
|
|
357
|
-
}
|
|
358
|
-
);
|
|
359
|
-
const tagName = `v${this.nextVersion}`;
|
|
360
|
-
await confirmAndSet(
|
|
361
|
-
"shouldTag",
|
|
362
|
-
"should create tag?",
|
|
363
|
-
"tag",
|
|
364
|
-
async () => {
|
|
365
|
-
__privateMethod(this, _check, check_fn).call(this, await gitTag(tagName, { message: message2 }));
|
|
366
|
-
}
|
|
367
|
-
);
|
|
368
|
-
await confirmAndSet(
|
|
369
|
-
"shouldPush",
|
|
370
|
-
"should push to remote?",
|
|
371
|
-
"push",
|
|
372
|
-
async () => {
|
|
373
|
-
__privateMethod(this, _check, check_fn).call(this, await gitPush({ shouldFollowTags: this.options.push.shouldFollowTags }));
|
|
374
|
-
}
|
|
375
|
-
);
|
|
376
|
-
};
|
|
377
|
-
_addTask = new WeakSet();
|
|
378
|
-
addTask_fn = function(task) {
|
|
379
|
-
const expect = this.taskQueue.length + 1;
|
|
380
|
-
return this.taskQueue.push(task) === expect;
|
|
381
|
-
};
|
|
382
|
-
_start = new WeakSet();
|
|
383
|
-
start_fn = function() {
|
|
384
|
-
intro("Cross release");
|
|
385
|
-
__privateMethod(this, _checkDryRun, checkDryRun_fn).call(this);
|
|
386
|
-
this.taskStatus = "running";
|
|
387
|
-
};
|
|
388
|
-
_done = new WeakSet();
|
|
389
|
-
done_fn = function() {
|
|
390
|
-
outro("Done");
|
|
391
|
-
this.taskStatus = "finished";
|
|
392
|
-
};
|
|
393
|
-
_check = new WeakSet();
|
|
394
|
-
check_fn = function(status) {
|
|
395
|
-
if (!status) {
|
|
396
|
-
this.taskStatus = "failed";
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
var app = new App();
|
|
400
|
-
|
|
401
|
-
void app.run();
|