Skip to content

Commit

Permalink
feat: add -p --project-name option so users can specify a name for th…
Browse files Browse the repository at this point in the history
…e askui project
  • Loading branch information
JohannesDienst-askui committed Mar 14, 2024
1 parent 5035f42 commit 556c977
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export interface CliOptions {
skipCredentials: boolean,
operatingSystem: 'windows' | 'linux' | 'macos',
workspaceId: string,
accessToken: string,
operatingSystem: 'windows' | 'linux' | 'macos',
projectName: string,
skipCredentials: boolean,
testFramework: 'jest',
typescriptConfig: boolean,
workspaceId: string,
}
6 changes: 6 additions & 0 deletions packages/askui-nodejs/src/lib/interactive_cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ const options = [
choices: [],
description: 'an access token for the workspace with the id.',
},
{
option: '-p, --project-name <value>',
choices: [],
description: 'an access token for the workspace with the id.',
default: 'askui_example',
},
{
option: '-t, --typescript-config',
choices: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CliOptions } from './cli-options-interface';
import { addScript, removeScript } from './add-remove-script-package-json';

export class CreateExampleProject {
private distexampleFolderPath: string;
private targetExampleFolderPath: string;

private exampleFolderName: string;

Expand All @@ -22,20 +22,29 @@ export class CreateExampleProject {

constructor(readonly cliOptions: CliOptions) {
this.baseDirPath = process.cwd();
this.exampleFolderName = 'askui_example';
this.distexampleFolderPath = path.join(

this.exampleFolderName = this.getExampleFolderName();
this.targetExampleFolderPath = path.join(
this.baseDirPath,
this.exampleFolderName,
);

this.askUIControllerUrl = 'https://docs.askui.com/docs/general/Components/AskUI-Controller';
this.helperTemplateConfig = {};
}

private getExampleFolderName(): string {
if (this.cliOptions.projectName) {
return this.cliOptions.projectName.trim();
}
return 'askui_example';
}

private async copyTemplateProject(): Promise<Listr.ListrTask<unknown>[]> {
const exampleProjectPath = path.join(
'example_projects_templates',
'typescript',
this.exampleFolderName,
'askui_example',
);

const runCommand = promisify(exec);
Expand Down Expand Up @@ -63,7 +72,7 @@ export class CreateExampleProject {
title: 'Copy project files',
task: async () => fs.copy(
path.join(getPathToNodeModulesRoot(), exampleProjectPath),
this.distexampleFolderPath,
this.exampleFolderName,
),
},
{
Expand All @@ -88,7 +97,7 @@ export class CreateExampleProject {
frameworkConfigs.jest,
);
await fs.copyFile(configFilePath, path.join(
this.distexampleFolderPath,
this.targetExampleFolderPath,
frameworkConfigs.jest,
));
}
Expand Down Expand Up @@ -146,9 +155,9 @@ export class CreateExampleProject {

nunjucks.configure(askuiHelperTemplateFilePath, { autoescape: false });
const result = nunjucks.render(templateFileName, this.helperTemplateConfig);
const filePath = path.join(this.distexampleFolderPath, 'helpers', 'askui-helper.ts');
if (!fs.existsSync(path.join(this.distexampleFolderPath, 'helpers'))) {
await fs.mkdir(path.join(this.distexampleFolderPath, 'helpers'));
const filePath = path.join(this.targetExampleFolderPath, 'helpers', 'askui-helper.ts');
if (!fs.existsSync(path.join(this.targetExampleFolderPath, 'helpers'))) {
await fs.mkdir(path.join(this.targetExampleFolderPath, 'helpers'));
}
await fs.writeFile(filePath, result, 'utf8');
},
Expand Down Expand Up @@ -274,7 +283,7 @@ export class CreateExampleProject {
console.log(chalk.greenBright('\nCongratulations!'));
console.log(
`askui example was created under ${chalk.gray(
this.distexampleFolderPath,
this.targetExampleFolderPath,
)}`,
);

Expand Down

0 comments on commit 556c977

Please sign in to comment.