Skip to content

Commit

Permalink
Merge pull request #5 from element-plus/feat/publish
Browse files Browse the repository at this point in the history
feat/publish
  • Loading branch information
jw-foss committed Dec 28, 2020
2 parents 4ae1153 + 9cc8a1a commit adb9e87
Show file tree
Hide file tree
Showing 9 changed files with 368 additions and 303 deletions.
42 changes: 42 additions & 0 deletions configs/rollup.comp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const path = require('path')
const rollup = require('rollup')
const typescript = require('rollup-plugin-typescript2')

const p = process.argv[2]; // node this.js compName
const exportName = `${p.split('/').pop().split('.').shift()}.js`

const root = path.resolve(__dirname, '..');

const esm = {
file: path.resolve(root, 'build/es', exportName),
format: 'esm',
sourcemap: false,
};

const cjs = {
file: path.resolve(root, 'build/lib', exportName),
format: 'cjs',
exports: 'named',
sourcemap: false,
};

rollup.rollup({
input: path.resolve(root, p),
plugins: [typescript(
{
tsconfigOverride: {
compilerOptions: {
declaration: false,
},
'exclude': [
'node_modules',
'__tests__',
],
},
abortOnError: false,
})],
external: ['vue']
}).then(async bundle => {
await Promise.all([bundle.write(esm), bundle.write(cjs)]);
console.log(' \u001b[32m', exportName, 'done');
})
27 changes: 27 additions & 0 deletions configs/rollup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const path = require('path')
const rollup = require('rollup')
const typescript = require('rollup-plugin-typescript2')

const root = path.resolve(__dirname, '..');
const esm = {
file: path.resolve(root, './build/es/index.js'),
format: 'esm',
name: 'icons',
sourcemap: false,
};

const cjs = {
file: path.resolve(root, './build/lib/index.js'),
format: 'cjs',
exports: 'named',
sourcemap: false,
}

rollup.rollup({
input: path.resolve(root, './packages/index.ts'),
plugins: [typescript()],
external: ['vue']
}).then(async bundle => {
await Promise.all([bundle.write(esm), bundle.write(cjs)]);
console.log('full bundle built success');
});
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{
"name": "@element-plus/icons",
"version": "0.0.2",
"main": "./lib/index.js",
"main:umd": "./lib/index.js",
"module": "./es/index.js",
"unpkg": "./lib/index.min.js",
"sideEffects": false,
"types": "./lib/index.d.ts",
"scripts": {
"serve": "vite",
"build": "node ./rollup.js",
"generate": "sh ./batch.sh",
"pub": "sh ./publish.sh"
"generate": "sh ./scripts/batch.sh",
"pub": "sh ./scripts/publish.sh"
},
"devDependencies": {
"@vue/compiler-sfc": "^3.0.2",
Expand Down
280 changes: 0 additions & 280 deletions packages/element-plus-icons/index.ts

This file was deleted.

281 changes: 281 additions & 0 deletions packages/index.ts

Large diffs are not rendered by default.

17 changes: 0 additions & 17 deletions rollup.js

This file was deleted.

6 changes: 4 additions & 2 deletions batch.sh → scripts/batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ ${normalized}.displayName = '${normalized}';
export default ${normalized};
EOF
echo "export { default as ${normalized} } from '../components/${BASE_NAME}'" >> packages/element-plus-icons/index.ts
echo "export { default as ${normalized} } from './components/${BASE_NAME}'" >> packages/index.ts
}

export -f gen

# gen ./v2/add-location.svg in case you want to use it directly
find . -name *.svg | sort | xargs -I {} bash -c 'gen "$@"' _ {}
find . -name *.svg | sort | xargs -I {} bash -c 'gen "$@"' _ {}

echo "export { default as Icon } from './icon'" >> packages/index.ts
4 changes: 4 additions & 0 deletions scripts/build-comp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#! /usr/bin/bash

find packages -mindepth 2 -type f -name '*.ts' -print0 | \
xargs -P4 -0 -I {} node configs/rollup.comp.js {}
3 changes: 2 additions & 1 deletion publish.sh → scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Do not run this file without setting the environment variables, you will end up fatal error
# If you wish to run this locally, please change the env variable before running this.
rm -rf build
yarn build
node configs/rollup.js
sh scripts/build-comp.sh

cat package.json | grep -v '"version":' | sed "s/\(\"name\": \"@element-plus\/icons\"\)/\1,\n \"version\": \"${TAG_VERSION}\"/g" > build/package.json

Expand Down

0 comments on commit adb9e87

Please sign in to comment.