docs: up website & sh

This commit is contained in:
元凛
2022-02-09 17:24:35 +08:00
parent f6cad1ea63
commit 1a0a9f0bf6
41 changed files with 1340 additions and 2278 deletions

23
script/check-commit.js Executable file
View File

@@ -0,0 +1,23 @@
const chalk = require('chalk');
const simpleGit = require('simple-git/promise');
const cwd = process.cwd();
const git = simpleGit(cwd);
async function checkCommit({ files }) {
if (files.length) {
console.log(chalk.yellow('🙄 You forgot something to commit.'));
files.forEach(({ path: filePath }) => {
console.log(' -', chalk.red(filePath));
});
console.log('');
process.exit(1);
}
}
async function run() {
const status = await git.status();
await checkCommit(status);
}
run();

14
script/pub.sh Normal file
View File

@@ -0,0 +1,14 @@
echo "[TEST] check format"
npm run format-check
echo "[TEST] test package"
npm run package
echo "[TEST] test commit"
npm run check-commit
echo "[Action] do tag"
npm run tag
echo "[Action] do release"
npm run release

54
script/release.js Normal file
View File

@@ -0,0 +1,54 @@
const chalk = require('chalk');
const open = require('open');
const newGithubReleaseUrl = require('new-github-release-url');
const { readFileSync } = require('fs');
const path = require('path');
let tag = '';
const CHANGELOG_NAME = 'CHANGELOG.md';
const user = 'actions-cool';
const repo = 'issues-helper';
function getChangelog(content) {
const lines = content.split('\n');
const changeLog = [];
const pin = /^## /;
let begin = false;
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
if (begin && pin.test(line)) {
break;
}
if (begin && line) {
changeLog.push(line);
}
if (!begin) {
begin = pin.test(line);
if (begin) {
tag = line.substring(3, line.length).trim();
}
}
}
return changeLog.join('\n');
}
const changelogPath = path.join(__dirname, '..', CHANGELOG_NAME);
const changelog = readFileSync(changelogPath, 'utf-8');
const body = getChangelog(changelog);
async function run() {
const url = newGithubReleaseUrl({
user,
repo,
tag,
body: body,
});
await open(url);
console.log(chalk.yellow('🚀 Please check tag and changelog. Then click publish!'));
};
run();

70
script/tag.js Normal file
View File

@@ -0,0 +1,70 @@
const chalk = require('chalk');
const simpleGit = require('simple-git/promise');
const { execSync } = require('child_process');
const { readFileSync } = require('fs');
const path = require('path');
const CHANGELOG_NAME = 'CHANGELOG.md';
const CHANGELOG_PATH = path.join(__dirname, '..', CHANGELOG_NAME);
const CHANGELOG = readFileSync(CHANGELOG_PATH, 'utf-8');
const cwd = process.cwd();
const git = simpleGit(cwd);
async function run() {
execSync(`git pull`);
const data = await git.tags();
const tags = data.all;
let tag = tags.reverse()[0];
console.log(chalk.green(`[Git Query] tag: ${tag}`));
const tagChangelog = getChangelogTag(CHANGELOG);
if (tagChangelog && tag != tagChangelog) {
console.log(chalk.yellow(`[Git Action] Push new ${tagChangelog} tag!`));
execSync(`git tag ${tagChangelog}`);
execSync(`git push origin ${tagChangelog}:${tagChangelog}`);
execSync(`git pull`);
tag = tagChangelog;
} else {
console.log(chalk.yellow('🙄 Please add new release changelog first.'));
console.log('');
process.exit(1);
}
const tagSimple = tag.startsWith('v') ? tag.substring(0, 2) : tag.substring(0, 1);
console.log(chalk.green(`[Git Query] tagSimple: ${tagSimple}`));
if (tags.includes(tagSimple)) {
console.log(chalk.yellow(`[Git Action] Delete ${tagSimple} tag`));
execSync(`git push origin :refs/tags/${tagSimple}`);
}
console.log(chalk.yellow(`[Git Action] Add new simple ${tagSimple} tag`));
execSync(`git push origin ${tag}:${tagSimple}`);
console.log(chalk.green('🎉 Done!'));
}
function getChangelogTag(content) {
const lines = content.split('\n');
const pin = /^## /;
let begin = false;
let tag = '';
for (let i = 0; i < lines.length; i += 1) {
const line = lines[i];
if (begin && pin.test(line)) {
break;
}
if (!begin) {
begin = pin.test(line);
if (begin) {
tag = line.substring(3, line.length);
}
}
}
return tag.trim();
}
run();

View File

@@ -1,7 +1,7 @@
const { readFileSync, writeFileSync } = require('fs');
const last = /v2\.4\.2/g;
const now = `v2`;
const last = /@v2/g;
const now = `@v3`;
let readme = readFileSync('./README.md', 'utf-8');
readme = readme.replace(last, now);
@@ -13,32 +13,32 @@ readmeen = readmeen.replace(last, now);
writeFileSync('./README.en-US.md', readmeen);
console.log('readmeen done!');
let index = readFileSync('./docs/index.md', 'utf-8');
let index = readFileSync('./web/docs/index.md', 'utf-8');
index = index.replace(last, now);
writeFileSync('./docs/index.md', index);
writeFileSync('./web/docs/index.md', index);
console.log('index done!');
let indexen = readFileSync('./docs/index.en-US.md', 'utf-8');
let indexen = readFileSync('./web/docs/index.en-US.md', 'utf-8');
indexen = indexen.replace(last, now);
writeFileSync('./docs/index.en-US.md', indexen);
writeFileSync('./web/docs/index.en-US.md', indexen);
console.log('indexen done!');
let base = readFileSync('./docs/base.md', 'utf-8');
let base = readFileSync('./web/docs/base.md', 'utf-8');
base = base.replace(last, now);
writeFileSync('./docs/base.md', base);
writeFileSync('./web/docs/base.md', base);
console.log('base done!');
let baseen = readFileSync('./docs/base.en-US.md', 'utf-8');
let baseen = readFileSync('./web/docs/base.en-US.md', 'utf-8');
baseen = baseen.replace(last, now);
writeFileSync('./docs/base.en-US.md', baseen);
writeFileSync('./web/docs/base.en-US.md', baseen);
console.log('baseen done!');
let adv = readFileSync('./docs/advanced.md', 'utf-8');
let adv = readFileSync('./web/docs/advanced.md', 'utf-8');
adv = adv.replace(last, now);
writeFileSync('./docs/advanced.md', adv);
writeFileSync('./web/docs/advanced.md', adv);
console.log('adv done!');
let adven = readFileSync('./docs/advanced.en-US.md', 'utf-8');
let adven = readFileSync('./web/docs/advanced.en-US.md', 'utf-8');
adven = adven.replace(last, now);
writeFileSync('./docs/advanced.en-US.md', adven);
writeFileSync('./web/docs/advanced.en-US.md', adven);
console.log('adven done!');