lowcode-engine/modules/code-generator/tests/bugfix/icejs-package-json-dependencies.test.ts
Clarence Pan 6a642e86da
fix: 解决出码的数据源依赖包问题 (#106)
* fix: 解决 package.json 中误添加了没有用到的数据源类型的 handler 的包的问题 (#56)

* test: 更新别的相关测试用例的期望值

* fix: 🐛 去掉 npm 上没有的依赖 (#68)

* chore: 🤖 fix release:beta script

* chore(release): 1.0.2-beta.0

* fix: 🐛 补充 icejs 模板中缺失的依赖包

* chore(release): 1.0.2-beta.1

* chore(release): 1.0.2
2022-03-10 11:34:14 +08:00

50 lines
1.7 KiB
TypeScript

import CodeGenerator from '../../src';
import * as fs from 'fs';
import * as path from 'path';
const testCaseBaseName = path.basename(__filename, '.test.ts');
test(testCaseBaseName, async () => {
const inputSchemaJsonFile = path.join(__dirname, `${testCaseBaseName}.schema.json`);
const outputDir = path.join(__dirname, `${testCaseBaseName}.generated`);
await exportProject(inputSchemaJsonFile, outputDir);
const generatedPackageJsonText = fs.readFileSync(
path.join(outputDir, 'demo-project/package.json'),
'utf-8',
);
const generatedPackageJson = JSON.parse(generatedPackageJsonText);
expect(generatedPackageJson.dependencies).toBeTruthy();
// 里面有的数据源则应该生成对应的 dependencies
expect(generatedPackageJson.dependencies).toMatchObject({
'@alilc/lowcode-datasource-engine': 'latest',
'@alilc/lowcode-datasource-fetch-handler': 'latest',
});
// 里面没有的,则不应该生成对应的 dependencies
expect(generatedPackageJson.dependencies).not.toMatchObject({
'@alilc/lowcode-datasource-url-params-handler': 'latest',
'@alilc/lowcode-datasource-mtop-handler': 'latest',
'@alilc/lowcode-datasource-mopen-handler': 'latest',
});
});
function exportProject(inputPath: string, outputPath: string) {
const schemaJson = fs.readFileSync(inputPath, { encoding: 'utf8' });
const newSchema = schemaJson;
const builder = CodeGenerator.solutions.icejs();
return builder.generateProject(newSchema).then(async (result) => {
// displayResultInConsole(result);
const publisher = CodeGenerator.publishers.disk();
await publisher.publish({
project: result,
outputPath,
projectSlug: 'demo-project',
createProjectFolder: true,
});
return result;
});
}