@@ -71,20 +71,54 @@ const initFunction = async () => {
71
71
parseOutput: false
72
72
})
73
73
74
- let command = `
75
- mkdir -m 777 -p 'functions/${answers.name}' && \
76
- cd 'functions/${answers.name}' && \
74
+ let initFirstCommand = `
75
+ cd '${answers.name}' && \
77
76
git init && \
78
77
git remote add -f origin https://github.com/{{ sdk .gitUserName }}/functions-starter && \
79
- git config core.sparseCheckout true && \
80
- echo '${answers.runtime.id}' >> .git/info/sparse-checkout && \
81
- git pull origin main && \
82
- rm -rf .git && \
83
- mv ${answers.runtime.id}/* . && \
84
- rm -rf ${answers.runtime.id}`;
78
+ git config core.sparseCheckout true`;
79
+
80
+ let initSecondCommand = `
81
+ cd '${answers.name}' && \
82
+ git pull origin dev && \
83
+ git checkout dev`;
84
+
85
+ // Convert commands from unix based ones to windows based ones
86
+ if (process.platform == 'win32') {
87
+ initFirstCommand = initFirstCommand.replace(/'/g, '"').replace(/\\/g, '').replace(/\n/g, '').replace(/ +/g, ' ');
88
+ initFirstCommand = 'cmd /c "' + initFirstCommand + '"';
89
+ initSecondCommand = initSecondCommand.replace(/'/g, '"').replace(/\\/g, '').replace(/\n/g, '').replace(/ +/g, ' ');
90
+ initSecondCommand = 'cmd /c "' + initSecondCommand + '"';
91
+ }
92
+
93
+ fs.mkdirSync(answers.name, { recursive: true });
94
+ fs.chmodSync(answers.name, 0o777);
85
95
86
96
// Execute the child process but do not print any std output
87
- childProcess.execSync(command, { stdio: 'pipe' });
97
+ childProcess.execSync(initFirstCommand, { stdio: 'pipe' });
98
+
99
+ fs.writeFileSync(`${answers.name}/.git/info/sparse-checkout`, answers.runtime.id);
100
+
101
+ childProcess.execSync(initSecondCommand, { stdio: 'pipe' });
102
+
103
+ fs.rmSync(`${answers.name}/.git`, { recursive: true, force: true });
104
+
105
+ // Copy files
106
+ function copyFolderSync(from, to) {
107
+ if (!fs.existsSync(to)) {
108
+ fs.mkdirSync(to, { recursive: true });
109
+ }
110
+
111
+ fs.readdirSync(from).forEach(element => {
112
+ if (fs.lstatSync(path.join(from, element)).isFile()) {
113
+ fs.copyFileSync(path.join(from, element), path.join(to, element));
114
+ } else {
115
+ copyFolderSync(path.join(from, element), path.join(to, element));
116
+ }
117
+ });
118
+ }
119
+
120
+ copyFolderSync(`./${answers.name}/${answers.runtime.id}`, `./${answers.name}/`);
121
+ fs.rmSync(`./${answers.name}/${answers.runtime.id}`, { recursive: true, force: true });
88
122
89
123
const readmePath = path.join(process.cwd(), 'functions', answers.name, 'README.md');
90
124
const readmeFile = fs.readFileSync(readmePath).toString();
0 commit comments