UNPKG

cckj-util

Version:

A common util lib for cj

58 lines (46 loc) 1.37 kB
const shell = require("shelljs"); const fs = require("fs"); const { resolve } = require("path"); const { ASSETS_CDN } = require('../config/path') function resolveFile(filePath) { return resolve(__dirname, "..", filePath); } function toMarkCode(code) { return "```\n" + code + "\n```"; } function toMarkH1(title) { return "\n# "+ title +"\n"; } function toMarkH3(title) { return "\n### "+ title +"\n"; } let dirArr = fs.readdirSync(resolveFile("dist")); // 获取打包后文件 let newScriptName = dirArr[0]; // 写入 markdown let str = toMarkH1('单独引入script标签') + toMarkCode(ASSETS_CDN + newScriptName) + toMarkH3('script 使用方式') + toMarkCode(`引入后会导入全局变量 CJ,所有的方法挂载到 CJ 上`) + toMarkH1('npm 包形式') + toMarkCode('npm install cckj-util -S') + toMarkH3('npm 包 使用方式') + toMarkCode(`import CJ from 'cckj-util'\nconst { CJZip } = CJ `) let result = fs.writeFileSync( resolveFile("README.md"), str, { flag: "w" } ); if (result) { // 如果有错误 shell.echo("Error: write file failed"); shell.exit(1); } // 生成文档 shell.exec("npm run docs"); // 发布 if (shell.exec('npm publish').code !== 0) { //执行 npm npm publish 命令 shell.echo('Error: npm publish failed'); shell.exit(1); }