系列文章
开发脚本
脚本:发布官网脚本
$ npm run packagePage
访问:https://doudizhu.github.io/fast-cache-ddza.github.io/
替换手动操作,如下:
gitbook build
cp -r _book/ ../package/fast-cache-ddza.github.io
cd ../package/fast-cache-ddza.github.io
git pull
git add .
git commit -m 'update'
git push
cd ../fast-cache-ddza.github.io
scripts/packagePage.js
const path = require("path");
const callfile = require("child_process");
const cwd = path.resolve(__dirname, `../`)
const packagePath = path.resolve(__dirname, `../package/fast-cache-ddza.github.io`)
callfile.exec(
`
gitbook build &&
cp -r _book/ ../package/fast-cache-ddza.github.io &&
cd ../package/fast-cache-ddza.github.io &&
git pull &&
git add . &&
git commit -m 'update' &&
git push
`,
{
cwd,
},
async function (error, stdout, stderr) {
console.log(error, stdout, stderr)
}
)
package.json, 新增
"packagePage": "node scripts/packagePage",
脚本: push
// 默认dev
$ npm run push 脚本发布官网脚本
// main
$ npm run push 脚本发布官网脚本 main
scripts/push.js
const path = require("path");
const callfile = require("child_process");
const cwd = path.resolve(__dirname, `../`)
const commitMsg = process.argv[2] // commit信息
const branch = process.argv[3] || 'dev' // 分支名
callfile.exec(
`
git checkout ${branch} &&
git reset --soft HEAD^ &&
git pull origin ${branch} &&
git add . &&
git commit -m ${commitMsg} &&
git push origin ${branch}
`,
{
cwd,
},
async function (error, stdout, stderr) {
console.log(error, stdout, stderr)
}
)
package.json, 新增
"push": "node scripts/push",
脚本: 从dev分支向main分支merge代码,并提交
$ npm run mergeMain
scripts/mergeMain.js
const path = require("path");
const callfile = require("child_process");
const cwd = path.resolve(__dirname, `../`)
callfile.exec(
`
git checkout main &&
git reset --soft HEAD^ &&
git pull &&
git merge dev &&
git push
`,
{
cwd,
},
async function (error, stdout, stderr) {
console.log(error, stdout, stderr)
}
)
package.json, 新增
"mergeMain": "node scripts/mergeMain",
完整 package.json
{
"name": "fast-cache-ddz",
"version": "0.0.1",
"description": "短小精悍的前端缓存工具,防止内存泄露",
"main": "src/index.js",
"scripts": {
"packagePage": "node scripts/packagePage",
"push": "node scripts/push",
"mergeMain": "node scripts/mergeMain",
"example": "http-server -p 8880",
"release": "webpack",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/doudizhu/fast-cache-ddz.git"
},
"keywords": [
"cache"
],
"author": "https://github.com/doudizhu/fast-cache-ddz",
"license": "MIT",
"bugs": {
"url": "https://github.com/doudizhu/fast-cache-ddz/issues"
},
"homepage": "https://github.com/doudizhu/fast-cache-ddz#readme",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-latest": "^6.24.1",
"webpack": "^4.7.0",
"webpack-cli": "^2.1.2"
},
"dependencies": {
"user": "0.0.0"
}
}
升级维护
代码,清空缓存功能
src/index.js
class FastCache {
constructor() {
this.list = {};
}
set(key, value) {
this.list[key] = value;
}
get(key) {
return this.list[key];
}
clear() {
this.list = {}
}
}
window.FastCache = FastCache;
example/test.html 测试页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>example</title>
</head>
<body>
<p>example</p >
<script src="../release/bundle.js"></script>
<script>
var FC = window.FastCache;
var cache = new FC();
cache.set("a", 100);
console.log("clear before", cache.get("a"));
cache.clear();
console.log("clear after", cache.get("a"));
</script>
</body>
</html>
编译&测试
$ npm run release
$ npm run example
访问(清空缓存):http://127.0.0.1:8880/example/test.html
提交(*脚本操作,参考第二部分)
npm run push 升级,清空缓存功能
升级文档
doc/use/README.md
# 使用文档
## 初始化
```js
var FC = window.FastCache;
var cache = new FC();
```
## 设置
```js
cache.set('a',100)
```
## 获取
```js
cache.get('a')
```
## 清空
```js
cache.clear()
```
提交
npm run push 升级,升级文档
发布至官网
$ npm run packagePage
访问:https://doudizhu.github.io/fast-cache-ddza.github.io/
开发脚本
合并 pr
访问 pull request:
https://github.com/doudizhu/fast-cache-ddz/pulls
确认没有问题,点解按钮:
Merge pull request
ps:
修复文档无目录问题
原因:md文件被vscode自动格式化导致,关闭自动格式化md
settings.json
{
"[markdown]": {
"editor.wordWrap": "on",
"editor.quickSuggestions": false,
"editor.formatOnSave": false
},
}