mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-04-20 12:28:08 +00:00
merge
This commit is contained in:
commit
8cbdd383ce
@ -7,21 +7,28 @@
|
|||||||
"lib"
|
"lib"
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "rimraf lib && tsc",
|
"compile": "rimraf lib && tsc",
|
||||||
|
"build": "rimraf lib && webpack",
|
||||||
"demo": "ts-node -r tsconfig-paths/register ./src/demo/main.ts",
|
"demo": "ts-node -r tsconfig-paths/register ./src/demo/main.ts",
|
||||||
"test": "ava"
|
"test": "ava"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ali/am-eslint-config": "*",
|
"@ali/am-eslint-config": "*",
|
||||||
|
"@types/prettier": "^1.19.1",
|
||||||
"change-case": "^3.1.0",
|
"change-case": "^3.1.0",
|
||||||
|
"prettier": "^2.0.2",
|
||||||
"short-uuid": "^3.1.1"
|
"short-uuid": "^3.1.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"ava": "^1.0.1",
|
"ava": "^1.0.1",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
|
"ts-loader": "^6.2.2",
|
||||||
"ts-node": "^7.0.1",
|
"ts-node": "^7.0.1",
|
||||||
"tsconfig-paths": "^3.9.0",
|
"tsconfig-paths": "^3.9.0",
|
||||||
"typescript": "^3.8.3"
|
"tsconfig-paths-webpack-plugin": "^3.2.0",
|
||||||
|
"webpack": "^4.42.1",
|
||||||
|
"webpack-cli": "^3.3.11",
|
||||||
|
"webpack-node-externals": "^1.7.2"
|
||||||
},
|
},
|
||||||
"ava": {
|
"ava": {
|
||||||
"compileEnhancements": false,
|
"compileEnhancements": false,
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import {
|
|||||||
ICompiledModule,
|
ICompiledModule,
|
||||||
IModuleBuilder,
|
IModuleBuilder,
|
||||||
IResultFile,
|
IResultFile,
|
||||||
|
PostProcessor,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import { COMMON_SUB_MODULE_NAME } from '../const/generator';
|
import { COMMON_SUB_MODULE_NAME } from '../const/generator';
|
||||||
@ -17,9 +18,11 @@ import ResultFile from '../model/ResultFile';
|
|||||||
export function createModuleBuilder(
|
export function createModuleBuilder(
|
||||||
options: {
|
options: {
|
||||||
plugins: BuilderComponentPlugin[];
|
plugins: BuilderComponentPlugin[];
|
||||||
|
postProcessors: PostProcessor[];
|
||||||
mainFileName?: string;
|
mainFileName?: string;
|
||||||
} = {
|
} = {
|
||||||
plugins: [],
|
plugins: [],
|
||||||
|
postProcessors: [],
|
||||||
},
|
},
|
||||||
): IModuleBuilder {
|
): IModuleBuilder {
|
||||||
const chunkGenerator = new ChunkBuilder(options.plugins);
|
const chunkGenerator = new ChunkBuilder(options.plugins);
|
||||||
@ -33,7 +36,7 @@ export function createModuleBuilder(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const files: IResultFile[] = [];
|
let files: IResultFile[] = [];
|
||||||
|
|
||||||
const { chunks } = await chunkGenerator.run(input);
|
const { chunks } = await chunkGenerator.run(input);
|
||||||
chunks.forEach(fileChunkList => {
|
chunks.forEach(fileChunkList => {
|
||||||
@ -46,6 +49,18 @@ export function createModuleBuilder(
|
|||||||
files.push(file);
|
files.push(file);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (options.postProcessors.length > 0) {
|
||||||
|
files = files.map(file => {
|
||||||
|
let content = file.content;
|
||||||
|
const type = file.ext;
|
||||||
|
options.postProcessors.forEach(processer => {
|
||||||
|
content = processer(content, type);
|
||||||
|
});
|
||||||
|
|
||||||
|
return new ResultFile(file.name, type, content);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
files,
|
files,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -8,10 +8,11 @@ import {
|
|||||||
IResultDir,
|
IResultDir,
|
||||||
IResultFile,
|
IResultFile,
|
||||||
ISchemaParser,
|
ISchemaParser,
|
||||||
|
PostProcessor,
|
||||||
} from '../types';
|
} from '../types';
|
||||||
|
|
||||||
import ResultDir from '@/model/ResultDir';
|
import ResultDir from '@/model/ResultDir';
|
||||||
import SchemaParser from '@/parse/SchemaParser';
|
import SchemaParser from '@/parser/SchemaParser';
|
||||||
|
|
||||||
import { createModuleBuilder } from '@/generator/ModuleBuilder';
|
import { createModuleBuilder } from '@/generator/ModuleBuilder';
|
||||||
|
|
||||||
@ -40,16 +41,20 @@ function getDirFromRoot(root: IResultDir, path: string[]): IResultDir {
|
|||||||
export class ProjectBuilder implements IProjectBuilder {
|
export class ProjectBuilder implements IProjectBuilder {
|
||||||
private template: IProjectTemplate;
|
private template: IProjectTemplate;
|
||||||
private plugins: IProjectPlugins;
|
private plugins: IProjectPlugins;
|
||||||
|
private postProcessors: PostProcessor[];
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
template,
|
template,
|
||||||
plugins,
|
plugins,
|
||||||
|
postProcessors,
|
||||||
}: {
|
}: {
|
||||||
template: IProjectTemplate;
|
template: IProjectTemplate;
|
||||||
plugins: IProjectPlugins;
|
plugins: IProjectPlugins;
|
||||||
|
postProcessors: PostProcessor[];
|
||||||
}) {
|
}) {
|
||||||
this.template = template;
|
this.template = template;
|
||||||
this.plugins = plugins;
|
this.plugins = plugins;
|
||||||
|
this.postProcessors = postProcessors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async generateProject(schema: IProjectSchema): Promise<IResultDir> {
|
public async generateProject(schema: IProjectSchema): Promise<IResultDir> {
|
||||||
@ -212,45 +217,57 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
|
|
||||||
builders.components = createModuleBuilder({
|
builders.components = createModuleBuilder({
|
||||||
plugins: this.plugins.components,
|
plugins: this.plugins.components,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
|
});
|
||||||
|
builders.pages = createModuleBuilder({
|
||||||
|
plugins: this.plugins.pages,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
builders.pages = createModuleBuilder({ plugins: this.plugins.pages });
|
|
||||||
builders.router = createModuleBuilder({
|
builders.router = createModuleBuilder({
|
||||||
plugins: this.plugins.router,
|
plugins: this.plugins.router,
|
||||||
mainFileName: this.template.slots.router.fileName,
|
mainFileName: this.template.slots.router.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
builders.entry = createModuleBuilder({
|
builders.entry = createModuleBuilder({
|
||||||
plugins: this.plugins.entry,
|
plugins: this.plugins.entry,
|
||||||
mainFileName: this.template.slots.entry.fileName,
|
mainFileName: this.template.slots.entry.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
builders.globalStyle = createModuleBuilder({
|
builders.globalStyle = createModuleBuilder({
|
||||||
plugins: this.plugins.globalStyle,
|
plugins: this.plugins.globalStyle,
|
||||||
mainFileName: this.template.slots.globalStyle.fileName,
|
mainFileName: this.template.slots.globalStyle.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
builders.htmlEntry = createModuleBuilder({
|
builders.htmlEntry = createModuleBuilder({
|
||||||
plugins: this.plugins.htmlEntry,
|
plugins: this.plugins.htmlEntry,
|
||||||
mainFileName: this.template.slots.htmlEntry.fileName,
|
mainFileName: this.template.slots.htmlEntry.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
builders.packageJSON = createModuleBuilder({
|
builders.packageJSON = createModuleBuilder({
|
||||||
plugins: this.plugins.packageJSON,
|
plugins: this.plugins.packageJSON,
|
||||||
mainFileName: this.template.slots.packageJSON.fileName,
|
mainFileName: this.template.slots.packageJSON.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (this.template.slots.constants && this.plugins.constants) {
|
if (this.template.slots.constants && this.plugins.constants) {
|
||||||
builders.constants = createModuleBuilder({
|
builders.constants = createModuleBuilder({
|
||||||
plugins: this.plugins.constants,
|
plugins: this.plugins.constants,
|
||||||
mainFileName: this.template.slots.constants.fileName,
|
mainFileName: this.template.slots.constants.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.template.slots.utils && this.plugins.utils) {
|
if (this.template.slots.utils && this.plugins.utils) {
|
||||||
builders.utils = createModuleBuilder({
|
builders.utils = createModuleBuilder({
|
||||||
plugins: this.plugins.utils,
|
plugins: this.plugins.utils,
|
||||||
mainFileName: this.template.slots.utils.fileName,
|
mainFileName: this.template.slots.utils.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if (this.template.slots.i18n && this.plugins.i18n) {
|
if (this.template.slots.i18n && this.plugins.i18n) {
|
||||||
builders.i18n = createModuleBuilder({
|
builders.i18n = createModuleBuilder({
|
||||||
plugins: this.plugins.i18n,
|
plugins: this.plugins.i18n,
|
||||||
mainFileName: this.template.slots.i18n.fileName,
|
mainFileName: this.template.slots.i18n.fileName,
|
||||||
|
postProcessors: this.postProcessors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -261,12 +278,15 @@ export class ProjectBuilder implements IProjectBuilder {
|
|||||||
export function createProjectBuilder({
|
export function createProjectBuilder({
|
||||||
template,
|
template,
|
||||||
plugins,
|
plugins,
|
||||||
|
postProcessors,
|
||||||
}: {
|
}: {
|
||||||
template: IProjectTemplate;
|
template: IProjectTemplate;
|
||||||
plugins: IProjectPlugins;
|
plugins: IProjectPlugins;
|
||||||
|
postProcessors: PostProcessor[];
|
||||||
}): IProjectBuilder {
|
}): IProjectBuilder {
|
||||||
return new ProjectBuilder({
|
return new ProjectBuilder({
|
||||||
template,
|
template,
|
||||||
plugins,
|
plugins,
|
||||||
|
postProcessors,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
import { createProjectBuilder } from '@/generator/ProjectBuilder';
|
import { createProjectBuilder } from '@/generator/ProjectBuilder';
|
||||||
|
import { createDiskPublisher } from '@/publisher/disk';
|
||||||
import createIceJsProjectBuilder from '@/solutions/icejs';
|
import createIceJsProjectBuilder from '@/solutions/icejs';
|
||||||
|
|
||||||
export * from './types';
|
export * from './types';
|
||||||
@ -12,4 +13,7 @@ export default {
|
|||||||
solutions: {
|
solutions: {
|
||||||
icejs: createIceJsProjectBuilder,
|
icejs: createIceJsProjectBuilder,
|
||||||
},
|
},
|
||||||
|
publishers: {
|
||||||
|
disk: createDiskPublisher,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
3
packages/code-generator/src/postprocessor/index.ts
Normal file
3
packages/code-generator/src/postprocessor/index.ts
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
import prettier from './prettier';
|
||||||
|
|
||||||
|
export { prettier };
|
||||||
22
packages/code-generator/src/postprocessor/prettier/index.ts
Normal file
22
packages/code-generator/src/postprocessor/prettier/index.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import prettier from 'prettier';
|
||||||
|
|
||||||
|
import { PostProcessor } from '@/types';
|
||||||
|
|
||||||
|
const PARSERS = ['css', 'scss', 'less', 'json', 'html', 'vue'];
|
||||||
|
|
||||||
|
const codePrettier: PostProcessor = (content: string, fileType: string) => {
|
||||||
|
let parser: prettier.BuiltInParserName;
|
||||||
|
if (fileType === 'js' || fileType === 'jsx') {
|
||||||
|
parser = 'babel';
|
||||||
|
} else if (PARSERS.indexOf(fileType) >= 0) {
|
||||||
|
parser = fileType as prettier.BuiltInParserName;
|
||||||
|
} else {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prettier.format(content, {
|
||||||
|
parser,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export default codePrettier;
|
||||||
@ -21,6 +21,8 @@ import template from '@/plugins/project/framework/icejs/template';
|
|||||||
import i18n from '@/plugins/project/i18n';
|
import i18n from '@/plugins/project/i18n';
|
||||||
import utils from '@/plugins/project/utils';
|
import utils from '@/plugins/project/utils';
|
||||||
|
|
||||||
|
import { prettier } from '@/postprocessor';
|
||||||
|
|
||||||
export default function createIceJsProjectBuilder(): IProjectBuilder {
|
export default function createIceJsProjectBuilder(): IProjectBuilder {
|
||||||
return createProjectBuilder({
|
return createProjectBuilder({
|
||||||
template,
|
template,
|
||||||
@ -56,5 +58,6 @@ export default function createIceJsProjectBuilder(): IProjectBuilder {
|
|||||||
htmlEntry: [iceJsEntryHtml],
|
htmlEntry: [iceJsEntryHtml],
|
||||||
packageJSON: [iceJsPackageJSON],
|
packageJSON: [iceJsPackageJSON],
|
||||||
},
|
},
|
||||||
|
postProcessors: [prettier],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -141,3 +141,5 @@ export interface IProjectPlugins {
|
|||||||
export interface IProjectBuilder {
|
export interface IProjectBuilder {
|
||||||
generateProject(schema: IProjectSchema): Promise<IResultDir>;
|
generateProject(schema: IProjectSchema): Promise<IResultDir>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type PostProcessor = (content: string, fileType: string) => string;
|
||||||
|
|||||||
@ -1,14 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.json",
|
"extends": "../../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es5",
|
||||||
"module": "commonjs",
|
"strictNullChecks": true,
|
||||||
"outDir": "lib",
|
"inlineSources": false,
|
||||||
|
"lib": ["es6"],
|
||||||
|
"downlevelIteration": true,
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
},
|
},
|
||||||
|
"outDir": "./lib",
|
||||||
"types": ["node"],
|
"types": ["node"],
|
||||||
"baseUrl": ".", /* Base directory to resolve non-absolute module names. */
|
"baseUrl": "." /* Base directory to resolve non-absolute module names. */
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"src/**/*"
|
"src/**/*"
|
||||||
|
|||||||
31
packages/code-generator/webpack.config.js
Normal file
31
packages/code-generator/webpack.config.js
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
const path = require('path');
|
||||||
|
const nodeExternals = require('webpack-node-externals');
|
||||||
|
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
mode: 'production',
|
||||||
|
target: 'node',
|
||||||
|
entry: {
|
||||||
|
index: './src/index.ts',
|
||||||
|
// demo: './src/demo/main.ts',
|
||||||
|
},
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.tsx?$/,
|
||||||
|
use: 'ts-loader',
|
||||||
|
exclude: /node_modules/,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
resolve: {
|
||||||
|
extensions: [ '.tsx', '.ts', '.js' ],
|
||||||
|
plugins: [new TsconfigPathsPlugin({/* options: see below */})],
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
// filename: 'bundle.js',
|
||||||
|
filename: '[name].js',
|
||||||
|
path: path.resolve(__dirname, 'lib'),
|
||||||
|
},
|
||||||
|
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
|
||||||
|
};
|
||||||
@ -1,7 +1,8 @@
|
|||||||
|
import './style.less';
|
||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import LowStyleSetter from '@ali/lc-style-setter';
|
import LowStyleSetter from '@ali/lc-style-setter';
|
||||||
import './style.less';
|
import { globalLocale } from '@ali/lowcode-globals';
|
||||||
|
|
||||||
export default class StyleSetter extends Component{
|
export default class StyleSetter extends Component{
|
||||||
|
|
||||||
@ -16,7 +17,7 @@ export default class StyleSetter extends Component{
|
|||||||
value: {},
|
value: {},
|
||||||
onChange: () => {},
|
onChange: () => {},
|
||||||
placeholder: '',
|
placeholder: '',
|
||||||
locale: 'zh-CN'
|
locale: globalLocale.getLocale() || 'en-US'
|
||||||
};
|
};
|
||||||
|
|
||||||
onChange = (val: any) => {
|
onChange = (val: any) => {
|
||||||
@ -25,11 +26,10 @@ export default class StyleSetter extends Component{
|
|||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
console.log(this.props);
|
|
||||||
const { value } = this.props;
|
const { value } = this.props;
|
||||||
return (
|
return (
|
||||||
<div className="lc-block-setter">
|
<div className="lc-block-setter">
|
||||||
<LowStyleSetter value={value} onChange={this.onChange} />
|
<LowStyleSetter {...this.props} value={value} onChange={this.onChange} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user