@insforge/cli 0.1.21 → 0.1.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +71 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1968,7 +1968,7 @@ async function copyDir(src, dest) {
|
|
|
1968
1968
|
}
|
|
1969
1969
|
}
|
|
1970
1970
|
function registerCreateCommand(program2) {
|
|
1971
|
-
program2.command("create").description("Create a new InsForge project").option("--name <name>", "Project name").option("--org-id <id>", "Organization ID").option("--region <region>", "Deployment region (us-east, us-west, eu-central, ap-southeast)").option("--template <template>", "Template to use: react, nextjs, or empty").action(async (opts, cmd) => {
|
|
1971
|
+
program2.command("create").description("Create a new InsForge project").option("--name <name>", "Project name").option("--org-id <id>", "Organization ID").option("--region <region>", "Deployment region (us-east, us-west, eu-central, ap-southeast)").option("--template <template>", "Template to use: react, nextjs, chatbot, or empty").action(async (opts, cmd) => {
|
|
1972
1972
|
const { json, apiUrl } = getRootOpts(cmd);
|
|
1973
1973
|
try {
|
|
1974
1974
|
await requireAuth(apiUrl);
|
|
@@ -2017,6 +2017,7 @@ function registerCreateCommand(program2) {
|
|
|
2017
2017
|
options: [
|
|
2018
2018
|
{ value: "react", label: "Web app template with React" },
|
|
2019
2019
|
{ value: "nextjs", label: "Web app template with Next.js" },
|
|
2020
|
+
{ value: "chatbot", label: "AI Chatbot with Next.js" },
|
|
2020
2021
|
{ value: "empty", label: "Empty project" }
|
|
2021
2022
|
]
|
|
2022
2023
|
});
|
|
@@ -2042,7 +2043,9 @@ function registerCreateCommand(program2) {
|
|
|
2042
2043
|
saveProjectConfig(projectConfig);
|
|
2043
2044
|
s?.stop(`Project "${project.name}" created and linked`);
|
|
2044
2045
|
const hasTemplate = template !== "empty";
|
|
2045
|
-
if (
|
|
2046
|
+
if (template === "chatbot") {
|
|
2047
|
+
await downloadGitHubTemplate("chatbot", projectConfig, json);
|
|
2048
|
+
} else if (hasTemplate) {
|
|
2046
2049
|
await downloadTemplate(template, projectConfig, projectName, json, apiUrl);
|
|
2047
2050
|
}
|
|
2048
2051
|
await installCliGlobally(json);
|
|
@@ -2148,6 +2151,72 @@ async function downloadTemplate(framework, projectConfig, projectName, json, _ap
|
|
|
2148
2151
|
}
|
|
2149
2152
|
}
|
|
2150
2153
|
}
|
|
2154
|
+
async function downloadGitHubTemplate(templateName, projectConfig, json) {
|
|
2155
|
+
const s = !json ? clack10.spinner() : null;
|
|
2156
|
+
s?.start(`Downloading ${templateName} template...`);
|
|
2157
|
+
const tempDir = path2.join(tmpdir(), `insforge-template-${Date.now()}`);
|
|
2158
|
+
try {
|
|
2159
|
+
await fs2.mkdir(tempDir, { recursive: true });
|
|
2160
|
+
await execAsync2(
|
|
2161
|
+
"git clone --depth 1 https://github.com/InsForge/insforge-templates.git .",
|
|
2162
|
+
{ cwd: tempDir, maxBuffer: 10 * 1024 * 1024, timeout: 6e4 }
|
|
2163
|
+
);
|
|
2164
|
+
const templateDir = path2.join(tempDir, templateName);
|
|
2165
|
+
const stat3 = await fs2.stat(templateDir).catch(() => null);
|
|
2166
|
+
if (!stat3?.isDirectory()) {
|
|
2167
|
+
throw new Error(`Template "${templateName}" not found in repository`);
|
|
2168
|
+
}
|
|
2169
|
+
s?.message("Copying template files...");
|
|
2170
|
+
const cwd = process.cwd();
|
|
2171
|
+
await copyDir(templateDir, cwd);
|
|
2172
|
+
const envExamplePath = path2.join(cwd, ".env.example");
|
|
2173
|
+
const envExampleExists = await fs2.stat(envExamplePath).catch(() => null);
|
|
2174
|
+
if (envExampleExists) {
|
|
2175
|
+
const anonKey = await getAnonKey();
|
|
2176
|
+
const envExample = await fs2.readFile(envExamplePath, "utf-8");
|
|
2177
|
+
const envContent = envExample.replace(
|
|
2178
|
+
/^([A-Z_]+=)(.*)$/gm,
|
|
2179
|
+
(_, prefix, _value) => {
|
|
2180
|
+
const key = prefix.slice(0, -1);
|
|
2181
|
+
if (/INSFORGE.*(URL|BASE_URL)$/.test(key)) return `${prefix}${projectConfig.oss_host}`;
|
|
2182
|
+
if (/INSFORGE.*ANON_KEY$/.test(key)) return `${prefix}${anonKey}`;
|
|
2183
|
+
return `${prefix}${_value}`;
|
|
2184
|
+
}
|
|
2185
|
+
);
|
|
2186
|
+
await fs2.writeFile(path2.join(cwd, ".env.local"), envContent);
|
|
2187
|
+
}
|
|
2188
|
+
s?.stop(`${templateName} template downloaded`);
|
|
2189
|
+
const migrationPath = path2.join(cwd, "migrations", "db_int.sql");
|
|
2190
|
+
const migrationExists = await fs2.stat(migrationPath).catch(() => null);
|
|
2191
|
+
if (migrationExists) {
|
|
2192
|
+
const dbSpinner = !json ? clack10.spinner() : null;
|
|
2193
|
+
dbSpinner?.start("Running database migrations...");
|
|
2194
|
+
try {
|
|
2195
|
+
const sql = await fs2.readFile(migrationPath, "utf-8");
|
|
2196
|
+
await ossFetch("/api/database/advance/rawsql/unrestricted", {
|
|
2197
|
+
method: "POST",
|
|
2198
|
+
body: JSON.stringify({ query: sql })
|
|
2199
|
+
});
|
|
2200
|
+
dbSpinner?.stop("Database migrations applied");
|
|
2201
|
+
} catch (err) {
|
|
2202
|
+
dbSpinner?.stop("Database migration failed");
|
|
2203
|
+
if (!json) {
|
|
2204
|
+
clack10.log.warn(`Migration failed: ${err.message}`);
|
|
2205
|
+
clack10.log.info('You can run the migration manually: insforge db query --unrestricted "$(cat migrations/db_int.sql)"');
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
} catch (err) {
|
|
2210
|
+
s?.stop(`${templateName} template download failed`);
|
|
2211
|
+
if (!json) {
|
|
2212
|
+
clack10.log.warn(`Failed to download ${templateName} template: ${err.message}`);
|
|
2213
|
+
clack10.log.info("You can manually clone from: https://github.com/InsForge/insforge-templates");
|
|
2214
|
+
}
|
|
2215
|
+
} finally {
|
|
2216
|
+
await fs2.rm(tempDir, { recursive: true, force: true }).catch(() => {
|
|
2217
|
+
});
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2151
2220
|
|
|
2152
2221
|
// src/commands/info.ts
|
|
2153
2222
|
function registerContextCommand(program2) {
|