@smi-digital/create-smi-app 1.0.2 → 1.0.4
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 +19 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -41,17 +41,14 @@ var TOOL_CHOICES = [
|
|
|
41
41
|
];
|
|
42
42
|
var SINGLE_PROJECT_FRAMEWORK_CHOICES = [
|
|
43
43
|
{ value: "astro", name: "Astro" },
|
|
44
|
-
{ value: "react", name: "React" },
|
|
45
44
|
{ value: "none", name: "None" }
|
|
46
45
|
];
|
|
47
46
|
var FRONTEND_FRAMEWORK_CHOICES = [
|
|
48
47
|
{ value: "astro", name: "Astro" },
|
|
49
|
-
{ value: "react", name: "React" },
|
|
50
48
|
{ value: "none", name: "None" }
|
|
51
49
|
];
|
|
52
50
|
var BACKEND_FRAMEWORK_CHOICES = [
|
|
53
51
|
{ value: "strapi", name: "Strapi" },
|
|
54
|
-
{ value: "express", name: "Express" },
|
|
55
52
|
{ value: "none", name: "None" }
|
|
56
53
|
];
|
|
57
54
|
var FRAMEWORK_GENERATORS = {
|
|
@@ -318,7 +315,7 @@ import { access as access2, mkdir as mkdir2 } from "fs/promises";
|
|
|
318
315
|
import { join as join5 } from "path";
|
|
319
316
|
|
|
320
317
|
// src/modules/scaffoldActions/createTools.ts
|
|
321
|
-
import { cp, readdir as readdir2 } from "fs/promises";
|
|
318
|
+
import { cp, readFile as readFile2, readdir as readdir2, writeFile } from "fs/promises";
|
|
322
319
|
import { join as join3 } from "path";
|
|
323
320
|
var templateRenameMap = {
|
|
324
321
|
"env.template": ".env",
|
|
@@ -336,7 +333,19 @@ function getTargetFileName(sourceName) {
|
|
|
336
333
|
}
|
|
337
334
|
return sourceName;
|
|
338
335
|
}
|
|
339
|
-
|
|
336
|
+
function toPackageName(projectName) {
|
|
337
|
+
const normalized = projectName.trim().toLowerCase().replaceAll(/\s+/gv, "-").replaceAll(/[^a-z0-9._~-]/gv, "").replaceAll(/-+/gv, "-").replaceAll(/^[._\-]+|[._\-]+$/gv, "");
|
|
338
|
+
return normalized || "app";
|
|
339
|
+
}
|
|
340
|
+
async function updatePackageJsonName(targetDir, projectName) {
|
|
341
|
+
const packageJsonPath = join3(targetDir, "package.json");
|
|
342
|
+
const packageJsonRaw = await readFile2(packageJsonPath, "utf8");
|
|
343
|
+
const packageJson = JSON.parse(packageJsonRaw);
|
|
344
|
+
packageJson.name = toPackageName(projectName);
|
|
345
|
+
await writeFile(packageJsonPath, `${JSON.stringify(packageJson, null, 2)}
|
|
346
|
+
`);
|
|
347
|
+
}
|
|
348
|
+
async function createTools(tools, targetDir, templatesDir, projectName) {
|
|
340
349
|
if (!tools.includes("basic")) {
|
|
341
350
|
return;
|
|
342
351
|
}
|
|
@@ -357,6 +366,7 @@ async function createTools(tools, targetDir, templatesDir) {
|
|
|
357
366
|
await cp(huskyDir, join3(targetDir, ".husky"), {
|
|
358
367
|
recursive: true
|
|
359
368
|
});
|
|
369
|
+
await updatePackageJsonName(targetDir, projectName);
|
|
360
370
|
}
|
|
361
371
|
|
|
362
372
|
// src/modules/scaffoldActions/progress.ts
|
|
@@ -475,7 +485,7 @@ async function createApps(projectRoot, targets) {
|
|
|
475
485
|
}
|
|
476
486
|
|
|
477
487
|
// src/modules/scaffoldActions/createIntegrations.ts
|
|
478
|
-
import { mkdir, readFile as
|
|
488
|
+
import { mkdir, readFile as readFile3, writeFile as writeFile2 } from "fs/promises";
|
|
479
489
|
import { dirname as dirname2, join as join4 } from "path";
|
|
480
490
|
function toTemplateToken(key) {
|
|
481
491
|
const normalized = key.replaceAll(/[^a-zA-Z0-9]+/gv, "_").replaceAll(/^_+|_+$/gv, "").toUpperCase();
|
|
@@ -489,10 +499,10 @@ function applyTemplateVariables(content, values) {
|
|
|
489
499
|
return result;
|
|
490
500
|
}
|
|
491
501
|
async function copyTemplateFile(sourcePath, targetPath, values) {
|
|
492
|
-
const rawContent = await
|
|
502
|
+
const rawContent = await readFile3(sourcePath, "utf8");
|
|
493
503
|
const content = applyTemplateVariables(rawContent, values);
|
|
494
504
|
await mkdir(dirname2(targetPath), { recursive: true });
|
|
495
|
-
await
|
|
505
|
+
await writeFile2(targetPath, content, "utf8");
|
|
496
506
|
}
|
|
497
507
|
async function createIntegrations(options, projectRoot, templatesDir) {
|
|
498
508
|
const { projectType } = options;
|
|
@@ -615,7 +625,7 @@ async function createScaffold(options, targetDir, templatesDir) {
|
|
|
615
625
|
);
|
|
616
626
|
await runStep(
|
|
617
627
|
"Copying base tools",
|
|
618
|
-
async () => createTools(options.tools, projectRoot, templatesDir)
|
|
628
|
+
async () => createTools(options.tools, projectRoot, templatesDir, projectName)
|
|
619
629
|
);
|
|
620
630
|
}
|
|
621
631
|
await createApps(projectRoot, getAppTargets(options));
|