Skip to content

Commit 6b0bbcc

Browse files
committed
refactor(cli): use function name as destination folder
1 parent c8a0982 commit 6b0bbcc

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,13 @@ const initFunction = async () => {
203203
}
204204

205205
const functionId = answers.id === 'unique()' ? ID.unique() : answers.id;
206-
const functionDir = path.join(functionFolder, functionId);
206+
const functionName = answers.name;
207+
const functionDir = path.join(functionFolder, functionName);
207208
const templatesDir = path.join(functionFolder, `${functionId}-templates`);
208209
const runtimeDir = path.join(templatesDir, answers.runtime.name);
209210

210211
if (fs.existsSync(functionDir)) {
211-
throw new Error(`( ${functionId} ) already exists in the current directory. Please choose another name.`);
212+
throw new Error(`( ${functionName} ) already exists in the current directory. Please choose another name.`);
212213
}
213214

214215
if (!answers.runtime.entrypoint) {
@@ -285,7 +286,7 @@ const initFunction = async () => {
285286

286287
fs.rmSync(templatesDir, { recursive: true, force: true });
287288

288-
const readmePath = path.join(process.cwd(), 'functions', functionId, 'README.md');
289+
const readmePath = path.join(process.cwd(), 'functions', functionName, 'README.md');
289290
const readmeFile = fs.readFileSync(readmePath).toString();
290291
const newReadmeFile = readmeFile.split('\n');
291292
newReadmeFile[0] = `# ${answers.name}`;
@@ -306,7 +307,7 @@ const initFunction = async () => {
306307
entrypoint: answers.runtime.entrypoint || '',
307308
commands: answers.runtime.commands || '',
308309
ignore: answers.runtime.ignore || null,
309-
path: `functions/${functionId}`,
310+
path: `functions/${functionName}`,
310311
};
311312

312313
localConfig.addFunction(data);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const pullFunctions = async ({ code, withVariables }) => {
8484

8585
func['path'] = localFunction['path'];
8686
if (!localFunction['path']) {
87-
func['path'] = `functions/${func.$id}`;
87+
func['path'] = `functions/${func.name}`;
8888
}
8989
if (!withVariables) {
9090
delete func['vars'];

0 commit comments

Comments
 (0)