forked from firebase/firebase-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.ts
41 lines (37 loc) · 1.36 KB
/
utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { readJSON as originalReadJSON } from "fs-extra";
import type { ReadOptions } from "fs-extra";
import { join } from "path";
import { readFile } from "fs/promises";
/**
* Whether the given string starts with http:// or https://
*/
export function isUrl(url: string): boolean {
return /^https?:\/\//.test(url);
}
/**
* add type to readJSON
*/
export function readJSON<JsonType = any>(
file: string,
options?: ReadOptions | BufferEncoding | string
): Promise<JsonType> {
return originalReadJSON(file, options) as Promise<JsonType>;
}
/**
* Prints a warning if the build script in package.json
* contains anything other than allowedBuildScripts.
*/
export async function warnIfCustomBuildScript(
dir: string,
framework: string,
defaultBuildScripts: string[]
): Promise<void> {
const packageJsonBuffer = await readFile(join(dir, "package.json"));
const packageJson = JSON.parse(packageJsonBuffer.toString());
const buildScript = packageJson.scripts?.build;
if (buildScript && !defaultBuildScripts.includes(buildScript)) {
console.warn(
`\nWARNING: Your package.json contains a custom build that is being ignored. Only the ${framework} default build script (e.g, "${defaultBuildScripts[0]}") is respected. If you have a more advanced build process you should build a custom integration https://firebase.google.com/docs/hosting/express\n`
);
}
}