Skip to content

Commit

Permalink
Move GCP upload script to a separate package
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsoulanille committed Sep 5, 2024
1 parent f966e57 commit daf19a8
Show file tree
Hide file tree
Showing 9 changed files with 222 additions and 37 deletions.
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 @@
---
'@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"]
}

0 comments on commit daf19a8

Please sign in to comment.