diff --git a/lib/__tests__/crypto.test.js b/lib/__tests__/crypto.test.js index 3349ee6..7aa8edf 100644 --- a/lib/__tests__/crypto.test.js +++ b/lib/__tests__/crypto.test.js @@ -1,4 +1,4 @@ -import {Encrypt, Decrypt} from '../crypto' +import { Encrypt, Decrypt } from '../crypto'; describe('Encrypt AES', () => { it('with empty', () => { @@ -10,13 +10,17 @@ describe('Encrypt AES', () => { }); it('valid oject data', () => { - const data = {name: '测试123'} - expect(Encrypt.AES(data, '1234567887654321')).toBe('egm/Mle8irv5rcW8KiYIP1ctnN/sh3k/KwpYvwyhjVg='); + const data = { name: '测试123' }; + expect(Encrypt.AES(data, '1234567887654321')).toBe( + 'egm/Mle8irv5rcW8KiYIP1ctnN/sh3k/KwpYvwyhjVg=', + ); }); it('valid Array data', () => { - const data = ['1', '2', '测试123'] - expect(Encrypt.AES(data, '1234567887654321')).toBe('GHRDr875WQZmG69cTBTvbaDBhT7IjN/lC8l5cfoHz2U='); + const data = ['1', '2', '测试123']; + expect(Encrypt.AES(data, '1234567887654321')).toBe( + 'GHRDr875WQZmG69cTBTvbaDBhT7IjN/lC8l5cfoHz2U=', + ); }); }); @@ -34,12 +38,16 @@ describe('Decrypt AES', () => { }); it('valid oject data', () => { - const data = {name: '测试123'} - expect(Decrypt.AES('egm/Mle8irv5rcW8KiYIP1ctnN/sh3k/KwpYvwyhjVg=', '1234567887654321')).toBe(JSON.stringify(data)); + const data = { name: '测试123' }; + expect(Decrypt.AES('egm/Mle8irv5rcW8KiYIP1ctnN/sh3k/KwpYvwyhjVg=', '1234567887654321')).toBe( + JSON.stringify(data), + ); }); it('valid Array data', () => { - const data = ['1', '2', '测试123'] - expect(Decrypt.AES('GHRDr875WQZmG69cTBTvbaDBhT7IjN/lC8l5cfoHz2U=', '1234567887654321')).toBe(JSON.stringify(data)); + const data = ['1', '2', '测试123']; + expect(Decrypt.AES('GHRDr875WQZmG69cTBTvbaDBhT7IjN/lC8l5cfoHz2U=', '1234567887654321')).toBe( + JSON.stringify(data), + ); }); }); diff --git a/package.json b/package.json index 78da696..c59d0a4 100644 --- a/package.json +++ b/package.json @@ -14,18 +14,18 @@ ], "scripts": { "start": "cross-env NODE_ENV=development PACKAGE=development node scripts/start.js", - "build": "npm run lint && cross-env NODE_ENV=production PACKAGE=production node scripts/build.js", + "build": "cross-env NODE_ENV=production PACKAGE=production node scripts/build.js", "release": "sh scripts/release.sh", + "clean": "rimraf build", + "ci": "yarn commit", "commit": "git-cz", "test": "jest --no-cache", "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0", - "prettier": "prettier -c --write '**/*'", - "lint": "npm run lint:ts", + "prettier": "prettier -c --write '**/*.ts'", + "lint": "tsc --build tsconfig.build.json && node node_modules/tslint/bin/tslint -c ./tslint.json -p ./tsconfig.build.json", "lint-staged": "lint-staged", - "lint:ts": "tsc --build tsconfig.build.json && node node_modules/tslint/bin/tslint -c ./tslint.json -p ./tsconfig.build.json", - "prepublish": "npm run lint && npm run test", - "np": "np --yolo --no-yarn", - "publish": "npm run build && npm run np" + "np": "np --no-cleanup --yolo --no-publish", + "prepublishOnly": "yarn clean && yarn prettier && yarn lint && yarn build && yarn np" }, "publishConfig": { "registry": "http://registry.npmjs.org" @@ -33,7 +33,8 @@ "husky": { "hooks": { "commit-msg": "node scripts/verify-commit-msg.js", - "pre-commit": "lint-staged" + "pre-commit": "lint-staged", + "pre-push": "node scripts/publish-tips.js" } }, "lint-staged": { diff --git a/scripts/publish-tips.js b/scripts/publish-tips.js new file mode 100644 index 0000000..9af1ff8 --- /dev/null +++ b/scripts/publish-tips.js @@ -0,0 +1,8 @@ +const chalk = require('chalk'); + +console.log(); +console.log( + ` ${chalk.bgWhite.black(' 请使用')}${chalk.bgRed.black(' npm publish ')}${chalk.bgWhite.black( + '发布代码,会自动检查代码、打包、修改版本号等... ', + )} `, +); diff --git a/scripts/verify-commit-msg.js b/scripts/verify-commit-msg.js index 7d1f1c6..5414a69 100644 --- a/scripts/verify-commit-msg.js +++ b/scripts/verify-commit-msg.js @@ -7,7 +7,9 @@ const packageJson = require('../package.json'); const commitRE = /^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types|build)(\(.+\))?: .{1,50}/; -if (!commitRE.test(msg) && packageJson.version !== msg) { +console.log(`Commit: ${chalk.bgRed.white(msg)}`); + +if (!commitRE.test(msg) && packageJson.version !== msg && !/^v/.test(msg)) { console.log(); console.error(` ${chalk.bgRed.white(' ERROR ')} 无效的提交信息`); process.exit(1);