From b47bffdf3c484dddb6b6d64481998699525d828e Mon Sep 17 00:00:00 2001 From: Hans Chan Date: Thu, 22 Jul 2021 19:48:15 +0800 Subject: [PATCH] fix(cli): build cli with latest core --- .eslintignore | 6 ++++++ package.json | 2 +- packages/cli/package.json | 2 +- packages/cli/src/cmd/editor/build.js | 27 ++++++++++++++++++++------- 4 files changed, 28 insertions(+), 9 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..4d55f98 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +.circleci +.github +.husky + +dist/ +node_modules/ diff --git a/package.json b/package.json index 644f502..99b684b 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "doc": "dumi dev", "start": "concurrently \"lerna run watch --parallel\" \"cross-env APP_ROOT=example umi dev\"", "example": "concurrently \"lerna run watch --parallel\" \"cross-env APP_ROOT=example umi dev\" \"imove -d\"", - "postinstall": "lerna init && lerna bootstrap && npm link packages/cli", + "postinstall": "npm link packages/cli && lerna init && lerna bootstrap", "prepare": "husky install" }, "jest": { diff --git a/packages/cli/package.json b/packages/cli/package.json index ac24cb2..7a5723e 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -12,7 +12,7 @@ ], "scripts": { "build:editor": "node src/cmd/editor/build.js", - "prepare": "npm run build:editor" + "postinstall": "npm run build:editor" }, "repository": { "type": "git", diff --git a/packages/cli/src/cmd/editor/build.js b/packages/cli/src/cmd/editor/build.js index 38f6ea9..95d97e3 100644 --- a/packages/cli/src/cmd/editor/build.js +++ b/packages/cli/src/cmd/editor/build.js @@ -1,22 +1,35 @@ +#!/usr/bin/env node + /* eslint-disable @typescript-eslint/no-var-requires */ const path = require('path'); const fs = require('fs-extra'); const { lessLoader } = require('esbuild-plugin-less'); -const outfile = path.join(__dirname, 'template/dist/app.bundle.js'); - -// if builded and NOT force re-build, exit -if (fs.existsSync(outfile) && process.argv.indexOf('--force') < 0) { - console.log('imove editor alredy builded'); - return; +// build @imove/core first, if in imove repo +const CORE_DIR = path.join(__dirname, '../../../../core'); +if (fs.pathExistsSync(CORE_DIR)) { + require('child_process').execSync(`cd ${CORE_DIR} && rollup -c`); } +// build js and css for editor +const OUT_FILE = path.join(__dirname, 'template/dist/app.bundle.js'); require('esbuild') .build({ bundle: true, entryPoints: [path.join(__dirname, 'template/app.jsx')], - outfile, + outfile: OUT_FILE, plugins: [ + { + name: 'resolve-multi-react', + setup: (build) => { + build.onResolve({ filter: /^react$/, namespace: 'file' }, () => { + return { + path: require.resolve('react'), + watchFiles: undefined, + }; + }); + }, + }, // fix import('antd/dist/antd.less') { name: 'resolve-antd-dist-less',