@@ -50,14 +50,15 @@ const initProject = async () => {
50
50
const initFunction = async () => {
51
51
// TODO: Add CI/CD support (ID, name, runtime)
52
52
let answers = await inquirer.prompt(questionsInitFunction)
53
+ let functionFolder = path.join(process.cwd(), 'functions');
53
54
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 , {
56
57
recursive: true
57
58
});
58
59
}
59
60
60
- const functionDir = path.join(process.cwd(), 'functions' , answers.name);
61
+ const functionDir = path.join(functionFolder , answers.name);
61
62
62
63
if (fs.existsSync(functionDir)) {
63
64
throw new Error(`( ${answers.name} ) already exists in the current directory. Please choose another name.`);
@@ -80,19 +81,19 @@ const initFunction = async () => {
80
81
81
82
let gitPullCommands = `git sparse-checkout add ${answers.runtime.id}`;
82
83
83
- // Force use CMD as powershell does not support &&
84
+ /* Force use CMD as powershell does not support && */
84
85
if (process.platform == 'win32') {
85
86
gitInitCommands = 'cmd /c "' + gitInitCommands + '"';
86
87
gitPullCommands = 'cmd /c "' + gitPullCommands + '"';
87
88
}
88
89
89
- // Execute the child process but do not print any std output
90
+ /* Execute the child process but do not print any std output */
90
91
try {
91
92
childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
92
93
93
94
childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
94
95
} catch (error) {
95
- // Specialised errors with recommended actions to take
96
+ /* Specialised errors with recommended actions to take */
96
97
if (error.message.includes('error: unknown option')) {
97
98
throw new Error(`${error.message} \n\nSuggestion: Try updating your git to the latest version, then trying to run this command again.`)
98
99
} else if (error.message.includes('is not recognized as an internal or external command,') || error.message.includes('command not found')) {
0 commit comments