MCPcopy Create free account
hub / github.com/alibaba/lowcode-engine / initSolution

Function initSolution

modules/code-generator/src/cli/init-solution.ts:10–54  ·  view source on GitHub ↗
(args: string[], options: {
  quiet?: boolean;
  verbose?: boolean;
})

Source from the content-addressed store, hash-verified

8
9
10export async function initSolution(args: string[], options: {
11 quiet?: boolean;
12 verbose?: boolean;
13}) {
14 try {
15 const cwd = process.cwd();
16 let solutionName = args[0] || 'hello';
17 let solutionPath = path.resolve(cwd, solutionName);
18 if (solutionName === '.') {
19 solutionName = path.basename(cwd);
20 solutionPath = cwd;
21 }
22
23 const modifyFileContent = (content: string) =>
24 content
25 .replace(/hello-world/g, changeCase.paramCase(solutionName))
26 .replace(/HelloWorld/g, changeCase.pascalCase(solutionName))
27 .replace(/Hello World/g, changeCase.titleCase(solutionName));
28
29 await ensureDirExists(solutionPath);
30
31 const templateFiles = getLowcodeSolutionTemplateFiles();
32 for (const templateFile of templateFiles) {
33 if (options.verbose) {
34 console.log('%s', chalk.gray(`creating file ${templateFile.file}`));
35 }
36
37 const templateFilePath = path.join(solutionPath, templateFile.file);
38 await ensureDirExists(path.dirname(templateFilePath));
39 await fs.writeFile(templateFilePath, modifyFileContent(templateFile.content), { encoding: 'utf-8' });
40 }
41
42 if (!options.quiet) {
43 console.log('%s', chalk.green(`solution ${solutionName} created successfully`));
44 }
45
46 return 0;
47 } catch (e) {
48 console.log(chalk.red(getErrorMessage(e) || `Unexpected error: ${e}`));
49 if (typeof e === 'object' && (e as { stack: string } | null)?.stack && options.verbose) {
50 console.log(chalk.gray((e as { stack: string }).stack));
51 }
52 return 1;
53 }
54}
55
56async function ensureDirExists(dirPath: string) {
57 try {

Callers

nothing calls this directly

Calls 6

getErrorMessageFunction · 0.90
ensureDirExistsFunction · 0.85
modifyFileContentFunction · 0.85
resolveMethod · 0.80
logMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…