Skip to content

Commit 7fe9dad

Browse files
authored
Add support for angular meta framework (#276)
* skip build if .apphosting dir exists already * change builder requirements * fix lint * fix lint
1 parent a5032dc commit 7fe9dad

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

packages/@apphosting/adapter-angular/src/bin/build.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
checkBuildConditions,
55
validateOutputDirectory,
66
parseOutputBundleOptions,
7+
outputBundleExists,
78
} from "../utils.js";
89
import { getBuildOptions, runBuild } from "@apphosting/common";
910

@@ -21,8 +22,10 @@ const { stdout: output } = await runBuild();
2122
if (!output) {
2223
throw new Error("No output from Angular build command, expecting a build manifest file.");
2324
}
24-
const outputBundleOptions = parseOutputBundleOptions(output);
25-
const root = process.cwd();
26-
await generateBuildOutput(root, outputBundleOptions, process.env.FRAMEWORK_VERSION);
25+
if (!outputBundleExists()) {
26+
const outputBundleOptions = parseOutputBundleOptions(output);
27+
const root = process.cwd();
28+
await generateBuildOutput(root, outputBundleOptions, process.env.FRAMEWORK_VERSION);
2729

28-
await validateOutputDirectory(outputBundleOptions);
30+
await validateOutputDirectory(outputBundleOptions);
31+
}

packages/@apphosting/adapter-angular/src/utils.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@ const __filename = fileURLToPath(import.meta.url);
2424
const __dirname = dirname(__filename);
2525
const SIMPLE_SERVER_FILE_PATH = join(__dirname, "simple-server", "bundled_server.mjs");
2626

27-
export const REQUIRED_BUILDER = "@angular-devkit/build-angular:application";
27+
export const ALLOWED_BUILDERS = [
28+
"@angular-devkit/build-angular:application",
29+
"@analogjs/platform:vite",
30+
];
2831

2932
/**
3033
* Check if the following build conditions are satisfied for the workspace:
@@ -38,9 +41,9 @@ export async function checkBuildConditions(opts: BuildOptions): Promise<void> {
3841
const output = execSync(`npx nx show project ${opts.projectName}`);
3942
const projectJson = JSON.parse(output.toString());
4043
const builder = projectJson.targets.build.executor;
41-
if (builder !== REQUIRED_BUILDER) {
44+
if (!ALLOWED_BUILDERS.includes(builder)) {
4245
throw new Error(
43-
"Only the Angular application builder is supported. Please refer to https://angular.dev/tools/cli/build-system-migration#for-existing-applications guide to upgrade your builder to the Angular application builder. ",
46+
`Currently, only the following builders are supported: ${ALLOWED_BUILDERS.join(",")}.`,
4447
);
4548
}
4649
return;
@@ -75,9 +78,9 @@ export async function checkBuildConditions(opts: BuildOptions): Promise<void> {
7578
if (!workspaceProject.targets.has(target)) throw new Error("Could not find build target.");
7679

7780
const { builder } = workspaceProject.targets.get(target)!;
78-
if (builder !== REQUIRED_BUILDER) {
81+
if (!ALLOWED_BUILDERS.includes(builder)) {
7982
throw new Error(
80-
"Only the Angular application builder is supported. Please refer to https://angular.dev/tools/cli/build-system-migration#for-existing-applications guide to upgrade your builder to the Angular application builder. ",
83+
`Currently, only the following builders are supported: ${ALLOWED_BUILDERS.join(",")}.`,
8184
);
8285
}
8386
}
@@ -226,3 +229,11 @@ export const isMain = (meta: ImportMeta) => {
226229
if (!process.argv[1]) return false;
227230
return process.argv[1] === fileURLToPath(meta.url);
228231
};
232+
233+
export const outputBundleExists = () => {
234+
const outputBundleDir = resolve(".apphosting");
235+
if (existsSync(outputBundleDir)) {
236+
return true;
237+
}
238+
return false;
239+
};

0 commit comments

Comments
 (0)