GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lowcode-engine/modules/code-generator/src/cli/init-solution.ts at main · Alvison/lowcode-engine

Expand file tree

/

init-solution.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
65 lines (56 loc) · 2.04 KB
/

init-solution.ts

Copy path

File metadata and controls

65 lines (56 loc) · 2.04 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* eslint-disable no-console */
import * as fs from 'fs-extra';
import * as path from 'path';
import chalk from 'chalk';
import * as changeCase from 'change-case';
import { getErrorMessage } from '../utils/errors';
import { getLowcodeSolutionTemplateFiles } from './solutions/example-solution';
export async function initSolution(args: string[], options: {
quiet?: boolean;
verbose?: boolean;
}) {
try {
const cwd = process.cwd();
let solutionName = args[0] || 'hello';
let solutionPath = path.resolve(cwd, solutionName);
if (solutionName === '.') {
solutionName = path.basename(cwd);
solutionPath = cwd;
}
const modifyFileContent = (content: string) =>
content
.replace(/hello-world/g, changeCase.paramCase(solutionName))
.replace(/HelloWorld/g, changeCase.pascalCase(solutionName))
.replace(/Hello World/g, changeCase.titleCase(solutionName));
await ensureDirExists(solutionPath);
const templateFiles = getLowcodeSolutionTemplateFiles();
for (const templateFile of templateFiles) {
if (options.verbose) {
console.log('%s', chalk.gray(`creating file ${templateFile.file}`));
}
const templateFilePath = path.join(solutionPath, templateFile.file);
await ensureDirExists(path.dirname(templateFilePath));
await fs.writeFile(templateFilePath, modifyFileContent(templateFile.content), { encoding: 'utf-8' });
}
if (!options.quiet) {
console.log('%s', chalk.green(`solution ${solutionName} created successfully`));
}
return 0;
} catch (e) {
console.log(chalk.red(getErrorMessage(e) || `Unexpected error: ${e}`));
if (typeof e === 'object' && (e as { stack: string } | null)?.stack && options.verbose) {
console.log(chalk.gray((e as { stack: string }).stack));
}
return 1;
}
}
async function ensureDirExists(dirPath: string) {
try {
await fs.mkdir(dirPath, { recursive: true });
} catch (e) {
if ((e as { code: string }).code === 'EEXIST') {
return;// ignore existing error
}
throw e;
}
}
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.