Skip to content

Commit 597da6a

Browse files
author
zihang.zzh
committed
feat: add readme copy logic
1 parent 04988de commit 597da6a

1 file changed

Lines changed: 42 additions & 38 deletions

File tree

src/built-in-plugins/command-publish/plugin/run-publish.ts

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -223,54 +223,54 @@ async function publishByPackageName(
223223
if (!options.publishOnly) {
224224
// Generate beta version if branch is not master or develop
225225
if (options.tag === 'beta' || !isDevelopBranch) {
226-
// fixed basicVersion to 1.0.0
227-
const basicVersion = '1.0.0';
228-
229-
const branchNameInVersion = currentBranchName.replace(/\//g, '').replace(/\./g, '');
230-
231-
let publishedVersions: string[] = [];
232-
try {
233-
// all of package versions
234-
const tempVersions = execSync(`${targetConfig.npmClient} view ${targetPackageJson.name} versions`);
235-
if (tempVersions) {
236-
publishedVersions = tempVersions
237-
.toString()
238-
.trim()
239-
.replace(/\n|'| |\[|\]/g, '')
240-
.split(',');
241-
} else {
226+
// fixed basicVersion to 1.0.0
227+
const basicVersion = '1.0.0';
228+
229+
const branchNameInVersion = currentBranchName.replace(/\//g, '').replace(/\./g, '');
230+
231+
let publishedVersions: string[] = [];
232+
try {
233+
// all of package versions
234+
const tempVersions = execSync(`${targetConfig.npmClient} view ${targetPackageJson.name} versions`);
235+
if (tempVersions) {
236+
publishedVersions = tempVersions
237+
.toString()
238+
.trim()
239+
.replace(/\n|'| |\[|\]/g, '')
240+
.split(',');
241+
} else {
242+
publishedVersions = [];
243+
}
244+
} catch (e) {
242245
publishedVersions = [];
243246
}
244-
} catch (e) {
245-
publishedVersions = [];
246-
}
247247

248-
let maxBetaVersionNum = 0;
248+
let maxBetaVersionNum = 0;
249249

250-
// 1.0.0-branchName.version
251-
const betaVersionReg = new RegExp(`\\d+\\.\\d+\\.\\d+-${branchNameInVersion}\\.\\d+`);
250+
// 1.0.0-branchName.version
251+
const betaVersionReg = new RegExp(`\\d+\\.\\d+\\.\\d+-${branchNameInVersion}\\.\\d+`);
252252

253-
// get max beta version
254-
publishedVersions.forEach((v: string) => {
255-
if (betaVersionReg.test(v)) {
256-
const tempBetaVersion = Number(v.split(`${branchNameInVersion}.`)[1]);
253+
// get max beta version
254+
publishedVersions.forEach((v: string) => {
255+
if (betaVersionReg.test(v)) {
256+
const tempBetaVersion = Number(v.split(`${branchNameInVersion}.`)[1]);
257257

258-
if (maxBetaVersionNum < tempBetaVersion) {
259-
maxBetaVersionNum = tempBetaVersion;
258+
if (maxBetaVersionNum < tempBetaVersion) {
259+
maxBetaVersionNum = tempBetaVersion;
260+
}
260261
}
261-
}
262-
});
262+
});
263263

264-
// basic version without branchName -> use basic version + branch name + beta version
265-
targetPackageJson.version = `${basicVersion}-${branchNameInVersion}.${maxBetaVersionNum + 1}`;
264+
// basic version without branchName -> use basic version + branch name + beta version
265+
targetPackageJson.version = `${basicVersion}-${branchNameInVersion}.${maxBetaVersionNum + 1}`;
266266

267-
await fs.outputFile(path.join(targetRoot, 'package.json'), `${JSON.stringify(targetPackageJson, null, 2)}\n`);
267+
await fs.outputFile(path.join(targetRoot, 'package.json'), `${JSON.stringify(targetPackageJson, null, 2)}\n`);
268268

269-
if (!(await isWorkingTreeClean())) {
270-
await exec(`git add -A; git commit -m "upgrade ${sourceType} version to ${targetPackageJson.version}" -n`, {
271-
cwd: pri.projectRootPath,
272-
});
273-
}
269+
if (!(await isWorkingTreeClean())) {
270+
await exec(`git add -A; git commit -m "upgrade ${sourceType} version to ${targetPackageJson.version}" -n`, {
271+
cwd: pri.projectRootPath,
272+
});
273+
}
274274
} else if (versionResult) {
275275
if (!options.semver) {
276276
const versionPrompt = await inquirer.prompt([
@@ -368,6 +368,10 @@ async function moveSourceFilesToTempFolderAndPublish(
368368
await copyDeclaration(sourceType, publishTempName);
369369
await fs.copy(path.join(targetRoot, 'package.json'), path.join(tempRoot, 'package.json'));
370370

371+
if (fs.existsSync(path.join(targetRoot, 'README.md'))) {
372+
await fs.copy(path.join(targetRoot, 'README.md'), path.join(tempRoot, 'README.md'));
373+
}
374+
371375
// Add external deps
372376
const targetPackageJson = await fs.readJson(path.join(tempRoot, 'package.json'));
373377
const addedPackageJson = await addMissingDeps(options, sourceType, depMap, targetConfig, isDevelopBranch);

0 commit comments

Comments
 (0)