refactor: refactor build script and @idraw/util export

This commit is contained in:
chenshenhai 2022-02-27 15:35:23 +08:00
parent 464b223dbd
commit 11411bd528
9 changed files with 84 additions and 52 deletions

View file

@ -25,7 +25,8 @@ module.exports = {
"modulePaths": [
"<rootDir>"
],
"testRegex": "(/packages/([^\/]{1,})/__tests__/.*)\\.test.ts$",
// "testRegex": "(/packages/([^\/]{1,})/__tests__/.*)\\.test.ts$",
"testRegex": "(/packages/util/__tests__/.*)\\.test.ts$",
"setupFiles": [
"jest-canvas-mock"
]

View file

@ -4,8 +4,8 @@
"scripts": {
"start": "node ./scripts/dev-vite.js",
"dev": "node ./scripts/dev-rollup.js",
"build": "npm run build:src && npm run build:min",
"build:src": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build-bundle.js",
"build": "npm run build:bundle && npm run build:min",
"build:bundle": "NODE_ENV=production BUILD_MODE=reset node ./scripts/build-bundle.js",
"build:mod": "node ./scripts/build-module.js",
"build:min": "node ./scripts/minify.js",
"snapshot": "node ./scripts/build.js && node ./scripts/snapshot.js",

View file

@ -1,16 +1,22 @@
import util from '../src';
import util from '../src/default';
const types = {
time: 'Object',
loader: 'Object',
file: 'Object',
color: 'Object',
uuid: 'Object',
istype: 'Object',
data: 'Object',
is: 'Object',
check: 'Object',
Context: 'Function',
'Context': 'Function',
'check': 'Object',
'compose': 'Function',
'createUUID': 'Function',
'deepClone': 'Function',
'delay': 'Function',
'downloadImageFromCanvas': 'Function',
'is': 'Object',
'isColorStr': 'Function',
'istype': 'Object',
'loadHTML': 'AsyncFunction',
'loadImage': 'Function',
'loadSVG': 'AsyncFunction',
'throttle': 'Function',
'toColorHexNum': 'Function',
'toColorHexStr': 'Function'
}
function getType (data: any): string {

View file

@ -1,9 +1,7 @@
import Context from './../../src/lib/context';
import util from './../../src'
import { deepClone } from './../../src/index'
import { getData } from './data';
const { deepClone } = util.data;
describe('@idraw/board: src/lib/context', () => {
const options = {
width: 600,

View file

@ -3,7 +3,7 @@
"version": "0.2.0-alpha.26",
"description": "",
"main": "dist/index.cjs.js",
"module": "dist/index.es.js",
"module": "dist/index.esm.js",
"unpkg": "dist/index.global.js",
"types": "dist/index.d.ts",
"scripts": {

View file

@ -0,0 +1 @@
export * as default from './index';

View file

@ -9,33 +9,53 @@ import Context from './lib/context';
import is from './lib/is';
import check from './lib/check';
export default {
export {
is,
check,
time: {
delay,
compose,
throttle,
},
loader: {
loadImage,
loadSVG,
loadHTML,
},
file: {
downloadImageFromCanvas,
},
color: {
toColorHexStr,
toColorHexNum,
isColorStr,
},
uuid: {
createUUID
},
delay,
compose,
throttle,
loadImage,
loadSVG,
loadHTML,
downloadImageFromCanvas,
toColorHexStr,
toColorHexNum,
isColorStr,
createUUID,
istype,
data: {
deepClone,
},
Context: Context,
};
deepClone,
Context,
}
// export default {
// is,
// check,
// time: {
// delay,
// compose,
// throttle,
// },
// loader: {
// loadImage,
// loadSVG,
// loadHTML,
// },
// file: {
// downloadImageFromCanvas,
// },
// color: {
// toColorHexStr,
// toColorHexNum,
// isColorStr,
// },
// uuid: {
// createUUID
// },
// istype,
// data: {
// deepClone,
// },
// Context: Context,
// };

View file

@ -20,7 +20,13 @@ async function main() {
}
await
execa('rollup', [ '-c', './scripts/rollup.config.js', ], { stdio: 'inherit' });
execa(
'rollup',
[
'-c',
'./scripts/rollup.config.js',
`--target-pkg=${process.argv[2] || ''}`,
], { stdio: 'inherit' });
}

View file

@ -13,7 +13,7 @@ const stylePlugin = require('./util/style-plugin');
const resolveFile = function(names = []) {
return path.join(__dirname, '..', 'packages', ...names)
}
const targetMod = process.argv[5];
const targetMod = process.argv[5] || process.argv[4];
const packages = getTargetPackage(targetMod);
const modules = [];
@ -31,7 +31,7 @@ for(let i = 0; i < packages.length; i++) {
// });
} else {
modules.push({
input: resolveFile([pkg.dirName, 'src', 'index.ts']),
input: resolveFile([pkg.dirName, 'src', 'default.ts']),
output: resolveFile([pkg.dirName, 'dist', 'index.global.js']),
name: pkg.globalName,
format: 'iife',
@ -45,7 +45,7 @@ for(let i = 0; i < packages.length; i++) {
// plugins: [],
// });
modules.push({
input: resolveFile([pkg.dirName, 'src', 'index.ts']),
input: resolveFile([pkg.dirName, 'src', 'default.ts']),
output: resolveFile([pkg.dirName, 'dist', 'index.cjs.js']),
name: pkg.globalName,
format: 'cjs',
@ -55,8 +55,8 @@ for(let i = 0; i < packages.length; i++) {
external,
});
modules.push({
input: resolveFile([pkg.dirName, 'src', 'index.ts']),
output: resolveFile([pkg.dirName, 'dist', 'index.es.js']),
input: resolveFile([pkg.dirName, 'src', 'default.ts']),
output: resolveFile([pkg.dirName, 'dist', 'index.esm.js']),
name: pkg.globalName,
esModule: true,
format: 'es',
@ -115,7 +115,7 @@ function createConfigItem(params, opts = {}) {
function createDevConfig(mods) {
const configs = mods.map((mod) => {
const cfg = createConfigItem(mod, {
minify: mod.output.endsWith('.mini.js'),
minify: mod.output.endsWith('.min.js'),
});
return cfg;
});