Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move GCP upload script to a separate package #74

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions custom_nodes/.changeset/chilled-rings-brake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is a changeset that records what this PR changed, what packages are affected, and how those packages' versions should be bumped (major / minor / patch). When we publish, I run changeset version, and it automatically updates all the package.json files with the correct version increase. Then, it deletes all these pending changeset files and puts them in the changelog for each package.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!!

'@visualblocks/tsconfig': minor
'@visualblocks/gemini': minor
---

Move GCP upload script to a separate scripts package
124 changes: 118 additions & 6 deletions custom_nodes/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion custom_nodes/packages/gemini/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"lint": "eslint .",
"typecheck": "tsc",
"upload-to-gcp": "node scripts/upload_to_gcp.js"
"upload-to-gcp": "upload-to-gcp"
},
"devDependencies": {
"@visualblocks/custom-node-types": "*",
"@visualblocks/node-utils": "*",
"@visualblocks/tsconfig": "*",
"@visualblocks/eslint-config": "*",
"@visualblocks/scripts": "*",
"esbuild": "^0.23.0",
"eslint": "^9.8.0",
"express": "^4.19.2",
Expand Down
29 changes: 0 additions & 29 deletions custom_nodes/packages/gemini/scripts/upload_to_gcp.js

This file was deleted.

1 change: 1 addition & 0 deletions custom_nodes/packages/scripts/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {default} from '@visualblocks/eslint-config';
28 changes: 28 additions & 0 deletions custom_nodes/packages/scripts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@visualblocks/scripts",
"private": "true",
"description": "Script for uploading a package to gcp",
"type": "module",
"files": [
"dist/**"
],
"license": "Apache-2.0",
"bin": {
"upload-to-gcp": "./dist/upload-to-gcp.js"
},
"scripts": {
"build": "tsc",
"clean": "rm -rf .turbo && rm -rf node_modules && rm -rf dist",
"lint": "eslint .",
"upload-to-gcp": "upload-to-gcp"
},
"devDependencies": {
"@types/argparse": "^2.0.16",
"@types/node": "^22.5.4",
"@visualblocks/tsconfig": "*"
},
"dependencies": {
"argparse": "^2.0.1",
"chalk": "^5.3.0"
}
}
55 changes: 55 additions & 0 deletions custom_nodes/packages/scripts/src/upload-to-gcp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/usr/bin/env node

import {ArgumentParser} from 'argparse';
import {exec} from 'child_process';
import * as fs from 'node:fs/promises';
import * as path from 'path';
import chalk from 'chalk';

function $(command: string) {
console.log(chalk.gray(command));
return exec(command);
}

export async function uploadPackageToGcp(packagePath = '.') {
packagePath = await fs.realpath(packagePath);

const packageJsonData = await fs.readFile(
path.join(packagePath, 'package.json')
);

const packageJson = JSON.parse(packageJsonData.toString('utf8'));
const {name, version} = packageJson;

console.log(`Uploading ${chalk.bold(name)} to GCP`);

const versionedGcpPackagePath = `gs://tfweb/visualblocks-github-bundles/${name}@${version}/`;
const latestGcpPackagePath = `gs://tfweb/visualblocks-github-bundles/${name}@latest/`;

for (const gcpPath of [versionedGcpPackagePath, latestGcpPackagePath]) {
$(`cd ${packagePath} && gcloud storage cp -r package.json ${gcpPath}`);

// Copy the dist/ bundles and sourcemaps.
// The src/ directory is not required for sourcemaps to work since they bundle
// the source code themselves.
$(`cd ${packagePath} && gcloud storage cp -r dist ${gcpPath}`);
}
}

async function main() {
const parser = new ArgumentParser({
description:
'Upload a package to the VisualBlocks GitHub GCP bucket. Run in the root directory of the package to upload.',
});

parser.add_argument('-p', '--package', {
help: 'The path to the root directory of the package to upload',
type: String,
default: '.',
});
const args = parser.parse_args();

uploadPackageToGcp(args['packagePath'] as string);
}

main().catch((e: Error) => console.error(e));
8 changes: 8 additions & 0 deletions custom_nodes/packages/scripts/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@visualblocks/tsconfig/tsconfig.json",
"compilerOptions": {
"noEmit": false,
"outDir": "dist"
},
"include": ["*.ts", "src/**/*.ts", "src/upload-to-gcp.ts~"]
}
5 changes: 4 additions & 1 deletion custom_nodes/packages/tsconfig/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"noUncheckedIndexedAccess": true,
"strict": true,
"moduleResolution": "Node",
"module": "ESNext",

/* Interop Constraints */
"esModuleInterop": true,
Expand All @@ -21,7 +22,9 @@
"skipLibCheck": true,

/* This project builds with esbuild */
"noEmit": true
"noEmit": true,

"sourceMap": true
},
"exclude": ["**/node_modules"]
}