@@ -10,6 +10,7 @@ const { databasesGet, databasesListCollections, databasesList } = require("./dat
10
10
const { storageListBuckets } = require("./storage");
11
11
const { sdkForConsole } = require("../sdks");
12
12
const { localConfig } = require("../config");
13
+ const ID = require("../id");
13
14
const { paginate } = require("../paginate");
14
15
const { questionsInitProject, questionsInitFunction, questionsInitCollection } = require("../questions");
15
16
const { success, log, actionRunner, commandDescriptions } = require("../parser");
@@ -63,10 +64,11 @@ const initFunction = async () => {
63
64
});
64
65
}
65
66
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);
67
69
68
70
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.`);
70
72
}
71
73
72
74
if (!answers.runtime.entrypoint) {
@@ -78,7 +80,7 @@ const initFunction = async () => {
78
80
}
79
81
80
82
let response = await functionsCreate({
81
- functionId: answers.id ,
83
+ functionId,
82
84
name: answers.name,
83
85
runtime: answers.runtime.id,
84
86
entrypoint: answers.runtime.entrypoint || '',
@@ -134,7 +136,7 @@ const initFunction = async () => {
134
136
135
137
fs.rmSync(`${functionDir}/${answers.runtime.id}`, { recursive: true, force: true });
136
138
137
- const readmePath = path.join(process.cwd(), 'functions', answers.name , 'README.md');
139
+ const readmePath = path.join(process.cwd(), 'functions', functionId , 'README.md');
138
140
const readmeFile = fs.readFileSync(readmePath).toString();
139
141
const newReadmeFile = readmeFile.split('\n');
140
142
newReadmeFile[0] = `# ${answers.name}`;
@@ -154,7 +156,7 @@ const initFunction = async () => {
154
156
entrypoint: response.entrypoint,
155
157
commands: response.commands,
156
158
ignore: answers.runtime.ignore || null,
157
- path: `functions/${answers.name }`,
159
+ path: `functions/${functionId }`,
158
160
};
159
161
160
162
localConfig.addFunction(data);
0 commit comments