Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Add --out param to "new" command and fix git initialization #72

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 current directory is a git directory\n ${response}`
psamusev marked this conversation as resolved.
Show resolved Hide resolved
);

// 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
Loading