@@ -81,12 +81,9 @@ const initFunction = async () => {
81
81
82
82
fs.mkdirSync(functionDir, "777");
83
83
84
- const gitInitCommands =
85
- `git init && ` +
86
- `git remote add -f origin https://github.com/{{ sdk .gitUserName }}/functions-starter && ` +
87
- `git config core.sparseCheckout true`;
84
+ const gitInitCommands = "git clone --depth 1 --sparse https://github.com/{{ sdk .gitUserName }}/functions-starter ."; // depth prevents fetching older commits reducing the amount fetched
88
85
89
- const gitPullCommands = `git pull origin main `;
86
+ const gitPullCommands = `git sparse-checkout add ${answers.runtime.id} `;
90
87
91
88
// Force use CMD as powershell does not support &&
92
89
if (process.platform == 'win32') {
@@ -95,11 +92,9 @@ const initFunction = async () => {
95
92
}
96
93
97
94
// Execute the child process but do not print any std output
98
- childProcess.execSync(gitInitCommands, { stdio: 'pipe' });
95
+ childProcess.execSync(gitInitCommands, { stdio: 'pipe', cwd: functionDir });
99
96
100
- fs.writeFileSync(path.join(functionDir, ".git/info/sparse-checkout"), `${answers.runtime.id}`);
101
-
102
- childProcess.execSync(gitPullCommands, { stdio: 'pipe' });
97
+ childProcess.execSync(gitPullCommands, { stdio: 'pipe', cwd: functionDir });
103
98
104
99
fs.rmSync(path.join(functionDir, ".git"), { recursive: true });
105
100
const copyRecursiveSync = (src, dest) => {
@@ -120,7 +115,7 @@ const initFunction = async () => {
120
115
};
121
116
copyRecursiveSync(path.join(functionDir, answers.runtime.id), functionDir);
122
117
123
- fs.rmSync(`./${answers.name }/${answers.runtime.id}`, { recursive: true, force: true });
118
+ fs.rmSync(`${functionDir }/${answers.runtime.id}`, { recursive: true, force: true });
124
119
125
120
const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
126
121
const readmeFile = fs.readFileSync(readmePath).toString();
0 commit comments