Skip to content

Commit 198d6e9

Browse files
chore(cli): add smoke tests (#489)
1 parent d6cf5c9 commit 198d6e9

File tree

9 files changed

+2831
-51
lines changed

9 files changed

+2831
-51
lines changed

apps/cli/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
2-
/dist
2+
/dist
3+
.smoke

apps/cli/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"dev": "tsdown --watch",
5050
"check-types": "tsc --noEmit",
5151
"check": "biome check --write .",
52-
"test": "vitest run",
52+
"test": "bun run build && vitest run",
53+
"test:with-build": "bun run build && WITH_BUILD=1 vitest run",
5354
"prepublishOnly": "npm run build"
5455
},
5556
"dependencies": {
@@ -70,6 +71,7 @@
7071
"@types/fs-extra": "^11.0.4",
7172
"@types/node": "^24.2.0",
7273
"tsdown": "^0.13.3",
73-
"typescript": "^5.9.2"
74+
"typescript": "^5.9.2",
75+
"vitest": "^3.2.4"
7476
}
7577
}

apps/cli/src/helpers/project-generation/post-installation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ async function getDatabaseInstructions(
236236
);
237237
instructions.push(
238238
`${pc.cyan("4.")} Generate migrations: ${pc.white(
239-
"cd apps/server && bun db:generate",
239+
`cd apps/server && ${packageManager} db:generate`,
240240
)}`,
241241
);
242242
instructions.push(

apps/cli/src/helpers/project-generation/template-manager.ts

Lines changed: 33 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ async function processAndCopyFiles(
1111
destDir: string,
1212
context: ProjectConfig,
1313
overwrite = true,
14+
ignorePatterns?: string[],
1415
) {
1516
const sourceFiles = await globby(sourcePattern, {
1617
cwd: baseSourceDir,
1718
dot: true,
1819
onlyFiles: true,
1920
absolute: false,
21+
ignore: ignorePatterns,
2022
});
2123

2224
for (const relativeSrcPath of sourceFiles) {
@@ -26,28 +28,30 @@ async function processAndCopyFiles(
2628
if (relativeSrcPath.endsWith(".hbs")) {
2729
relativeDestPath = relativeSrcPath.slice(0, -4);
2830
}
29-
const basename = path.basename(relativeSrcPath);
31+
32+
const basename = path.basename(relativeDestPath);
3033
if (basename === "_gitignore") {
31-
relativeDestPath = path.join(path.dirname(relativeSrcPath), ".gitignore");
34+
relativeDestPath = path.join(
35+
path.dirname(relativeDestPath),
36+
".gitignore",
37+
);
3238
} else if (basename === "_npmrc") {
33-
relativeDestPath = path.join(path.dirname(relativeSrcPath), ".npmrc");
39+
relativeDestPath = path.join(path.dirname(relativeDestPath), ".npmrc");
3440
}
3541

3642
const destPath = path.join(destDir, relativeDestPath);
3743

38-
try {
39-
await fs.ensureDir(path.dirname(destPath));
44+
await fs.ensureDir(path.dirname(destPath));
4045

41-
if (!overwrite && (await fs.pathExists(destPath))) {
42-
continue;
43-
}
46+
if (!overwrite && (await fs.pathExists(destPath))) {
47+
continue;
48+
}
4449

45-
if (srcPath.endsWith(".hbs")) {
46-
await processTemplate(srcPath, destPath, context);
47-
} else {
48-
await fs.copy(srcPath, destPath, { overwrite: true });
49-
}
50-
} catch (_error) {}
50+
if (srcPath.endsWith(".hbs")) {
51+
await processTemplate(srcPath, destPath, context);
52+
} else {
53+
await fs.copy(srcPath, destPath, { overwrite: true });
54+
}
5155
}
5256
}
5357

@@ -655,26 +659,14 @@ export async function setupExamplesTemplate(
655659
ignorePatterns.push("next/**");
656660
}
657661

658-
const generalServerFiles = await globby(["**/*.ts", "**/*.hbs"], {
659-
cwd: exampleServerSrc,
660-
onlyFiles: true,
661-
deep: 1,
662-
ignore: ignorePatterns,
663-
});
664-
665-
for (const file of generalServerFiles) {
666-
const srcPath = path.join(exampleServerSrc, file);
667-
const destPath = path.join(serverAppDir, file.replace(".hbs", ""));
668-
try {
669-
if (srcPath.endsWith(".hbs")) {
670-
await processTemplate(srcPath, destPath, context);
671-
} else {
672-
if (!(await fs.pathExists(destPath))) {
673-
await fs.copy(srcPath, destPath, { overwrite: false });
674-
}
675-
}
676-
} catch (_error) {}
677-
}
662+
await processAndCopyFiles(
663+
["**/*.ts", "**/*.hbs"],
664+
exampleServerSrc,
665+
serverAppDir,
666+
context,
667+
false,
668+
ignorePatterns,
669+
);
678670
}
679671

680672
if (webAppDirExists) {
@@ -791,9 +783,13 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
791783

792784
if (context.packageManager === "bun") {
793785
const bunfigSrc = path.join(extrasDir, "bunfig.toml.hbs");
794-
const bunfigDest = path.join(projectDir, "bunfig.toml");
795786
if (await fs.pathExists(bunfigSrc)) {
796-
await processTemplate(bunfigSrc, bunfigDest, context);
787+
await processAndCopyFiles(
788+
"bunfig.toml.hbs",
789+
extrasDir,
790+
projectDir,
791+
context,
792+
);
797793
}
798794
}
799795

@@ -802,9 +798,8 @@ export async function handleExtras(projectDir: string, context: ProjectConfig) {
802798
(hasNative || context.frontend.includes("nuxt"))
803799
) {
804800
const npmrcTemplateSrc = path.join(extrasDir, "_npmrc.hbs");
805-
const npmrcDest = path.join(projectDir, ".npmrc");
806801
if (await fs.pathExists(npmrcTemplateSrc)) {
807-
await processTemplate(npmrcTemplateSrc, npmrcDest, context);
802+
await processAndCopyFiles("_npmrc.hbs", extrasDir, projectDir, context);
808803
}
809804
}
810805

apps/cli/src/utils/errors.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { cancel } from "@clack/prompts";
2-
import { consola } from "consola";
2+
import consola from "consola";
33
import pc from "picocolors";
44

55
export function exitWithError(message: string): never {

0 commit comments

Comments
 (0)