@@ -10,6 +10,7 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
1010const { storageListBuckets } = require("./storage");
1111const { sdkForConsole } = require("../sdks");
1212const { localConfig } = require("../config");
13+ const ID = require("../id");
1314const { paginate } = require("../paginate");
1415const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
1516const { success, log, actionRunner, commandDescriptions } = require("../parser");
@@ -63,10 +64,11 @@ const initFunction = async () => {
6364 });
6465 }
6566
66- const functionDir = path.join(functionFolder, answers.name);
67+ const functionId = answers.id === 'unique()' ? ID.unique() : answers.id;
68+ const functionDir = path.join(functionFolder, functionId);
6769
6870 if (fs.existsSync(functionDir)) {
69- throw new Error(`( ${answers.name } ) already exists in the current directory. Please choose another name.`);
71+ throw new Error(`( ${functionId } ) already exists in the current directory. Please choose another name.`);
7072 }
7173
7274 if (!answers.runtime.entrypoint) {
@@ -78,7 +80,7 @@ const initFunction = async () => {
7880 }
7981
8082 let response = await functionsCreate({
81- functionId: answers.id ,
83+ functionId,
8284 name: answers.name,
8385 runtime: answers.runtime.id,
8486 entrypoint: answers.runtime.entrypoint || '',
@@ -134,7 +136,7 @@ const initFunction = async () => {
134136
135137 fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
136138
137- const readmePath = path.join(process.cwd(), 'functions', answers.name , 'README.md');
139+ const readmePath = path.join(process.cwd(), 'functions', functionId , 'README.md');
138140 const readmeFile = fs.readFileSync(readmePath).toString();
139141 const newReadmeFile = readmeFile.split('\n');
140142 newReadmeFile[0] = `# ${answers.name}`;
@@ -154,7 +156,7 @@ const initFunction = async () => {
154156 entrypoint: response.entrypoint,
155157 commands: response.commands,
156158 ignore: answers.runtime.ignore || null,
157- path: `functions/${answers.name }`,
159+ path: `functions/${functionId }`,
158160 };
159161
160162 localConfig.addFunction(data);
0 commit comments