scripts: Updated deploying + staging processes

This commit is contained in:
Prozilla 2024-07-23 16:51:43 +02:00
parent 5269660adc
commit db865012e6
No known key found for this signature in database
GPG key ID: 5858DFE71CAF31EE
12 changed files with 90 additions and 81 deletions

View file

@ -63,16 +63,16 @@ ProzillaOS uses the package manager [pnpm](https://pnpm.io/) to run scripts.
| Script | Description |
| --- | --- |
| <pre>pnpm&nbsp;run&nbsp;start</pre> | Run [`pnpm run site:start`](#package-prozilla-os-demo). VSCode is configured to run this script whenever the project is opened.
| <pre>pnpm&nbsp;run&nbsp;start</pre> | Run [`pnpm run demo:start`](#package-prozilla-os-demo). VSCode is configured to run this script whenever the project is opened.
| <pre>pnpm&nbsp;run&nbsp;build</pre> | Build every package in sequential order.
| <pre>pnpm&nbsp;run&nbsp;deploy</pre> | Clear the `dist` directory, build and stage each package that comprises the website, then deploy to GitHub pages. This should then trigger a GitHub Action that deploys the build to production.
| <pre>pnpm&nbsp;run&nbsp;publish</pre> | Publish the `dist` directory directly to GitHub pages.
| <pre>pnpm&nbsp;run&nbsp;stage</pre> | Copy and combine the build of each package that comprises the website in the `dist` directory at the root.
| <pre>pnpm&nbsp;run&nbsp;deploy</pre> | Clear the `dist` directory, stage each package that comprises the website, then deploy to GitHub pages. This should trigger a GitHub Action that deploys the build to production.
### Public packages
| Script | Description |
| --- | --- |
| <pre>pnpm&nbsp;run&nbsp;packages:build</pre> | Build all packages using Vite in sequential order and output to respective `dist` directories.
| <pre>pnpm&nbsp;run&nbsp;packages:build</pre> | Build all dependencies of the `prozilla-os` package in sequential order and output to respective `dist` directories.
| <pre>pnpm&nbsp;run&nbsp;packages:update</pre> | Create a new changeset for packages and update their version accordingly.
| <pre>pnpm&nbsp;run&nbsp;packages:release</pre> | Publish the latest versions of each package to the npm registry.
@ -87,7 +87,6 @@ ProzillaOS uses the package manager [pnpm](https://pnpm.io/) to run scripts.
| <pre>pnpm&nbsp;run&nbsp;demo:build</pre> | See [`pnpm run build`](./packages/demo/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;demo:preview</pre> | See [`pnpm run preview`](./packages/demo/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;demo:stage</pre> | See [`pnpm run stage`](./packages/demo/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;demo:deploy</pre> | See [`pnpm run deploy`](./packages/demo/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;demo:fetch</pre> | See [`pnpm run fetch`](./packages/demo/README.md#scripts)
### Internal package: `@prozilla-os/docs`
@ -97,8 +96,6 @@ ProzillaOS uses the package manager [pnpm](https://pnpm.io/) to run scripts.
| <pre>pnpm&nbsp;run&nbsp;docs:start</pre> | See [`pnpm run start`](./packages/docs/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;docs:build</pre> | See [`pnpm run build`](./packages/docs/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;docs:preview</pre> | See [`pnpm run preview`](./packages/docs/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;docs:stage</pre> | See [`pnpm run stage`](./packages/docs/README.md#scripts)
| <pre>pnpm&nbsp;run&nbsp;docs:deploy</pre> | Build and stage docs, then run `pnpm run publish`.
| <pre>pnpm&nbsp;run&nbsp;docs:generate</pre> | See [`pnpm run generate`](./packages/docs/README.md#scripts)
## Links

View file

@ -12,26 +12,22 @@
"scripts": {
"preinstall": "npx only-allow pnpm",
"start": "pnpm run demo:start",
"prebuild": "rimraf dist",
"build": "pnpm run packages:build && pnpm run docs:build && pnpm run demo:build",
"predeploy": "rimraf dist",
"deploy": "pnpm run docs:build && pnpm run docs:stage && pnpm run demo:deploy",
"publish": "pnpm vite-node packages/demo/scripts/deploy",
"build": "pnpm -r --sequential build",
"stage": "pnpm vite-node scripts/stageSite.ts",
"predeploy": "rimraf dist && pnpm run stage",
"deploy": "pnpm vite-node scripts/publishSite.ts",
"demo:start": "pnpm --filter @prozilla-os/demo run start",
"demo:build": "pnpm --filter @prozilla-os/demo run build",
"demo:preview": "pnpm --filter @prozilla-os/demo run preview",
"demo:stage": "pnpm --filter @prozilla-os/demo run stage",
"demo:deploy": "pnpm --filter @prozilla-os/demo run deploy",
"demo:fetch": "pnpm --filter @prozilla-os/demo run fetch",
"docs:start": "pnpm --filter @prozilla-os/docs run start",
"docs:build": "pnpm --filter @prozilla-os/docs run build",
"docs:stage": "pnpm --filter @prozilla-os/docs run stage",
"docs:preview": "pnpm --filter @prozilla-os/docs run preview",
"docs:deploy": "pnpm run docs:build && pnpm run docs:stage && pnpm run publish",
"docs:generate": "pnpm --filter @prozilla-os/docs run generate",
"packages:build": "pnpm -r --sequential --filter prozilla-os... build",
"packages:update": "npx changeset && pnpm changeset version",
"packages:release": "pnpm changeset publish && pnpm vite-node scripts/releasePackage.ts"
"packages:release": "pnpm changeset publish && pnpm vite-node scripts/createRelease.ts"
},
"workspaces": [
"packages/*",

View file

@ -25,7 +25,6 @@
| <pre>pnpm&nbsp;run&nbsp;build</pre> | Compile project using TypeScript and bundle all files into the `dist` directory, or the directory specified in config file. This directory can be uploaded to a web server.
| <pre>pnpm&nbsp;run&nbsp;preview</pre> | Start web server with preview of build at [localhost:8080](http://localhost:8080/). Can be useful for validating build before deploying.
| <pre>pnpm&nbsp;run&nbsp;stage</pre> | Execute [stage.ts](./scripts/stage.ts), which stages the build and prepares it for deployment. Script will generate a sitemap, robots.txt and all other necessary files.
| <pre>pnpm&nbsp;run&nbsp;deploy</pre> | Run `pnpm run build && pnpm run stage`, then execute [deploy.ts](../scripts/deploy.ts), which uploads the staged build to GitHub Pages on branch called `gh-pages`. This should then trigger a GitHub Action that deploys the build to production.
| <pre>pnpm&nbsp;run&nbsp;fetch</pre> | Fetch the repository tree using GitHub's API and store it as a JSON file that will be used to populate the virtual drive. More information can be found on the [virtual drive](./features/virtual-drive/README.md) page.
## Links

View file

@ -11,10 +11,9 @@
"scripts": {
"start": "vite",
"build": "tsc --project tsconfig.build.json && vite build",
"postbuild": "pnpm run stage",
"preview": "vite preview --port 8080",
"stage": "vite-node scripts/stage",
"predeploy": "pnpm run build && pnpm run stage",
"deploy": "vite-node scripts/deploy",
"fetch": "vite-node scripts/fetchRepository"
},
"repository": {

View file

@ -1,27 +0,0 @@
import ghpages from "gh-pages";
import { ANSI } from "../../core/src/constants";
import { BASE_URL, BUILD_DIR, COMMIT_MESSAGE, DOMAIN, REPO_URL } from "../src/config/deploy.config";
import path from "node:path";
function deploy() {
console.log(`${ANSI.fg.yellow}Deploying to GitHub Pages...${ANSI.reset}`);
console.log(`Domain: ${ANSI.fg.cyan + DOMAIN + ANSI.reset}`);
console.log(`Commit message: ${ANSI.fg.cyan + COMMIT_MESSAGE + ANSI.reset}`);
console.log(`Repository: ${ANSI.fg.cyan + REPO_URL + ANSI.reset}\n`);
void ghpages.publish(path.resolve(__dirname, "../../../", BUILD_DIR), {
repo: REPO_URL,
message: COMMIT_MESSAGE
}, (error) => {
if (error == null)
return;
console.error(error);
console.log(`${ANSI.fg.red}⚠ Failed to deploy${ANSI.reset}`);
process.exit(1);
}).then(() => {
console.log(`${ANSI.fg.green}✓ Successfully deployed to ${ANSI.fg.cyan + BASE_URL + ANSI.reset}`);
});
}
deploy();

View file

@ -4,7 +4,6 @@ import { ANSI } from "../../core/src/constants";
import { NAME, TAG_LINE } from "../src/config/branding.config";
import { BASE_URL, BUILD_DIR, DOMAIN } from "../src/config/deploy.config";
import { skin } from "../src/config/skin.config";
import path from "node:path";
import { name } from "../package.json";
const PATHS = {
@ -134,9 +133,8 @@ function stage() {
files.forEach(([path, generateContent]) => {
const directory = path.substring(0, path.lastIndexOf("/"));
if (directory != "" && !fs.existsSync(directory)){
if (directory != "" && !fs.existsSync(directory))
fs.mkdirSync(directory, { recursive: true });
}
fs.writeFileSync(path, generateContent(), { flag: "w+" });
console.log(`- ${ANSI.fg.cyan}${path}${ANSI.reset}`);
@ -149,8 +147,6 @@ function stage() {
generate404Page(template);
generateAppPages(template);
fs.cpSync(BUILD_DIR, path.resolve(__dirname, "../../../", BUILD_DIR), { recursive: true });
console.log(`\n${ANSI.fg.green}✓ Staging complete${ANSI.reset}`);
} catch (error) {

View file

@ -24,7 +24,6 @@
| <pre>pnpm&nbsp;run&nbsp;start</pre> | Start VitePress dev server at [localhost:3000](http://localhost:3000/). Changes to module will dynamically be hot-reloaded, so normally there is no need for hard-refreshes.
| <pre>pnpm&nbsp;run&nbsp;build</pre> | Compile project using VitePress and output to the `dist` directory.
| <pre>pnpm&nbsp;run&nbsp;preview</pre> | Start web server with preview of build at [localhost:8080](http://localhost:8080/). Can be useful for validating build before deploying.
| <pre>pnpm&nbsp;run&nbsp;stage</pre> | Execute [stage.ts](./scripts/stage.ts), which copies the `./dist` directory of this package into the `/dist/docs` directory at the root, within the build of the demo site.
| <pre>pnpm&nbsp;run&nbsp;generate</pre> | Generate basic information files in JSON format to use as a base for writing the documentation and output to the `data` directory.
## Links

View file

@ -12,7 +12,6 @@
"start": "vitepress --port 3000",
"build": "vitepress build",
"preview": "vitepress preview --port 8080",
"stage": "vite-node scripts/stage",
"generate": "rimraf data && vite-node scripts/generateData"
},
"repository": {

View file

@ -1,22 +0,0 @@
import { ANSI } from "../../core/src/constants";
import { name } from "../package.json";
import fs from "node:fs";
import { resolve } from "node:path";
const BUILD_DIR = "dist";
function stage() {
try {
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
console.log(`${ANSI.fg.yellow}Staging build...${ANSI.reset}`);
fs.cpSync(BUILD_DIR, resolve(__dirname, `../../../${BUILD_DIR}/docs/`), { recursive: true });
console.log(`\n${ANSI.fg.green}✓ Staging complete${ANSI.reset}`);
} catch (error) {
console.error(error);
console.log(`${ANSI.fg.red}⚠ Staging failed${ANSI.reset}`);
process.exit(1);
}
}
stage();

View file

@ -33,19 +33,17 @@ const createGitHubRelease = (): void => {
// Write changelog to a temporary file
fs.writeFileSync(changelogFilePath, changelog);
// Push all tags, not recommended
console.log(`${ANSI.fg.yellow}Pushing tags...${ANSI.reset}`);
execSync("git push --tags", {
console.log(`${ANSI.fg.yellow}Pushing tag...${ANSI.reset}`);
execSync(`git push origin tag ${tagName}`, {
stdio: "inherit"
});
// Create a new release
console.log(`${ANSI.fg.yellow}Creating release...${ANSI.reset}`);
execSync(`gh release create ${tagName} --title "${releaseTitle}" --notes-file "${changelogFilePath}"`, {
stdio: "inherit"
});
console.log(`\n${ANSI.fg.green}✓ Release created:${ANSI.reset} ${releaseTitle}`);
console.log(`\n${ANSI.fg.green}✓ Release created: ${ANSI.fg.cyan + releaseTitle + ANSI.reset}`);
} catch (error) {
if ((error as Record<string, string>).stdout) {
console.error((error as Record<string, string>).stdout.toString());
@ -54,7 +52,7 @@ const createGitHubRelease = (): void => {
console.error((error as Record<string, string>).stderr.toString());
}
console.error(`${ANSI.fg.red}⚠ Failed to create release:${ANSI.reset} ${(error as Error).message}`);
console.error(`\n${ANSI.fg.red}⚠ Failed to create release: ${(error as Error).message}${ANSI.reset}`);
process.exit(1);
} finally {
// Clean up the temporary file

30
scripts/publishSite.ts Normal file
View file

@ -0,0 +1,30 @@
import ghpages from "gh-pages";
import { ANSI } from "../packages/core/src/constants";
import { BASE_URL, BUILD_DIR, COMMIT_MESSAGE, DOMAIN, REPO_URL } from "../packages/demo/src/config/deploy.config";
import path from "node:path";
import { name } from "../package.json";
function publishSite() {
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
console.log(`${ANSI.fg.yellow}Publishing to GitHub Pages...${ANSI.reset}`);
console.log(`- Domain: ${ANSI.fg.cyan + DOMAIN + ANSI.reset}`);
console.log(`- Commit message: ${ANSI.fg.cyan + COMMIT_MESSAGE + ANSI.reset}`);
console.log(`- Repository: ${ANSI.fg.cyan + REPO_URL + ANSI.reset}\n`);
void ghpages.publish(path.resolve(__dirname, "../", BUILD_DIR), {
repo: REPO_URL,
message: COMMIT_MESSAGE
}, (error) => {
if (error == null)
return;
console.error(error);
console.log(`${ANSI.fg.red}⚠ Failed to publish${ANSI.reset}`);
process.exit(1);
}).then(() => {
console.log(`${ANSI.fg.green}✓ Published site: ${ANSI.fg.cyan + BASE_URL + ANSI.reset}`);
});
}
publishSite();

45
scripts/stageSite.ts Normal file
View file

@ -0,0 +1,45 @@
import { ANSI } from "../packages/core/src/constants";
import { name } from "../package.json";
import fs from "node:fs";
import { BUILD_DIR } from "packages/demo/src/config/deploy.config";
import { resolve } from "node:path";
const PACKAGES = [
{ source: `../packages/demo/${BUILD_DIR}`, path: "/" },
{ source: `../packages/docs/${BUILD_DIR}`, path: "/docs" }
];
const TARGET = `../${BUILD_DIR}`;
function stageSite() {
try {
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
console.log(`${ANSI.fg.yellow}Staging site...${ANSI.reset}`);
PACKAGES.forEach(({ source, path }) => {
const sourceDirectory = resolve(__dirname, source);
const targetDirectory = resolve(__dirname, TARGET, path.replace(/^\//, ""));
if (!fs.existsSync(targetDirectory))
fs.mkdirSync(targetDirectory, { recursive: true });
fs.cpSync(sourceDirectory, targetDirectory, { recursive: true });
console.log(`- Copied ${ANSI.fg.cyan + source.replace(/^\.\.\//, "") + ANSI.reset} to ${ANSI.fg.cyan + path + ANSI.reset}`);
});
console.log(`\n${ANSI.fg.green}✓ Site staged: ${ANSI.fg.cyan}./${BUILD_DIR + ANSI.reset}`);
} catch (error) {
if ((error as Record<string, string>).stdout) {
console.error((error as Record<string, string>).stdout.toString());
}
if ((error as Record<string, string>).stderr) {
console.error((error as Record<string, string>).stderr.toString());
}
console.error(error);
console.log(`${ANSI.fg.red}⚠ Staging failed${ANSI.reset}`);
process.exit(1);
}
}
stageSite();