howone 0.1.1 → 0.1.3
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/bin/index.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { cancel, confirm, intro, isCancel, outro, select, spinner, text } from "@clack/prompts";
|
|
4
4
|
import { cac } from "cac";
|
|
5
|
-
import { readdir, rename, stat } from "node:fs/promises";
|
|
5
|
+
import { readdir, rename, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { copy, emptyDir, ensureDir, pathExists } from "fs-extra/esm";
|
|
7
7
|
import pc from "picocolors";
|
|
8
8
|
import path from "node:path";
|
|
@@ -226,9 +226,36 @@ async function createTemplate(plan, json) {
|
|
|
226
226
|
}
|
|
227
227
|
});
|
|
228
228
|
await restoreGitignore(plan.targetDir);
|
|
229
|
+
await writeHowoneEnvFile(plan);
|
|
229
230
|
await assertTemplateCopied(plan);
|
|
230
231
|
task?.stop("Project created");
|
|
231
232
|
}
|
|
233
|
+
function normalizeHowoneEnv(value) {
|
|
234
|
+
const normalized = value?.trim().toLowerCase();
|
|
235
|
+
if (!normalized) return "dev";
|
|
236
|
+
if (normalized === "development") return "dev";
|
|
237
|
+
if (normalized === "production") return "prod";
|
|
238
|
+
if (normalized === "local" || normalized === "dev" || normalized === "prod") return normalized;
|
|
239
|
+
return "dev";
|
|
240
|
+
}
|
|
241
|
+
function getHowoneCreateContext() {
|
|
242
|
+
const projectId = process.env.HOWONE_PROJECT_ID?.trim();
|
|
243
|
+
if (!projectId) return null;
|
|
244
|
+
return {
|
|
245
|
+
projectId,
|
|
246
|
+
env: normalizeHowoneEnv(process.env.HOWONE_ENV ?? process.env.APP_ENV)
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
function getTemplateEnvEntries(template, context) {
|
|
250
|
+
if (template === "vite") return [["VITE_HOWONE_PROJECT_ID", context.projectId], ["VITE_HOWONE_ENV", context.env]];
|
|
251
|
+
return [["NEXT_PUBLIC_HOWONE_PROJECT_ID", context.projectId], ["NEXT_PUBLIC_HOWONE_ENV", context.env]];
|
|
252
|
+
}
|
|
253
|
+
async function writeHowoneEnvFile(plan) {
|
|
254
|
+
const context = getHowoneCreateContext();
|
|
255
|
+
if (!context) return;
|
|
256
|
+
const lines = getTemplateEnvEntries(plan.template, context).map(([key, value]) => `${key}=${value}`);
|
|
257
|
+
await writeFile(path.join(plan.targetDir, ".env"), [...lines, ""].join("\n"), "utf-8");
|
|
258
|
+
}
|
|
232
259
|
function getTemplateDir(template) {
|
|
233
260
|
const currentFile = fileURLToPath(import.meta.url);
|
|
234
261
|
const packageDir = path.resolve(path.dirname(currentFile), "..");
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createClient, defineEntities, withEntities } from '@howone/sdk'
|
|
2
2
|
|
|
3
|
-
export const HOWONE_PROJECT_ID = 'demo'
|
|
3
|
+
export const HOWONE_PROJECT_ID = process.env.NEXT_PUBLIC_HOWONE_PROJECT_ID ?? 'demo'
|
|
4
4
|
|
|
5
5
|
const client = createClient({
|
|
6
6
|
projectId: HOWONE_PROJECT_ID,
|
|
7
|
+
env: (process.env.NEXT_PUBLIC_HOWONE_ENV ?? 'prod') as 'local' | 'dev' | 'prod',
|
|
7
8
|
})
|
|
8
9
|
|
|
9
10
|
export const entities = defineEntities({
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createClient, defineEntities, withEntities } from '@howone/sdk'
|
|
2
2
|
|
|
3
|
-
export const HOWONE_PROJECT_ID =
|
|
3
|
+
export const HOWONE_PROJECT_ID = import.meta.env.VITE_HOWONE_PROJECT_ID
|
|
4
4
|
|
|
5
5
|
const client = createClient({
|
|
6
6
|
projectId: HOWONE_PROJECT_ID,
|
|
7
|
+
env: import.meta.env.VITE_HOWONE_ENV
|
|
7
8
|
})
|
|
8
9
|
|
|
9
10
|
export const entities = defineEntities({
|