alemonjs 2.1.88 → 2.1.89
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/bin/README.md +2 -1
- package/bin/publish.js +43 -22
- package/package.json +2 -2
package/bin/README.md
CHANGED
|
@@ -117,7 +117,8 @@ alemonc publish --dry-run
|
|
|
117
117
|
- 传 `patch/minor/major/prepatch/preminor/premajor/prerelease` 时会自动递增
|
|
118
118
|
- 传具体版本号时会直接以该版本发布
|
|
119
119
|
- 默认先执行 `npm run build`
|
|
120
|
-
-
|
|
120
|
+
- 默认发布内容是 `lib/`、`package.json`、`README.md`
|
|
121
|
+
- 如果项目配置了 `.npmignore` 或 `package.json.files`,则切换为 npm 文件选择规则
|
|
121
122
|
- 最终把产物提交到 git `release` 分支,并推送对应 tag
|
|
122
123
|
- 默认要求 git 工作区干净,发布成功后会自动提交源码中的 `package.json` 版本变更
|
|
123
124
|
|
package/bin/publish.js
CHANGED
|
@@ -6,6 +6,7 @@ import { execSync, spawnSync } from 'child_process';
|
|
|
6
6
|
|
|
7
7
|
const RELEASE_TYPES = new Set(['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease']);
|
|
8
8
|
const SEMVER_RE = /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/;
|
|
9
|
+
const DEFAULT_PUBLISH_FILES = ['lib', 'package.json', 'README.md'];
|
|
9
10
|
|
|
10
11
|
function readPackageJson() {
|
|
11
12
|
const pkgPath = join(process.cwd(), 'package.json');
|
|
@@ -188,29 +189,49 @@ function getPackResult(cwd = process.cwd()) {
|
|
|
188
189
|
return result[0];
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
function
|
|
192
|
-
|
|
192
|
+
function hasNpmPublishRules(pkg) {
|
|
193
|
+
if (fs.existsSync(join(process.cwd(), '.npmignore'))) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
193
196
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
const sourcePath = join(process.cwd(), relativePath);
|
|
197
|
-
const targetPath = join(stageDir, relativePath);
|
|
197
|
+
return Array.isArray(pkg.files) && pkg.files.length > 0;
|
|
198
|
+
}
|
|
198
199
|
|
|
199
|
-
|
|
200
|
-
|
|
200
|
+
function getDefaultPublishFiles() {
|
|
201
|
+
return DEFAULT_PUBLISH_FILES.filter(file => fs.existsSync(join(process.cwd(), file)));
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function warnDefaultPublishState(pkg, publishFiles) {
|
|
205
|
+
const hasLibDir = fs.existsSync(join(process.cwd(), 'lib'));
|
|
206
|
+
const mainField = typeof pkg.main === 'string' ? pkg.main : '';
|
|
207
|
+
|
|
208
|
+
if (!hasLibDir && mainField.startsWith('./lib/')) {
|
|
209
|
+
console.warn(`警告: 缺少 lib/ 目录,但 package.json main 指向 ${mainField},将继续发布`);
|
|
201
210
|
}
|
|
202
211
|
|
|
203
|
-
|
|
212
|
+
if (publishFiles.length === 0) {
|
|
213
|
+
console.warn('警告: 默认发布规则下没有匹配到任何文件');
|
|
214
|
+
}
|
|
204
215
|
}
|
|
205
216
|
|
|
206
|
-
function
|
|
207
|
-
const publishDir = fs.mkdtempSync(join(os.tmpdir(), 'alemon-
|
|
217
|
+
function copyPublishFiles(files) {
|
|
218
|
+
const publishDir = fs.mkdtempSync(join(os.tmpdir(), 'alemon-publish-'));
|
|
208
219
|
|
|
209
220
|
for (const item of files) {
|
|
210
|
-
const relativePath = item.path;
|
|
211
|
-
const sourcePath = join(
|
|
221
|
+
const relativePath = typeof item === 'string' ? item : item.path;
|
|
222
|
+
const sourcePath = join(process.cwd(), relativePath);
|
|
212
223
|
const targetPath = join(publishDir, relativePath);
|
|
213
224
|
|
|
225
|
+
if (!fs.existsSync(sourcePath)) {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (fs.statSync(sourcePath).isDirectory()) {
|
|
230
|
+
fs.mkdirSync(join(targetPath, '..'), { recursive: true });
|
|
231
|
+
fs.cpSync(sourcePath, targetPath, { recursive: true });
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
|
|
214
235
|
fs.mkdirSync(join(targetPath, '..'), { recursive: true });
|
|
215
236
|
fs.copyFileSync(sourcePath, targetPath);
|
|
216
237
|
}
|
|
@@ -335,7 +356,6 @@ export async function publish(release, options = {}) {
|
|
|
335
356
|
console.log(`已更新 package.json 版本: ${localVersion} -> ${targetVersion}`);
|
|
336
357
|
}
|
|
337
358
|
|
|
338
|
-
let stageDir = null;
|
|
339
359
|
let publishDir = null;
|
|
340
360
|
let worktreeDir = null;
|
|
341
361
|
try {
|
|
@@ -350,13 +370,17 @@ export async function publish(release, options = {}) {
|
|
|
350
370
|
console.log('已跳过构建');
|
|
351
371
|
}
|
|
352
372
|
|
|
353
|
-
const
|
|
354
|
-
|
|
373
|
+
const useNpmRules = hasNpmPublishRules(pkg);
|
|
374
|
+
const publishFiles = useNpmRules ? getPackResult().files : getDefaultPublishFiles();
|
|
355
375
|
|
|
356
|
-
|
|
357
|
-
|
|
376
|
+
if (!useNpmRules) {
|
|
377
|
+
warnDefaultPublishState(pkg, publishFiles);
|
|
378
|
+
}
|
|
358
379
|
|
|
359
|
-
|
|
380
|
+
publishDir = copyPublishFiles(publishFiles);
|
|
381
|
+
|
|
382
|
+
console.log(`发布规则: ${useNpmRules ? 'npm' : 'default'}`);
|
|
383
|
+
console.log(`发布文件数: ${publishFiles.length}`);
|
|
360
384
|
|
|
361
385
|
if (options.dryRun) {
|
|
362
386
|
console.log('dry-run 模式,不会真正推送到 git');
|
|
@@ -388,9 +412,6 @@ export async function publish(release, options = {}) {
|
|
|
388
412
|
}
|
|
389
413
|
throw error;
|
|
390
414
|
} finally {
|
|
391
|
-
if (stageDir) {
|
|
392
|
-
fs.rmSync(stageDir, { recursive: true, force: true });
|
|
393
|
-
}
|
|
394
415
|
if (publishDir) {
|
|
395
416
|
fs.rmSync(publishDir, { recursive: true, force: true });
|
|
396
417
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "alemonjs",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.89",
|
|
4
4
|
"description": "bot script",
|
|
5
5
|
"author": "lemonade",
|
|
6
6
|
"license": "MIT",
|
|
@@ -93,4 +93,4 @@
|
|
|
93
93
|
"url": "https://github.com/lemonade-lab/alemonjs.git"
|
|
94
94
|
},
|
|
95
95
|
"gitHead": "c6aa5616afe091a37610dad22fbb2d2618d943b8"
|
|
96
|
-
}
|
|
96
|
+
}
|