-
Notifications
You must be signed in to change notification settings - Fork 6.8k
/
Copy pathutils.mts
59 lines (49 loc) · 1.99 KB
/
utils.mts
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import * as fs from 'fs';
import * as path from 'path';
import {fileURLToPath} from 'url';
import {$, cd} from 'zx';
/** Absolute path to the `angular/components` project root. */
export const projectDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '../..');
/** Interface describing a site target for the docs-app. */
export class SiteTarget {
constructor(
public firebaseSiteId: string,
public remoteUrl: string,
) {}
}
/** Object capturing all site targets for the docs-app. */
export const sites = {
stable: new SiteTarget('latest-material-angular-io', 'https://material.angular.io'),
next: new SiteTarget('next-material-angular-io', 'https://next.material.angular.io'),
rc: new SiteTarget('rc-material-angular-io', 'https://rc.material.angular.io'),
forMajor: (major: number) =>
new SiteTarget(`v${major}-material-angular-io`, `https://v${major}.material.angular.io`),
};
/** Optional Github access token. Can be used for querying the active release trains. */
export const githubAccessToken: string | undefined = process.env['DOCS_DEPLOY_GITHUB_TOKEN'];
/** Configuration describing the Firebase project that we deploy to. */
export const firebaseConfig = {
projectId: 'material-angular-io',
serviceKey: process.env['DOCS_SITE_GCP_SERVICE_KEY']!,
};
/** Finds and parsed the `package.json` of the specified project directory. */
export async function getPackageJsonOfProject(
projectPath: string,
): Promise<{path: string; parsed: any}> {
const packageJsonPath = path.join(projectPath, 'package.json');
const packageJsonContent = await fs.promises.readFile(packageJsonPath, 'utf8');
return {
path: packageJsonPath,
parsed: JSON.parse(packageJsonContent),
};
}
/**
* Builds the docs site in production.
*/
export async function buildDocsSite() {
cd(projectDir);
await $`pnpm bazel build --config=snapshot-build //docs:build.production`;
await $`rm -Rf docs/dist`;
await $`cp -R dist/bin/docs/dist/browser docs/dist`;
await $`chmod u+w -R docs/dist`;
}