Merge pull request #227 from alibaba/fix/parse-default-value

fix no defaultValue in ts parser
This commit is contained in:
林熠 2022-03-30 14:03:11 +08:00 committed by GitHub
commit 071e1e975d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "@alilc/lowcode-material-parser", "name": "@alilc/lowcode-material-parser",
"version": "1.0.1", "version": "1.0.1-beta.3",
"description": "material parser for Ali lowCode engine", "description": "material parser for Ali lowCode engine",
"main": "lib/index.js", "main": "lib/index.js",
"files": [ "files": [
@ -18,6 +18,8 @@
"@types/prop-types": "^15.7.3", "@types/prop-types": "^15.7.3",
"copy-webpack-plugin": "^9.1.0", "copy-webpack-plugin": "^9.1.0",
"copyfiles": "^2.4.1", "copyfiles": "^2.4.1",
"eslint": "^8.12.0",
"eslint-config-ali": "^14.0.0",
"jest": "^26.6.3", "jest": "^26.6.3",
"js-yaml": "^3.13.1", "js-yaml": "^3.13.1",
"json-schema-to-typescript": "^8.2.0", "json-schema-to-typescript": "^8.2.0",

View File

@ -286,9 +286,11 @@ export function transformItem(name: string, item: any) {
// if ('computed' in defaultValue) { // if ('computed' in defaultValue) {
// val = val.value; // val = val.value;
try { try {
const value = safeEval(defaultValue.value); if (isEvaluable(defaultValue.value)) {
if (isEvaluable(value)) { const value = safeEval(`'${defaultValue.value}'`);
result.defaultValue = value; result.defaultValue = value;
} else {
result.defaultValue = defaultValue.value;
} }
} catch (e) { } catch (e) {
log(e); log(e);

View File

@ -13,6 +13,14 @@ export async function isNPMInstalled(args: {
return pathExists(path.join(args.workDir, 'node_modules')); return pathExists(path.join(args.workDir, 'node_modules'));
} }
export async function isNPMModuleInstalled(
args: { workDir: string; moduleDir: string; npmClient?: string },
name: string,
) {
const modulePkgJsonPath = path.resolve(args.workDir, 'node_modules', name, 'package.json');
return pathExists(modulePkgJsonPath);
}
export async function install(args: { workDir: string; moduleDir: string; npmClient?: string }) { export async function install(args: { workDir: string; moduleDir: string; npmClient?: string }) {
if (await isNPMInstalled(args)) return; if (await isNPMInstalled(args)) return;
const { workDir, npmClient = 'tnpm' } = args; const { workDir, npmClient = 'tnpm' } = args;
@ -27,6 +35,7 @@ export async function installModule(
args: { workDir: string; moduleDir: string; npmClient?: string }, args: { workDir: string; moduleDir: string; npmClient?: string },
name: string, name: string,
) { ) {
if (await isNPMModuleInstalled(args, name)) return;
const { workDir, npmClient = 'tnpm' } = args; const { workDir, npmClient = 'tnpm' } = args;
try { try {
await spawn(npmClient, ['i', name], { stdio: 'inherit', cwd: workDir } as any); await spawn(npmClient, ['i', name], { stdio: 'inherit', cwd: workDir } as any);