Skip to content

Commit

Permalink
build: 增加发布npm包的脚本 (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
kagol authored Mar 19, 2022
1 parent 1a1e619 commit 2a319d5
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 5 deletions.
2 changes: 1 addition & 1 deletion commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ module.exports = {
'subject-case': [0, 'never'],
'header-max-length': [2, 'always', 88],
},
};
};
33 changes: 33 additions & 0 deletions packages/devui-vue/devui-cli/commands/release.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const path = require('path');
const fsExtra = require('fs-extra');
const { omit } = require('lodash');
const shell = require('shelljs');

const outputDir = path.resolve(__dirname, '../../build');

const package = require('../../package.json');

const getVersion = (version) => {
if (version) {
return version;
} else {
const versionNums = package.version.split('.');
return versionNums.map((num, index) => index === versionNums.length - 1 ? +num + 1 : num).join('.');
}
};

const createPackageJson = async (version) => {
package.version = getVersion(version);
const fileStr = JSON.stringify(omit(package, 'scripts', 'devDependencies'), null, 2);
await fsExtra.outputFile(path.resolve(outputDir, `package.json`), fileStr, 'utf-8');
};

exports.release = async ({ version }) => {
await createPackageJson(version);
shell.sed('-i', 'workspace:', '', path.resolve(outputDir, 'package.json'));
shell.cp('-R', path.resolve(__dirname, '../../../../README.md'), outputDir);
shell.cd(outputDir);
shell.mkdir('-p', 'theme');
shell.cp('-R', path.resolve(__dirname, '../../devui/theme/theme.scss'), path.resolve(outputDir, 'theme'));
// shell.exec('npm publish');
};
7 changes: 7 additions & 0 deletions packages/devui-vue/devui-cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { create, validateCreateType } = require('./commands/create');
const { build } = require('./commands/build');
const { generateTheme } = require('./commands/generate-theme');
const { generateDts } = require('./commands/generate-dts');
const { release } = require('./commands/release');
const { VERSION, CREATE_SUPPORT_TYPES } = require('./shared/constant');

const program = new Command();
Expand Down Expand Up @@ -33,4 +34,10 @@ program
.description('生成ts类型文件')
.action(generateDts);

program
.command('release')
.option('-v --version <version>', '版本号')
.description('发布npm包')
.action(release);

program.parse().version(VERSION);
14 changes: 10 additions & 4 deletions packages/devui-vue/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-devui",
"version": "0.0.1",
"version": "1.0.0-rc.0",
"license": "MIT",
"description": "DevUI components based on Vite and Vue3",
"keywords": [
Expand All @@ -15,23 +15,29 @@
"jsx",
"devui"
],
"homepage": "https://vue-devui.github.io/",
"repository": {
"type": "git",
"url": "[email protected]:DevCloudFE/vue-devui.git"
},
"main": "vue-devui.umd.js",
"module": "vue-devui.es.js",
"style": "style.css",
"scripts": {
"dev": "pnpm generate:theme && vitepress dev docs",
"build": "pnpm generate:theme && node --max-old-space-size=4096 node_modules/vitepress/bin/vitepress.js build docs && cp public/* docs/.vitepress/dist/assets",
"build:lib": "pnpm predev && pnpm build:components && pnpm changelog && pnpm copy",
"build:lib": "pnpm predev && pnpm build:components && pnpm changelog && pnpm release",
"test": "jest --config jest.config.js",
"build:components": "node ./devui-cli/index.js build",
"generate:theme": "node ./devui-cli/index.js generate:theme",
"generate:dts": "node ./devui-cli/index.js generate:dts",
"copy": "cp package.json build && cp ../../README.md build && cd build && mkdir theme && cd ../ && cp devui/theme/theme.scss build/theme",
"release": "node ./devui-cli/index.js release",
"cli": "node ./devui-cli/index.js",
"cli:create": "node ./devui-cli/index.js create -t component",
"predev": "node ./devui-cli/index.js create -t vue-devui --ignore-parse-error",
"prebuild": "node ./devui-cli/index.js create -t vue-devui --ignore-parse-error",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"cli": "devui"
"devui-cli": "devui"
},
"dependencies": {
"@devui-design/icons": "^1.3.0",
Expand Down

0 comments on commit 2a319d5

Please sign in to comment.