From 38847c815fdf18513c3eb32de5d9e52e69ebbb66 Mon Sep 17 00:00:00 2001 From: Matthew Soulanille Date: Thu, 5 Sep 2024 21:05:08 +0000 Subject: [PATCH] Move GCP upload script to a separate package --- .../.changeset/chilled-rings-brake.md | 6 + custom_nodes/package-lock.json | 124 +++++++++++++++++- custom_nodes/packages/gemini/package.json | 3 +- .../packages/gemini/scripts/upload_to_gcp.js | 29 ---- .../packages/scripts/eslint.config.js | 1 + custom_nodes/packages/scripts/package.json | 28 ++++ .../packages/scripts/src/upload-to-gcp.ts | 55 ++++++++ custom_nodes/packages/scripts/tsconfig.json | 8 ++ custom_nodes/packages/tsconfig/tsconfig.json | 5 +- 9 files changed, 222 insertions(+), 37 deletions(-) create mode 100644 custom_nodes/.changeset/chilled-rings-brake.md delete mode 100644 custom_nodes/packages/gemini/scripts/upload_to_gcp.js create mode 100644 custom_nodes/packages/scripts/eslint.config.js create mode 100644 custom_nodes/packages/scripts/package.json create mode 100644 custom_nodes/packages/scripts/src/upload-to-gcp.ts create mode 100644 custom_nodes/packages/scripts/tsconfig.json diff --git a/custom_nodes/.changeset/chilled-rings-brake.md b/custom_nodes/.changeset/chilled-rings-brake.md new file mode 100644 index 0000000..d3490d6 --- /dev/null +++ b/custom_nodes/.changeset/chilled-rings-brake.md @@ -0,0 +1,6 @@ +--- +'@visualblocks/tsconfig': minor +'@visualblocks/gemini': minor +--- + +Move GCP upload script to a separate scripts package diff --git a/custom_nodes/package-lock.json b/custom_nodes/package-lock.json index 588f46e..d3854e3 100644 --- a/custom_nodes/package-lock.json +++ b/custom_nodes/package-lock.json @@ -20,7 +20,7 @@ }, "apps/devserver": { "name": "@visualblocks/devserver", - "version": "0.0.0", + "version": "0.1.0", "dependencies": { "@visualblocks/custom-node-types": "*", "@visualblocks/gemini": "*", @@ -1348,6 +1348,12 @@ "win32" ] }, + "node_modules/@types/argparse": { + "version": "2.0.16", + "resolved": "https://registry.npmjs.org/@types/argparse/-/argparse-2.0.16.tgz", + "integrity": "sha512-aMqBra2JlqpFeCWOinCtpRpiCkPIXH8hahW2+FkGzvWjfE5sAqtOcrjN5DRcMnTQqFDe6gb1CVYuGnBH0lhXwA==", + "dev": true + }, "node_modules/@types/estree": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", @@ -1642,10 +1648,18 @@ "resolved": "packages/node-utils", "link": true }, + "node_modules/@visualblocks/scripts": { + "resolved": "packages/scripts", + "link": true + }, "node_modules/@visualblocks/tsconfig": { "resolved": "packages/tsconfig", "link": true }, + "node_modules/@visualblocks/utility-nodes": { + "resolved": "packages/utility-nodes", + "link": true + }, "node_modules/accepts": { "version": "1.3.8", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.8.tgz", @@ -5112,6 +5126,12 @@ } } }, + "node_modules/undici-types": { + "version": "6.19.8", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", + "dev": true + }, "node_modules/universalify": { "version": "0.1.2", "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.2.tgz", @@ -5355,7 +5375,7 @@ }, "packages/custom-node-types": { "name": "@visualblocks/custom-node-types", - "version": "0.1.0", + "version": "0.2.0", "license": "Apache-2.0", "devDependencies": { "@visualblocks/tsconfig": "*" @@ -5363,7 +5383,7 @@ }, "packages/eslint-config": { "name": "@visualblocks/eslint-config", - "version": "0.0.0", + "version": "0.1.0", "license": "Apache-2.0", "devDependencies": { "@eslint/js": "^9.8.0", @@ -5372,7 +5392,7 @@ }, "packages/gemini": { "name": "@visualblocks/gemini", - "version": "0.1.0", + "version": "0.2.1", "license": "Apache-2.0", "dependencies": { "@google/generative-ai": "^0.16.0", @@ -5382,6 +5402,7 @@ "@visualblocks/custom-node-types": "*", "@visualblocks/eslint-config": "*", "@visualblocks/node-utils": "*", + "@visualblocks/scripts": "*", "@visualblocks/tsconfig": "*", "esbuild": "^0.23.0", "eslint": "^9.8.0", @@ -5393,7 +5414,8 @@ }, "packages/node-utils": { "name": "@visualblocks/node-utils", - "version": "0.0.0", + "version": "0.1.0", + "license": "Apache-2.0", "dependencies": { "fast-deep-equal": "^3.1.3", "lit": "^3.1.4" @@ -5407,10 +5429,100 @@ "typescript": "^5.5.4" } }, + "packages/publish-to-gcp": { + "name": "@visualblocks/publish-to-gcp", + "extraneous": true, + "license": "Apache-2.0", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "publish-to-gcp": "dist/index.js" + }, + "devDependencies": { + "@types/argparse": "^2.0.16", + "@types/node": "^22.5.4" + } + }, + "packages/scripts": { + "name": "@visualblocks/scripts", + "license": "Apache-2.0", + "dependencies": { + "argparse": "^2.0.1", + "chalk": "^5.3.0" + }, + "bin": { + "upload-to-gcp": "dist/upload-to-gcp.js" + }, + "devDependencies": { + "@types/argparse": "^2.0.16", + "@types/node": "^22.5.4", + "@visualblocks/tsconfig": "*" + } + }, + "packages/scripts/node_modules/@types/node": { + "version": "22.5.4", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.5.4.tgz", + "integrity": "sha512-FDuKUJQm/ju9fT/SeX/6+gBzoPzlVCzfzmGkwKvRHQVxi4BntVbyIwf6a4Xn62mrvndLiml6z/UBXIdEVjQLXg==", + "dev": true, + "dependencies": { + "undici-types": "~6.19.2" + } + }, + "packages/scripts/node_modules/argparse": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", + "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==" + }, + "packages/scripts/node_modules/chalk": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "packages/tsconfig": { "name": "@visualblocks/tsconfig", - "version": "0.1.0", + "version": "0.2.0", "license": "Apache-2.0" + }, + "packages/upload-to-gcp": { + "name": "@visualblocks/upload-to-gcp", + "extraneous": true, + "license": "Apache-2.0", + "dependencies": { + "argparse": "^2.0.1" + }, + "bin": { + "upload-to-gcp": "dist/upload-to-gcp.js" + }, + "devDependencies": { + "@types/argparse": "^2.0.16", + "@types/node": "^22.5.4" + } + }, + "packages/utility-nodes": { + "name": "@visualblocks/utility-nodes", + "version": "0.0.0", + "license": "Apache-2.0", + "dependencies": { + "lit": "^3.1.4" + }, + "devDependencies": { + "@visualblocks/custom-node-types": "*", + "@visualblocks/eslint-config": "*", + "@visualblocks/node-utils": "*", + "@visualblocks/scripts": "*", + "@visualblocks/tsconfig": "*", + "esbuild": "^0.23.0", + "eslint": "^9.8.0", + "tsup": "^8.2.3", + "typescript": "^5.5.4" + } } } } diff --git a/custom_nodes/packages/gemini/package.json b/custom_nodes/packages/gemini/package.json index 308c36b..6d9b0e7 100644 --- a/custom_nodes/packages/gemini/package.json +++ b/custom_nodes/packages/gemini/package.json @@ -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", diff --git a/custom_nodes/packages/gemini/scripts/upload_to_gcp.js b/custom_nodes/packages/gemini/scripts/upload_to_gcp.js deleted file mode 100644 index d69e919..0000000 --- a/custom_nodes/packages/gemini/scripts/upload_to_gcp.js +++ /dev/null @@ -1,29 +0,0 @@ -import {exec} from 'child_process'; -import * as fs from 'node:fs/promises'; -import * as path from 'path'; - -function $(command) { - console.log(command); - return exec(command); -} - -const packageJsonDir = path.join(import.meta.dirname, '../'); -const packageJsonData = await fs.readFile( - path.join(packageJsonDir, 'package.json') -); -const packageJson = JSON.parse(packageJsonData.toString('utf8')); -const {name, version} = packageJson; - -const versionedGcpPackagePath = `gs://tfweb/visualblocks-github-bundles/${name}@${version}/`; -const latestGcpPackagePath = `gs://tfweb/visualblocks-github-bundles/${name}@latest/`; - -for (const gcpPath of [versionedGcpPackagePath, latestGcpPackagePath]) { - console.log('Copying package.json to GCP'); - $(`cd ${packageJsonDir} && 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. - console.log('Copying dist/ to GCP'); - $(`cd ${packageJsonDir} && gcloud storage cp -r dist ${gcpPath}`); -} diff --git a/custom_nodes/packages/scripts/eslint.config.js b/custom_nodes/packages/scripts/eslint.config.js new file mode 100644 index 0000000..770faae --- /dev/null +++ b/custom_nodes/packages/scripts/eslint.config.js @@ -0,0 +1 @@ +export {default} from '@visualblocks/eslint-config'; diff --git a/custom_nodes/packages/scripts/package.json b/custom_nodes/packages/scripts/package.json new file mode 100644 index 0000000..39ae518 --- /dev/null +++ b/custom_nodes/packages/scripts/package.json @@ -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" + } +} diff --git a/custom_nodes/packages/scripts/src/upload-to-gcp.ts b/custom_nodes/packages/scripts/src/upload-to-gcp.ts new file mode 100644 index 0000000..b444244 --- /dev/null +++ b/custom_nodes/packages/scripts/src/upload-to-gcp.ts @@ -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)); diff --git a/custom_nodes/packages/scripts/tsconfig.json b/custom_nodes/packages/scripts/tsconfig.json new file mode 100644 index 0000000..a136189 --- /dev/null +++ b/custom_nodes/packages/scripts/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "@visualblocks/tsconfig/tsconfig.json", + "compilerOptions": { + "noEmit": false, + "outDir": "dist" + }, + "include": ["*.ts", "src/**/*.ts", "src/upload-to-gcp.ts~"] +} diff --git a/custom_nodes/packages/tsconfig/tsconfig.json b/custom_nodes/packages/tsconfig/tsconfig.json index f8eeca5..06f8507 100644 --- a/custom_nodes/packages/tsconfig/tsconfig.json +++ b/custom_nodes/packages/tsconfig/tsconfig.json @@ -8,6 +8,7 @@ "noUncheckedIndexedAccess": true, "strict": true, "moduleResolution": "Node", + "module": "ESNext", /* Interop Constraints */ "esModuleInterop": true, @@ -21,7 +22,9 @@ "skipLibCheck": true, /* This project builds with esbuild */ - "noEmit": true + "noEmit": true, + + "sourceMap": true }, "exclude": ["**/node_modules"] }