Merge branch 'feat/0228' of github.com:alibaba/lowcode-engine into feat/0228

This commit is contained in:
LeoYuan 袁力皓 2023-03-02 10:23:53 +08:00
commit bb770b8e5a
38 changed files with 231 additions and 114 deletions

View File

@ -71,7 +71,7 @@
},
"lifeCycles": {
"componentDidMount": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function() { console.log('componentDidMount'); }"
}
},
@ -91,7 +91,7 @@
"isSync": true
},
"dataHandler": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data;\n}"
}
},
@ -105,13 +105,13 @@
"isSync": true
},
"dataHandler": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data.result;\n}"
}
}
],
"dataHandler": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function (dataMap) {\n console.info(\"All datasources loaded:\", dataMap);\n}"
}
},

View File

@ -71,7 +71,7 @@
},
lifeCycles: {
componentDidMount: {
type: 'JSExpression',
type: 'JSFunction',
value: "function() { console.log('componentDidMount'); }",
},
},
@ -91,7 +91,7 @@
isSync: true,
},
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data;\n}',
},
},
@ -105,13 +105,13 @@
isSync: true,
},
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data.result;\n}',
},
},
],
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (dataMap) {\n console.info("All datasources loaded:", dataMap);\n}',
},
},

View File

@ -136,6 +136,7 @@ export class ProjectBuilder implements IProjectBuilder {
const builders = this.createModuleBuilders({
extraContextData: {
projectRemark: parseResult?.project?.projectRemark,
template: this.template,
},
});
// Generator Code module
@ -320,7 +321,7 @@ export class ProjectBuilder implements IProjectBuilder {
// template: this.template,
inStrictMode: this.inStrictMode,
tolerateEvalErrors: true,
evalErrorsHandler: 'console.error(error)',
evalErrorsHandler: '',
...this.extraContextData,
...extraContextData,
},

View File

@ -1,6 +1,6 @@
/**
* Schema
* API , API
* API API
* export { xxx } from 'xx' export * from 'xxx')
* API tests/public
*/
@ -51,6 +51,7 @@ export default {
},
plugins: {
common: {
/**
* ES Module
* @deprecated please use esModule

View File

@ -13,12 +13,12 @@ import {
} from '../../../types';
export interface PluginConfig {
fileType: string;
fileType?: string;
implementType: 'inConstructor' | 'insMember' | 'hooks';
}
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
const cfg: PluginConfig & { fileType: string } = {
fileType: FileType.JSX,
implementType: 'inConstructor',
...config,

View File

@ -11,6 +11,7 @@ import {
FileType,
ICodeStruct,
} from '../../../types';
import { getSlotRelativePath } from '../../../utils/pathHelper';
export interface PluginConfig {
fileType: string;
@ -31,9 +32,8 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
type: ChunkType.STRING,
fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.InternalDepsImport,
// TODO: 下面这个路径有没有更好的方式来获取?而非写死
content: `
import * as __$$i18n from '../../i18n';
import * as __$$i18n from '${getSlotRelativePath({ contextData: next.contextData, from: 'components', to: 'i18n' })}';
`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
});

View File

@ -11,18 +11,18 @@ import {
FileType,
ICodeStruct,
IContainerInfo,
IProjectTemplate,
} from '../../../types';
import { getSlotRelativePath } from '../../../utils/pathHelper';
export interface PluginConfig {
fileType: string;
fileType?: string;
/** prefer using class property to define utils */
preferClassProperty?: boolean;
}
const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) => {
const cfg: PluginConfig = {
const cfg: PluginConfig & { fileType: string } = {
fileType: FileType.JSX,
...config,
};
@ -36,26 +36,12 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
next.contextData.useRefApi = true;
const useRef = !!ir.analyzeResult?.isUsingRef;
// const isSingleComponent = next.contextData?.projectRemark?.isSingleComponent;
// const template = next.contextData?.template;
// function getRelativeUtilsPath(template: IProjectTemplate, isSingleComponent: boolean) {
// let relativeUtilsPath = '../../utils';
// const utilsPath = template.slots.utils.path;
// if (ir.containerType === 'Component') {
// // TODO: isSingleComponent
// relativeUtilsPath = getRelativePath(template.slots.components.path.join('/'), utilsPath.join('/'));
// }
// return relativeUtilsPath;
// }
next.chunks.push({
type: ChunkType.STRING,
fileType: cfg.fileType,
name: COMMON_CHUNK_NAME.InternalDepsImport,
// TODO: 下面这个路径有没有更好的方式来获取?而非写死
content: `
import utils${useRef ? ', { RefsManager }' : ''} from '../../utils';
import utils${useRef ? ', { RefsManager }' : ''} from '${getSlotRelativePath({ contextData: next.contextData, from: 'components', to: 'utils' })}';
`,
linkAfter: [COMMON_CHUNK_NAME.ExternalDepsImport],
});

View File

@ -25,8 +25,7 @@ const pluginFactory: BuilderComponentPluginFactory<unknown> = () => {
content: `
const i18nConfig = ${i18nStr};
// let locale = typeof navigator === 'object' && typeof navigator.language === 'string' ? navigator.language : 'zh-CN';
let locale = 'zh-CN';
let locale = typeof navigator === 'object' && typeof navigator.language === 'string' ? navigator.language : 'zh-CN';
const getLocale = () => locale;

View File

@ -271,7 +271,7 @@ export function parseExpressionConvertThis2Context(
const localVariablesSet = new Set(localVariables);
let thisScopeLevel = -1;
let thisScopeLevel = CROSS_THIS_SCOPE_TYPE_NODE[exprAst.type] ? -1 : 0;
traverse(fileAst, {
enter(path) {
if (CROSS_THIS_SCOPE_TYPE_NODE[path.node.type]) {
@ -303,7 +303,7 @@ export function parseExpressionConvertThis2Context(
}
// 替换 this (只在顶层替换)
if (thisScopeLevel === 0) {
if (thisScopeLevel <= 0) {
obj.replaceWith(t.identifier(contextName));
}
},
@ -317,7 +317,7 @@ export function parseExpressionConvertThis2Context(
return;
}
if (thisScopeLevel === 0) {
if (thisScopeLevel <= 0) {
path.replaceWith(t.identifier(contextName));
}
},

View File

@ -12,6 +12,7 @@ import * as version from './version';
import * as scope from './Scope';
import * as expressionParser from './expressionParser';
import * as dataSource from './dataSource';
import * as pathHelper from './pathHelper';
export {
common,
@ -27,4 +28,5 @@ export {
scope,
expressionParser,
dataSource,
pathHelper,
};

View File

@ -0,0 +1,41 @@
import { IContextData } from '../types';
function relativePath(from: string[], to: string[]): string[] {
const length = Math.min(from.length, to.length);
let samePartsLength = length;
for (let i = 0; i < length; i++) {
if (from[i] !== to[i]) {
samePartsLength = i;
break;
}
}
if (samePartsLength === 0) {
return to;
}
let outputParts = [];
for (let i = samePartsLength; i < from.length; i++) {
outputParts.push('..');
}
outputParts = [...outputParts, ...to.slice(samePartsLength)];
if (outputParts[0] !== '..') {
outputParts.unshift('.');
}
return outputParts;
}
export function getSlotRelativePath(options: {
contextData: IContextData;
from: string;
to: string;
}) {
const { contextData, from, to } = options;
const isSingleComponent = contextData?.extraContextData?.projectRemark?.isSingleComponent;
const template = contextData?.extraContextData?.template;
let toPath = template.slots[to].path;
toPath = [...toPath, template.slots[to].fileName!];
let fromPath = template.slots[from].path;
if (!isSingleComponent && ['components', 'pages'].indexOf(from) !== -1) {
fromPath = [...fromPath, 'pageName'];
}
return relativePath(fromPath, toPath).join('/');
}

View File

@ -253,7 +253,6 @@ class Home$$Page extends Component {
if (!response.success) {
throw new Error(response.message);
}
return response.data;
},
isInit: true,
@ -280,7 +279,6 @@ class Home$$Page extends Component {
if (!response.success) {
throw new Error(response.message);
}
return response.data.result;
},
isInit: true,

View File

@ -31,9 +31,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -71,10 +71,10 @@ class Test$$Page extends React.Component {
type: 'urlParams',
isInit: function () {
return undefined;
},
}.bind(_this),
options: function () {
return undefined;
},
}.bind(_this),
},
{
id: 'user',
@ -85,17 +85,16 @@ class Test$$Page extends React.Component {
uri: 'https://shs.xxx.com/mock/1458/demo/user',
isSync: true,
};
},
}.bind(_this),
dataHandler: function (response) {
if (!response.data.success) {
throw new Error(response.data.message);
}
return response.data.data;
},
isInit: function () {
return undefined;
},
}.bind(_this),
},
{
id: 'orders',
@ -106,17 +105,16 @@ class Test$$Page extends React.Component {
uri: 'https://shs.xxx.com/mock/1458/demo/orders',
isSync: true,
};
},
}.bind(_this),
dataHandler: function (response) {
if (!response.data.success) {
throw new Error(response.data.message);
}
return response.data.data.result;
},
isInit: function () {
return undefined;
},
}.bind(_this),
},
],
dataHandler: function (dataMap) {

View File

@ -71,7 +71,7 @@
},
"lifeCycles": {
"componentDidMount": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function() { console.log('componentDidMount'); }"
}
},

View File

@ -34,9 +34,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -67,10 +67,10 @@ class Aaaa$$Page extends React.Component {
return {
uri: '',
};
},
}.bind(_this),
isInit: function () {
return undefined;
},
}.bind(_this),
},
],
};

View File

@ -29,9 +29,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -71,7 +71,7 @@
},
"lifeCycles": {
"componentDidMount": {
"type": "JSExpression",
"type": "JSFunction",
"value": "function() { console.log('componentDidMount'); }"
}
},

View File

@ -29,9 +29,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -31,9 +31,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -76,7 +76,7 @@ class Test$$Page extends React.Component {
type: 'fetch',
isInit: function () {
return true;
},
}.bind(_this),
options: function () {
return {
params: {},
@ -86,7 +86,7 @@ class Test$$Page extends React.Component {
headers: {},
uri: 'https://mocks.xxx.com/mock/jjpin/user/list',
};
},
}.bind(_this),
id: 'users',
},
],

View File

@ -32,9 +32,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -31,9 +31,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -71,10 +71,10 @@ class Test$$Page extends React.Component {
type: 'urlParams',
isInit: function () {
return undefined;
},
}.bind(_this),
options: function () {
return undefined;
},
}.bind(_this),
},
{
id: 'user',
@ -85,17 +85,16 @@ class Test$$Page extends React.Component {
uri: 'https://shs.xxx.com/mock/1458/demo/user',
isSync: true,
};
},
}.bind(_this),
dataHandler: function (response) {
if (!response.data.success) {
throw new Error(response.data.message);
}
return response.data.data;
},
isInit: function () {
return undefined;
},
}.bind(_this),
},
{
id: 'orders',
@ -106,17 +105,16 @@ class Test$$Page extends React.Component {
uri: 'https://shs.xxx.com/mock/1458/demo/orders',
isSync: true,
};
},
}.bind(_this),
dataHandler: function (response) {
if (!response.data.success) {
throw new Error(response.data.message);
}
return response.data.data.result;
},
isInit: function () {
return undefined;
},
}.bind(_this),
},
],
dataHandler: function (dataMap) {

View File

@ -71,7 +71,7 @@
},
lifeCycles: {
componentDidMount: {
type: 'JSExpression',
type: 'JSFunction',
value: "function() { console.log('componentDidMount'); }",
},
},
@ -91,7 +91,7 @@
isSync: true,
},
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data;\n}',
},
},
@ -105,13 +105,13 @@
isSync: true,
},
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (response) {\nif (!response.data.success){\n throw new Error(response.data.message);\n }\n return response.data.data.result;\n}',
},
},
],
dataHandler: {
type: 'JSExpression',
type: 'JSFunction',
value: 'function (dataMap) {\n console.info("All datasources loaded:", dataMap);\n}',
},
},

View File

@ -31,9 +31,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -151,6 +151,7 @@ class Test$$Page extends React.Component {
onOkModifyDialogThird() {
//
this.setState({
currentStep: 0,
isModifyDialogVisible: false,
@ -159,6 +160,7 @@ class Test$$Page extends React.Component {
onCancelModifyDialogThird() {
//
this.setState({
isModifyDialogVisible: false,
});

View File

@ -30,9 +30,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -63,10 +63,10 @@ class Example$$Page extends React.Component {
return {
uri: 'https://api.example.com/user/list',
};
},
}.bind(_this),
isInit: function () {
return undefined;
},
}.bind(_this),
},
],
};

View File

@ -30,9 +30,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -59,14 +59,14 @@ class $$Page extends React.Component {
id: 'todos',
isInit: function () {
return true;
},
}.bind(_this),
type: 'jsonp',
options: function () {
return {
method: 'GET',
uri: 'https://a0ee9135-6a7f-4c0f-a215-f0f247ad907d.mock.pstmn.io',
};
},
}.bind(_this),
dataHandler: function dataHandler(data) {
return data.data;
},

View File

@ -32,9 +32,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -65,7 +65,6 @@ class Test$$Page extends React.Component {
};
this.__jp__init();
this.statusDesc = {
0: '失败',
1: '成功',
@ -163,7 +162,6 @@ class Test$$Page extends React.Component {
if (!item) {
return '暂无结果';
}
const { channel, plat, version, status } = item;
return [channel, plat, version, status].join('-');
}

View File

@ -32,9 +32,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -67,7 +67,6 @@ class Test$$Page extends React.Component {
};
this.__jp__init();
this.statusDesc = {
0: '失败',
1: '成功',
@ -202,12 +201,10 @@ class Test$$Page extends React.Component {
componentDidMount() {
this.$ds.resolve('PROJECTS');
if (this.userTimeout) {
clearTimeout(this.userTimeout);
this.userTimeout = null;
}
if (this.projectTimeout) {
clearTimeout(this.projectTimeout);
this.projectTimeout = null;

View File

@ -25,9 +25,16 @@
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
"ideMode": { "name": "ice-react" },
"iceworks": { "type": "react", "adapter": "adapter-react-v3" },
"engines": { "node": ">=8.0.0" },
"ideMode": {
"name": "ice-react"
},
"iceworks": {
"type": "react",
"adapter": "adapter-react-v3"
},
"engines": {
"node": ">=8.0.0"
},
"repository": {
"type": "git",
"url": "http://gitlab.xxx.com/msd/leak-scan/tree/master"

View File

@ -19,7 +19,12 @@ export function App() {
`;
exports[`postprocessor/prettier should works for json file 1`] = `
"{ \\"components\\": [\\"Button\\", \\"Block\\"] }
"{
\\"components\\": [
\\"Button\\",
\\"Block\\"
]
}
"
`;