mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
refactor: refactor build script and @idraw/util export
This commit is contained in:
parent
464b223dbd
commit
11411bd528
9 changed files with 84 additions and 52 deletions
|
|
@ -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"
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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": {
|
||||
|
|
|
|||
1
packages/util/src/default.ts
Normal file
1
packages/util/src/default.ts
Normal file
|
|
@ -0,0 +1 @@
|
|||
export * as default from './index';
|
||||
|
|
@ -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,
|
||||
// };
|
||||
|
|
@ -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' });
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue