mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-06 10:27:22 +00:00
chore: 出码模块无 UI,直接使用 esbuild 来构建更方便更快捷
This commit is contained in:
parent
c94a4fb1df
commit
2177f3f169
3
packages/code-generator/.gitignore
vendored
3
packages/code-generator/.gitignore
vendored
@ -108,3 +108,6 @@ codealike.json
|
||||
|
||||
# def publish
|
||||
.package
|
||||
|
||||
# types
|
||||
types
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
"license": "MIT",
|
||||
"main": "lib/index.js",
|
||||
"module": "es/index.js",
|
||||
"typings": "es/index.d.ts",
|
||||
"typings": "types/index.d.ts",
|
||||
"files": [
|
||||
"bin",
|
||||
"lib",
|
||||
@ -21,11 +21,8 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "jest --watchAll",
|
||||
"build": "npm run build:bs",
|
||||
"build:bs": "rimraf lib es dist && npm run build:cjs && npm run build:esm",
|
||||
"build:cjs": "tsc --module commonjs --outDir lib",
|
||||
"build:esm": "tsc --module es6 --outDir es",
|
||||
"clean": "rimraf es lib dist test-cases/*/*/actual",
|
||||
"build": "npm run clean && node scripts/build",
|
||||
"clean": "rimraf es lib types dist test-cases/*/*/actual",
|
||||
"lint": "eslint --ext .jsx,.js,.ts,.tsx src/",
|
||||
"lintfix": "eslint --ext .jsx,.js,.ts,.tsx --fix src/",
|
||||
"template": "node ./scripts/build-template-static-files.js",
|
||||
@ -95,6 +92,7 @@
|
||||
"@typescript-eslint/eslint-plugin": "^4.12.0",
|
||||
"@typescript-eslint/parser": "^4.12.0",
|
||||
"build-plugin-component": "^0.2.22",
|
||||
"concurrently": "^6.5.1",
|
||||
"cross-env": "^7.0.3",
|
||||
"esbuild": "^0.14.5",
|
||||
"esbuild-plugin-ignore": "^1.1.0",
|
||||
@ -115,8 +113,7 @@
|
||||
"yargs-parser": "^20.2.9"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10.0.0",
|
||||
"install-node": "14.x"
|
||||
"node": ">=10.0.0"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "http://registry.npm.alibaba-inc.com"
|
||||
|
||||
10
packages/code-generator/scripts/build-types
Executable file
10
packages/code-generator/scripts/build-types
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo building types...
|
||||
tsc --outDir types --declaration --emitDeclarationOnly && \
|
||||
echo built types... && \
|
||||
rm -rf types/types/src && \
|
||||
mv types/code-generator/src/* types/ && \
|
||||
rm -rf types/code-generator/src
|
||||
|
||||
|
||||
78
packages/code-generator/scripts/build.js
Normal file
78
packages/code-generator/scripts/build.js
Normal file
@ -0,0 +1,78 @@
|
||||
/* eslint-disable no-console */
|
||||
/* eslint-disable @typescript-eslint/no-require-imports */
|
||||
const _ = require('lodash');
|
||||
const esbuild = require('esbuild');
|
||||
const concurrently = require('concurrently');
|
||||
const argv = require('yargs-parser')(process.argv.slice(2));
|
||||
const packageJson = require('../package.json');
|
||||
|
||||
if (!argv.format) {
|
||||
buildAll();
|
||||
} else {
|
||||
buildFormat(argv.format, argv.out || 'dist');
|
||||
}
|
||||
|
||||
function buildAll() {
|
||||
concurrently(
|
||||
[
|
||||
{ name: 'build:types', command: 'sh scripts/build-types' },
|
||||
{ name: 'build:cjs', command: 'node scripts/build --format=cjs --out=lib' },
|
||||
{ name: 'build:esm', command: 'node scripts/build --format=esm --out=es' },
|
||||
],
|
||||
{
|
||||
prefix: 'name',
|
||||
killOthers: ['failure'],
|
||||
restartTries: 0,
|
||||
},
|
||||
).then(
|
||||
() => {
|
||||
console.log('all done.');
|
||||
},
|
||||
() => {
|
||||
process.exit(1);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
function buildFormat(format, outDir) {
|
||||
try {
|
||||
console.log('building %s...', format);
|
||||
const startTime = Date.now();
|
||||
const result = esbuild.buildSync({
|
||||
entryPoints: ['src/index.ts'],
|
||||
outfile: `${outDir}/index.js`,
|
||||
bundle: true,
|
||||
platform: 'node',
|
||||
target: ['node10'],
|
||||
format,
|
||||
sourcemap: true,
|
||||
sourcesContent: true,
|
||||
define: {
|
||||
process: JSON.stringify({
|
||||
env: {
|
||||
NODE_ENV: 'production',
|
||||
STANDALONE: 'true',
|
||||
},
|
||||
}),
|
||||
},
|
||||
treeShaking: true,
|
||||
external: _.keys(packageJson.dependencies),
|
||||
minify: false,
|
||||
legalComments: 'external',
|
||||
});
|
||||
if (result.errors.length > 0) {
|
||||
throw result.errors;
|
||||
}
|
||||
|
||||
if (result.warnings.length > 0) {
|
||||
result.warnings.forEach((warnings) => {
|
||||
console.warn(warnings);
|
||||
});
|
||||
}
|
||||
|
||||
console.log('built %s in %ds', format, ((Date.now() - startTime) / 1000).toFixed(2));
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
@ -1,3 +1,4 @@
|
||||
import _ from 'lodash';
|
||||
import { COMMON_CHUNK_NAME } from '../../const/generator';
|
||||
|
||||
import {
|
||||
@ -164,23 +165,21 @@ function buildPackageImport(
|
||||
|
||||
// 发现 nodeIdentifier 与 exportName 或者 aliasName 冲突的场景
|
||||
const nodeIdentifiers = depsInfo.map((info) => info.nodeIdentifier).filter(Boolean);
|
||||
const conflictInfos = Object.keys(exportItems)
|
||||
.map((exportName) => {
|
||||
const exportItem = exportItems[exportName];
|
||||
const usedNames = [
|
||||
...exportItem.aliasNames,
|
||||
...(exportItem.needOriginExport || exportItem.aliasNames.length <= 0 ? [exportName] : []),
|
||||
const conflictInfos = _.flatMap(Object.keys(exportItems), (exportName) => {
|
||||
const exportItem = exportItems[exportName];
|
||||
const usedNames = [
|
||||
...exportItem.aliasNames,
|
||||
...(exportItem.needOriginExport || exportItem.aliasNames.length <= 0 ? [exportName] : []),
|
||||
];
|
||||
const conflictNames = usedNames.filter((n) => nodeIdentifiers.indexOf(n) >= 0);
|
||||
if (conflictNames.length > 0) {
|
||||
return [
|
||||
...(conflictNames.indexOf(exportName) >= 0 ? [[exportName, true, exportItem]] : []),
|
||||
...conflictNames.filter((n) => n !== exportName).map((n) => [n, false, exportItem]),
|
||||
];
|
||||
const conflictNames = usedNames.filter((n) => nodeIdentifiers.indexOf(n) >= 0);
|
||||
if (conflictNames.length > 0) {
|
||||
return [
|
||||
...(conflictNames.indexOf(exportName) >= 0 ? [[exportName, true, exportItem]] : []),
|
||||
...conflictNames.filter((n) => n !== exportName).map((n) => [n, false, exportItem]),
|
||||
];
|
||||
}
|
||||
return [];
|
||||
})
|
||||
.flat();
|
||||
}
|
||||
return [];
|
||||
});
|
||||
|
||||
const conflictExports = conflictInfos.filter((c) => c[1]).map((c) => c[0] as string);
|
||||
const conflictAlias = conflictInfos.filter((c) => !c[1]).map((c) => c[0] as string);
|
||||
|
||||
@ -3,5 +3,6 @@
|
||||
"compilerOptions": {
|
||||
"outDir": "lib"
|
||||
},
|
||||
"include": ["./src/"]
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["./tests", "./test-cases", "../types", "node_modules"]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user