Skip to content

Commit db23207

Browse files
Update init.js.twig
1 parent 23b2401 commit db23207

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

templates/cli/lib/commands/init.js.twig

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@ const initProject = async () => {
5050
const initFunction = async () => {
5151
// TODO: Add CI/CD support (ID, name, runtime)
5252
let answers = await inquirer.prompt(questionsInitFunction)
53+
let functionFolder = path.join(process.cwd(), 'functions');
5354

54-
if (!fs.existsSync(path.join(process.cwd(), 'functions'))) {
55-
fs.mkdirSync(path.join(process.cwd(), 'functions'), {
55+
if (!fs.existsSync(functionFolder)) {
56+
fs.mkdirSync(functionFolder, {
5657
recursive: true
5758
});
5859
}
5960

60-
const functionDir = path.join(process.cwd(), 'functions', answers.name);
61+
const functionDir = path.join(functionFolder, answers.name);
6162

6263
if (fs.existsSync(functionDir)) {
6364
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
@@ -80,19 +81,19 @@ const initFunction = async () => {
8081

8182
let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
8283

83-
// Force use CMD as powershell does not support &&
84+
/* Force use CMD as powershell does not support && */
8485
if (process.platform == 'win32') {
8586
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
8687
gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
8788
}
8889

89-
// Execute the child process but do not print any std output
90+
/* Execute the child process but do not print any std output */
9091
try {
9192
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
9293

9394
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
9495
} catch (error) {
95-
// Specialised errors with recommended actions to take
96+
/* Specialised errors with recommended actions to take */
9697
if (error.message.includes('error: unknown option')) {
9798
throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
9899
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {

0 commit comments

Comments
 (0)