Skip to content

Commit

Permalink
chore: update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed Jun 8, 2021
1 parent d8ecb37 commit 45b1a35
Show file tree
Hide file tree
Showing 30 changed files with 248 additions and 44 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -3,6 +3,7 @@ node_modules/

# Dist files
packages/*/client/
packages/*/lib/
packages/*/node/
packages/theme/layouts/
packages/theme/styles/
Expand Down
4 changes: 0 additions & 4 deletions packages/add-this/package.json
Expand Up @@ -37,9 +37,5 @@
"demo:serve": "vuepress dev __tests__/demo",
"dev": "rollup -c -w",
"dev:rollup": "rollup -c -w"
},
"devDependencies": {
"rollup": "2.51.0",
"vuepress": "2.0.0-beta.17"
}
}
2 changes: 1 addition & 1 deletion packages/add-this/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", { external: ["@vuepress/utils"] }),
Expand Down
4 changes: 0 additions & 4 deletions packages/comment/package.json
Expand Up @@ -48,10 +48,6 @@
"balloon-css": "^1.2.0",
"vuepress-plugin-reading-time2": "2.0.0-alpha.0"
},
"devDependencies": {
"rollup": "2.51.0",
"vuepress": "2.0.0-beta.17"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/comment/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
4 changes: 0 additions & 4 deletions packages/components/package.json
Expand Up @@ -44,10 +44,6 @@
"screenfull": "^5.1.0",
"vue-router": "^4.0.8"
},
"devDependencies": {
"rollup": "2.51.0",
"vuepress": "2.0.0-beta.17"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/components/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript, rollupVue } from "../../script/rollup";
import { rollupTypescript, rollupVue } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
3 changes: 0 additions & 3 deletions packages/copy-code/package.json
Expand Up @@ -44,9 +44,6 @@
"@mr-hope/vuepress-shared": "2.0.0-alpha.0",
"balloon-css": "^1.2.0"
},
"devDependencies": {
"rollup": "2.51.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/copy-code/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
3 changes: 0 additions & 3 deletions packages/feed/package.json
Expand Up @@ -41,9 +41,6 @@
"chalk": "^4.1.1",
"xml-js": "^1.6.11"
},
"devDependencies": {
"rollup": "2.51.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/feed/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default rollupTypescript("node/index", {
external: ["@mr-hope/vuepress-shared", "chalk", "fs-extra", "path", "xml-js"],
Expand Down
3 changes: 0 additions & 3 deletions packages/md-enhance/package.json
Expand Up @@ -55,8 +55,5 @@
"mermaid": "^8.10.2",
"react": "^17.0.2",
"reveal.js": "^4.1.1"
},
"devDependencies": {
"vuepress": "2.0.0-beta.17"
}
}
2 changes: 1 addition & 1 deletion packages/md-enhance/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
3 changes: 0 additions & 3 deletions packages/palette/package.json
Expand Up @@ -41,9 +41,6 @@
"dependencies": {
"@mr-hope/vuepress-shared": "2.0.0-alpha.0"
},
"devDependencies": {
"rollup": "2.51.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/palette/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default rollupTypescript("node/index", {
external: ["@vuepress/utils"],
Expand Down
2 changes: 1 addition & 1 deletion packages/photo-swipe/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript, rollupVue } from "../../script/rollup";
import { rollupTypescript, rollupVue } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
2 changes: 1 addition & 1 deletion packages/pwa/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript, rollupVue } from "../../script/rollup";
import { rollupTypescript, rollupVue } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
3 changes: 0 additions & 3 deletions packages/reading-time/package.json
Expand Up @@ -37,9 +37,6 @@
"dependencies": {
"@mr-hope/vuepress-shared": "2.0.0-alpha.0"
},
"devDependencies": {
"rollup": "2.51.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/reading-time/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default rollupTypescript("node/index", {
external: ["@mr-hope/vuepress-shared"],
Expand Down
2 changes: 1 addition & 1 deletion packages/seo/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default rollupTypescript("node/index", {
external: [
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", { resolve: true }),
Expand Down
2 changes: 1 addition & 1 deletion packages/sitemap/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript } from "../../script/rollup";
import { rollupTypescript } from "../../scripts/rollup";

export default rollupTypescript("node/index", {
external: ["@vuepress/core", "chalk", "fs-extra", "path", "sitemap"],
Expand Down
3 changes: 0 additions & 3 deletions packages/theme/package.json
Expand Up @@ -59,9 +59,6 @@
"vue": "^3.0.11",
"vue-router": "^4.0.8"
},
"devDependencies": {
"rollup": "2.51.0"
},
"publishConfig": {
"access": "public"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/theme/rollup.config.js
@@ -1,4 +1,4 @@
import { rollupTypescript, rollupVue } from "../../script/rollup";
import { rollupTypescript, rollupVue } from "../../scripts/rollup";

export default [
...rollupTypescript("node/index", {
Expand Down
93 changes: 93 additions & 0 deletions scripts/bootstrap.ts
@@ -0,0 +1,93 @@
import { existsSync, writeFileSync, readdirSync } from "fs";
import { join, resolve } from "path";
import { version } from "../packages/theme/package.json";

const packagesDir = resolve(__dirname, "../packages/");
const files = readdirSync(packagesDir);

files.forEach((pkgName) => {
if (pkgName.charAt(0) === "." || pkgName === "theme") return;

const desc = `${pkgName} plugin for vuepress-theme-hope`;
const pkgPath = join(packagesDir, pkgName, "package.json");

// generate package.json
if (!existsSync(pkgPath)) {
const pkgJSON = {
name: `@mr-hope/vuepress-plugin-${pkgName}`,
version,
description: desc,
main: "node/index.js",
types: "node/index.d.ts",
publishConfig: {
access: "public",
},
repository: {
type: "git",
url: "git+https://github.com/vuepress-theme-hope/vuepress-theme-hope.git",
directory: `packages/${pkgName}`,
},
keywords: [
"vuepress-plugin",
"vuepress",
pkgName,
"vuepress-theme-hope",
"mr-hope",
],
author: {
email: "zhangbowang1998@gmail.com",
name: "Mr.Hope",
url: "https://mrhope.site",
},
license: "MIT",
bugs: {
url: "https://github.com/vuepress-theme-hope/vuepress-theme-hope/issues",
},
homepage: `https://github.com/vuepress-theme-hope/vuepress-theme-hope/packages/${pkgName}#readme`,
};

writeFileSync(pkgPath, `${JSON.stringify(pkgJSON, null, 2)}\n`);
}

const readmePath = join(packagesDir, pkgName, "readme.md");

// generate readme.md
if (!existsSync(readmePath))
writeFileSync(
readmePath,
`# @mr-hope/vuepress-plugin-${pkgName}
[![Version](https://img.shields.io/npm/v/@mr-hope/vuepress-plugin-${pkgName}.svg?style=flat-square&logo=npm) ![Downloads](https://img.shields.io/npm/dm/@mr-hope/vuepress-plugin-${pkgName}.svg?style=flat-square&logo=npm) ![Size](https://img.shields.io/bundlephobia/min/@mr-hope/vuepress-plugin-${pkgName}?style=flat-square&logo=npm)](https://www.npmjs.com/package/@mr-hope/vuepress-plugin-${pkgName})
${desc}.
## Usage
\`\`\`bash
yarn add @mr-hope/vuepress-plugin-${pkgName}
\`\`\`
Or
\`\`\`bash
npm i @mr-hope/vuepress-plugin-${pkgName}
\`\`\`
---
vuepress-theme-hope 的 ${pkgName} 插件。
## 使用
\`\`\`bash
yarn add @mr-hope/vuepress-plugin-${pkgName}
\`\`\`
\`\`\`bash
npm i @mr-hope/vuepress-plugin-${pkgName}
\`\`\`
`
);
});
6 changes: 6 additions & 0 deletions scripts/release/index.ts
@@ -0,0 +1,6 @@
import { release } from "./release";

release().catch((err) => {
console.error(err);
process.exit(1);
});
93 changes: 93 additions & 0 deletions scripts/release/release.ts
@@ -0,0 +1,93 @@
import execa = require("execa");
import { black, cyan, green, red } from "chalk";
import { prompt } from "inquirer";
import { ReleaseType, inc } from "semver";
import { version as currentVersion } from "../../lerna.json";
import { getNpmTags, getVersion, versions } from "./version";
import { sync } from "./sync";
import type { Answers } from "./version";

export const release = async (): Promise<void> => {
console.log(black.bgYellow("wait"), "Building project...");
await execa("yarn", ["run", "clean"]);
await execa("yarn", ["run", "build"]);

console.log(`Current version: ${green(currentVersion)}`);

const bumps: ReleaseType[] = [
"patch",
"minor",
"major",
"prerelease",
"premajor",
];

bumps.forEach((bump) => {
versions[bump] = inc(currentVersion, bump) as string;
});

const bumpChoices = bumps.map((bump) => ({
name: `${bump} (${versions[bump]})`,
value: bump,
}));

const { bump, customVersion, npmTag } = await prompt<Answers>([
{
name: "bump",
message: "Select release type:",
type: "list",
choices: [...bumpChoices, { name: "custom", value: "custom" }],
},
{
name: "customVersion",
message: "Input version:",
type: "input",
when: (answers): boolean => answers.bump === "custom",
},
{
name: "npmTag",
message: "Input npm tag:",
type: "list",
default: (answers: Answers): string => getNpmTags(getVersion(answers))[0],
choices: (answers: Answers): string[] => getNpmTags(getVersion(answers)),
},
]);

const version = customVersion || versions[bump];

const { confirm } = await prompt<{ confirm: "Y" | "N" }>([
{
name: "confirm",
message: `Confirm releasing ${version} (${npmTag})?`,
type: "list",
choices: ["N", "Y"],
},
]);

if (confirm === "N") return console.log(red("Release canceled."));

const releaseArguments = [
"publish",
version,
"--dist-tag",
npmTag,
"--registry",
"https://registry.npmjs.org/",
];

console.log(cyan(`lerna ${releaseArguments.join(" ")}`));

await execa(require.resolve("lerna/cli"), releaseArguments, {
stdio: "inherit",
});

console.log(black.bgYellow("wait"), "Syncing npm.taobao.org...");

await sync();

console.log(black.bgYellow("wait"), "Generating changelog...");

await execa("yarn", ["run", "changelog"]);

console.log(green("Release complete"));
};
20 changes: 20 additions & 0 deletions scripts/release/sync.ts
@@ -0,0 +1,20 @@
import { readdirSync } from "fs";
import { get } from "https";
import { resolve } from "path";

const packages = readdirSync(resolve(__dirname, "../../packages"));

export const sync = (): Promise<void[]> => {
const promises = packages.map((packageName) => {
return import(`../../packages/${packageName}/package.json`).then(
(content: Record<string, unknown>) =>
new Promise<void>((resolve) => {
get(`https://npm.taobao.org/sync/${content.name as string}`, () =>
resolve()
);
})
);
});

return Promise.all(promises);
};

0 comments on commit 45b1a35

Please sign in to comment.