@varlet/release 0.2.2 → 0.2.4

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 CHANGED
@@ -68,8 +68,10 @@ npx vr publish
68
68
  | Params | Instructions |
69
69
  | ---------------------- | ------------------- |
70
70
  | -r --remote \<remote\> | Specify remote name |
71
- | -s --skip-npm-publish | Skip npm publish |
72
- | -sgt --skip-git-tag | Skip git tag |
71
+ | -s --skip-npm-publish | Skip npm publish |
72
+ | -sc --skip-changelog | Skip generate changelog |
73
+ | -sgt --skip-git-tag | Skip git tag |
74
+ | -nt --npm-tag \<npmTag\> | npm tag |
73
75
 
74
76
  #### changelog
75
77
 
@@ -89,9 +91,10 @@ npx vr publish
89
91
 
90
92
  #### publish
91
93
 
92
- ```shell
93
- vr publish
94
- ```
94
+ | Params | Instructions |
95
+ | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
96
+ | -c --check-remote-version | Detects whether the remote version of the npm package is the same as the package version to be published locally, and if it is, skip the release |
97
+ | -nt --npm-tag \<npmTag\> | npm tag |
95
98
 
96
99
  ### Custom Handle
97
100
 
@@ -120,12 +123,19 @@ release({ task })
120
123
  #### Types
121
124
 
122
125
  ```ts
123
- function publish(preRelease: boolean | undefined): Promise<void>
126
+ interface PublishCommandOptions {
127
+ preRelease?: boolean
128
+ checkRemoteVersion?: boolean
129
+ npmTag?: string
130
+ }
131
+ function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>
124
132
  function updateVersion(version: string): void
125
133
  interface ReleaseCommandOptions {
126
134
  remote?: string
127
135
  skipNpmPublish?: boolean
136
+ skipChangelog?: boolean
128
137
  skipGitTag?: boolean
138
+ npmTag?: string
129
139
  task?(): Promise<void>
130
140
  }
131
141
  function release(options: ReleaseCommandOptions): Promise<void>
package/README.zh-CN.md CHANGED
@@ -68,8 +68,10 @@ npx vr publish
68
68
  | 参数 | 说明 |
69
69
  | ---------------------- | ---------------- |
70
70
  | -r --remote \<remote\> | 指定远程仓库名称 |
71
- | -s --skip-npm-publish | 跳过 npm 发布 |
72
- | -sgt --skip-git-tag | 跳过 git tag |
71
+ | -s --skip-npm-publish | 跳过 npm 发布 |
72
+ | -sc --skip-changelog | 跳过生成变更日志 |
73
+ | -sgt --skip-git-tag | 跳过 git tag |
74
+ | -nt --npm-tag \<npmTag\> | npm tag |
73
75
 
74
76
  #### changelog
75
77
 
@@ -89,9 +91,10 @@ npx vr publish
89
91
 
90
92
  #### publish
91
93
 
92
- ```shell
93
- vr publish
94
- ```
94
+ | 参数 | 说明 |
95
+ | ------------------------- | --------------------------------------------------------------------- |
96
+ | -c --check-remote-version | 检测npm包的远程版本是否与要在本地发布的包版本相同,如果是,则跳过发布 |
97
+ | -nt --npm-tag \<npmTag\> | npm tag |
95
98
 
96
99
  ### 自定义处理
97
100
 
@@ -120,12 +123,19 @@ release({ task })
120
123
  #### 类型
121
124
 
122
125
  ```ts
123
- function publish(preRelease: boolean | undefined): Promise<void>
126
+ interface PublishCommandOptions {
127
+ preRelease?: boolean
128
+ checkRemoteVersion?: boolean
129
+ npmTag?: string
130
+ }
131
+ function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>
124
132
  function updateVersion(version: string): void
125
133
  interface ReleaseCommandOptions {
126
134
  remote?: string
127
135
  skipNpmPublish?: boolean
136
+ skipChangelog?: boolean
128
137
  skipGitTag?: boolean
138
+ npmTag?: string
129
139
  task?(): Promise<void>
130
140
  }
131
141
  function release(options: ReleaseCommandOptions): Promise<void>
package/bin/index.js CHANGED
@@ -8,14 +8,18 @@ program
8
8
  .command('release')
9
9
  .option('-r --remote <remote>', 'Remote name')
10
10
  .option('-s --skip-npm-publish', 'Skip npm publish')
11
+ .option('-sc --skip-changelog', 'Skip generate changelog')
11
12
  .option('-sgt --skip-git-tag', 'Skip git tag')
13
+ .option('-nt --npm-tag <npmTag>', 'Npm tag')
12
14
  .description('Release all packages and generate changelogs')
13
15
  .action(async (options) => release(options))
14
16
 
15
17
  program
16
18
  .command('publish')
19
+ .option('-c --check-remote-version', 'Check remote version')
20
+ .option('-nt --npm-tag <npmTag>', 'Npm tag')
17
21
  .description('Publish to npm')
18
- .action(async () => publish())
22
+ .action(async (options) => publish(options))
19
23
 
20
24
  program
21
25
  .command('changelog')
package/dist/index.cjs CHANGED
@@ -100,12 +100,29 @@ async function isWorktreeEmpty() {
100
100
  const ret = await (0, import_execa.execa)("git", ["status", "--porcelain"]);
101
101
  return !ret.stdout;
102
102
  }
103
- async function publish(preRelease) {
103
+ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
104
104
  const s = (0, import_nanospinner2.createSpinner)("Publishing all packages").start();
105
105
  const args = ["-r", "publish", "--no-git-checks", "--access", "public"];
106
+ if (checkRemoteVersion) {
107
+ const packageJson = getPackageJsons().find((packageJson2) => !packageJson2.config.private);
108
+ if (packageJson) {
109
+ const { config } = packageJson;
110
+ try {
111
+ await (0, import_execa.execa)("npm", ["view", `${config.name}@${config.version}`, "version"]);
112
+ s.warn({
113
+ text: `The npm package has a same remote version ${config.version}, publishing automatically skipped.`
114
+ });
115
+ return;
116
+ } catch {
117
+ }
118
+ }
119
+ }
106
120
  if (preRelease) {
107
121
  args.push("--tag", "alpha");
108
122
  }
123
+ if (npmTag) {
124
+ args.push("--tag", npmTag);
125
+ }
109
126
  const ret = await (0, import_execa.execa)("pnpm", args);
110
127
  if (ret.stderr && ret.stderr.includes("npm ERR!")) {
111
128
  throw new Error("\n" + ret.stderr);
@@ -126,14 +143,21 @@ async function pushGit(version, remote = "origin", skipGitTag = false) {
126
143
  s.success({ text: "Push remote repository successfully" });
127
144
  ret.stdout && logger_default.info(ret.stdout);
128
145
  }
146
+ function getPackageJsons() {
147
+ const packageJsons = ["package.json", ...import_glob.glob.sync("packages/*/package.json")];
148
+ return packageJsons.map((path) => {
149
+ const filePath = (0, import_path2.resolve)(cwd, path);
150
+ return {
151
+ config: readJSONSync(filePath),
152
+ filePath
153
+ };
154
+ });
155
+ }
129
156
  function updateVersion(version) {
130
- const packageJsons = import_glob.glob.sync("packages/*/package.json");
131
- packageJsons.push("package.json");
132
- packageJsons.forEach((path) => {
133
- const file = (0, import_path2.resolve)(cwd, path);
134
- const config = readJSONSync(file);
157
+ const packageJsons = getPackageJsons();
158
+ packageJsons.forEach(({ config, filePath }) => {
135
159
  config.version = version;
136
- writeFileSync(file, JSON.stringify(config, null, 2));
160
+ writeFileSync(filePath, JSON.stringify(config, null, 2));
137
161
  });
138
162
  }
139
163
  async function confirmRegistry() {
@@ -214,10 +238,12 @@ async function release(options) {
214
238
  await options.task();
215
239
  }
216
240
  if (!options.skipNpmPublish) {
217
- await publish(isPreRelease);
241
+ await publish({ preRelease: isPreRelease, npmTag: options.npmTag });
218
242
  }
219
243
  if (!isPreRelease) {
220
- await changelog();
244
+ if (!options.skipChangelog) {
245
+ await changelog();
246
+ }
221
247
  await pushGit(expectVersion, options.remote, options.skipGitTag);
222
248
  }
223
249
  logger_default.success(`Release version ${expectVersion} successfully!`);
package/dist/index.d.cts CHANGED
@@ -1,8 +1,15 @@
1
- declare function publish(preRelease: boolean | undefined): Promise<void>;
1
+ interface PublishCommandOptions {
2
+ preRelease?: boolean;
3
+ checkRemoteVersion?: boolean;
4
+ npmTag?: string;
5
+ }
6
+ declare function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>;
2
7
  declare function updateVersion(version: string): void;
3
8
  interface ReleaseCommandOptions {
4
9
  remote?: string;
10
+ npmTag?: string;
5
11
  skipNpmPublish?: boolean;
12
+ skipChangelog?: boolean;
6
13
  skipGitTag?: boolean;
7
14
  task?(): Promise<void>;
8
15
  }
@@ -25,4 +32,4 @@ interface CommitLintCommandOptions {
25
32
  }
26
33
  declare function commitLint(options: CommitLintCommandOptions): void;
27
34
 
28
- export { COMMIT_MESSAGE_RE, type ChangelogCommandOptions, type CommitLintCommandOptions, type ReleaseCommandOptions, changelog, commitLint, getCommitMessage, isVersionCommitMessage, publish, release, updateVersion };
35
+ export { COMMIT_MESSAGE_RE, type ChangelogCommandOptions, type CommitLintCommandOptions, type PublishCommandOptions, type ReleaseCommandOptions, changelog, commitLint, getCommitMessage, isVersionCommitMessage, publish, release, updateVersion };
package/dist/index.d.ts CHANGED
@@ -1,8 +1,15 @@
1
- declare function publish(preRelease: boolean | undefined): Promise<void>;
1
+ interface PublishCommandOptions {
2
+ preRelease?: boolean;
3
+ checkRemoteVersion?: boolean;
4
+ npmTag?: string;
5
+ }
6
+ declare function publish({ preRelease, checkRemoteVersion, npmTag }: PublishCommandOptions): Promise<void>;
2
7
  declare function updateVersion(version: string): void;
3
8
  interface ReleaseCommandOptions {
4
9
  remote?: string;
10
+ npmTag?: string;
5
11
  skipNpmPublish?: boolean;
12
+ skipChangelog?: boolean;
6
13
  skipGitTag?: boolean;
7
14
  task?(): Promise<void>;
8
15
  }
@@ -25,4 +32,4 @@ interface CommitLintCommandOptions {
25
32
  }
26
33
  declare function commitLint(options: CommitLintCommandOptions): void;
27
34
 
28
- export { COMMIT_MESSAGE_RE, type ChangelogCommandOptions, type CommitLintCommandOptions, type ReleaseCommandOptions, changelog, commitLint, getCommitMessage, isVersionCommitMessage, publish, release, updateVersion };
35
+ export { COMMIT_MESSAGE_RE, type ChangelogCommandOptions, type CommitLintCommandOptions, type PublishCommandOptions, type ReleaseCommandOptions, changelog, commitLint, getCommitMessage, isVersionCommitMessage, publish, release, updateVersion };
package/dist/index.js CHANGED
@@ -57,12 +57,29 @@ async function isWorktreeEmpty() {
57
57
  const ret = await execa("git", ["status", "--porcelain"]);
58
58
  return !ret.stdout;
59
59
  }
60
- async function publish(preRelease) {
60
+ async function publish({ preRelease, checkRemoteVersion, npmTag }) {
61
61
  const s = createSpinner2("Publishing all packages").start();
62
62
  const args = ["-r", "publish", "--no-git-checks", "--access", "public"];
63
+ if (checkRemoteVersion) {
64
+ const packageJson = getPackageJsons().find((packageJson2) => !packageJson2.config.private);
65
+ if (packageJson) {
66
+ const { config } = packageJson;
67
+ try {
68
+ await execa("npm", ["view", `${config.name}@${config.version}`, "version"]);
69
+ s.warn({
70
+ text: `The npm package has a same remote version ${config.version}, publishing automatically skipped.`
71
+ });
72
+ return;
73
+ } catch {
74
+ }
75
+ }
76
+ }
63
77
  if (preRelease) {
64
78
  args.push("--tag", "alpha");
65
79
  }
80
+ if (npmTag) {
81
+ args.push("--tag", npmTag);
82
+ }
66
83
  const ret = await execa("pnpm", args);
67
84
  if (ret.stderr && ret.stderr.includes("npm ERR!")) {
68
85
  throw new Error("\n" + ret.stderr);
@@ -83,14 +100,21 @@ async function pushGit(version, remote = "origin", skipGitTag = false) {
83
100
  s.success({ text: "Push remote repository successfully" });
84
101
  ret.stdout && logger_default.info(ret.stdout);
85
102
  }
103
+ function getPackageJsons() {
104
+ const packageJsons = ["package.json", ...glob.sync("packages/*/package.json")];
105
+ return packageJsons.map((path) => {
106
+ const filePath = resolve(cwd, path);
107
+ return {
108
+ config: readJSONSync(filePath),
109
+ filePath
110
+ };
111
+ });
112
+ }
86
113
  function updateVersion(version) {
87
- const packageJsons = glob.sync("packages/*/package.json");
88
- packageJsons.push("package.json");
89
- packageJsons.forEach((path) => {
90
- const file = resolve(cwd, path);
91
- const config = readJSONSync(file);
114
+ const packageJsons = getPackageJsons();
115
+ packageJsons.forEach(({ config, filePath }) => {
92
116
  config.version = version;
93
- writeFileSync(file, JSON.stringify(config, null, 2));
117
+ writeFileSync(filePath, JSON.stringify(config, null, 2));
94
118
  });
95
119
  }
96
120
  async function confirmRegistry() {
@@ -171,10 +195,12 @@ async function release(options) {
171
195
  await options.task();
172
196
  }
173
197
  if (!options.skipNpmPublish) {
174
- await publish(isPreRelease);
198
+ await publish({ preRelease: isPreRelease, npmTag: options.npmTag });
175
199
  }
176
200
  if (!isPreRelease) {
177
- await changelog();
201
+ if (!options.skipChangelog) {
202
+ await changelog();
203
+ }
178
204
  await pushGit(expectVersion, options.remote, options.skipGitTag);
179
205
  }
180
206
  logger_default.success(`Release version ${expectVersion} successfully!`);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@varlet/release",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.4",
5
5
  "description": "release all packages and generate changelogs",
6
6
  "keywords": [
7
7
  "varlet",