Skip to content

Commit

Permalink
[Fix] Add --out param to "new" command and fix git initialization (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
psamusev authored Oct 3, 2024
1 parent 1b893e5 commit 8ed0e10
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/connector-cli/src/commands/init/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
interface InitCommandOptions {
name: string;
type: ConnectorType;
out: string;
}

export async function runInit(options: InitCommandOptions): Promise<void> {
Expand All @@ -29,7 +30,7 @@ export async function runInit(options: InitCommandOptions): Promise<void> {
);
}

let relDirectory = './';
let relDirectory = options.out;
if (commandName === 'new') {
relDirectory = path.join(relDirectory, options.name);
}
Expand Down Expand Up @@ -90,11 +91,25 @@ export async function runInit(options: InitCommandOptions): Promise<void> {
info('Creating .gitignore');
fs.writeFileSync(path.join(projectDir, './.gitignore'), gitIgnore);

// 7. init git project
info(
execSync(`git init`, {
cwd: projectDir,
encoding: 'utf-8',
})
// Checking whether currenct directory is a git directory
const response = execSync(`git rev-parse --is-inside-work-tree`, {
cwd: projectDir,
encoding: 'utf-8',
});

verbose(
`Checking whether the current directory is a git directory\n ${response}`
);

// 7. init or add files to git project
if (response.trim() === 'true') {
info('Adding generated project files to the git...');
} else {
info(
execSync(`git init`, {
cwd: projectDir,
encoding: 'utf-8',
})
);
}
}
5 changes: 5 additions & 0 deletions src/connector-cli/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function main() {
.choices(Object.values(ConnectorType))
.default('media')
)
.option(
'-o, --out [out]',
'Output path of project files. Combined with <name> to produce final directory',
'./'
)
.action(withErrorHandlerAction(runInit));

program
Expand Down

0 comments on commit 8ed0e10

Please sign in to comment.