From ea8ecbee80fed364d542c942048bfb51a77df9b1 Mon Sep 17 00:00:00 2001 From: atticusofsparta Date: Mon, 13 Jan 2025 06:15:19 -0600 Subject: [PATCH] fix(tools): move package script to tool script and leverage ao-build-config --- package.json | 2 +- tools/copy-aos-process.mjs | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 tools/copy-aos-process.mjs diff --git a/package.json b/package.json index bc4a73b..c218744 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "type": "module", "scripts": { - "copy-aos-process": "rm -rf tools/fixtures/aos-process && git clone https://github.com/permaweb/aos.git temp-repo && cd temp-repo && git checkout 15dd81ee596518e2f44521e973b8ad1ce3ee9945 && cd .. && mv temp-repo/process tools/fixtures/aos-process && rm -rf temp-repo && cp ao-build-config.yml tools/fixtures/aos-process/config.yml", + "copy-aos-process": "node tools/copy-aos-process.mjs", "module:build": "rm -rf dist && yarn aos:build && rm -rf build && cp -r tools/fixtures/aos-process build && cp dist/aos-bundled.lua build/ant.lua && yarn node tools/inject-ant-code.mjs && cd build && ao build && mv process.wasm ../dist/aos-ant.wasm && cd .. && rm -rf build && yarn module:load", "module:publish": "node tools/publish-module.mjs", "module:load": "node tools/load-module.mjs", diff --git a/tools/copy-aos-process.mjs b/tools/copy-aos-process.mjs new file mode 100644 index 0000000..acc7c96 --- /dev/null +++ b/tools/copy-aos-process.mjs @@ -0,0 +1,62 @@ +import { exec } from 'node:child_process'; +import { promisify } from 'node:util'; +import { rm, rename, copyFile } from 'node:fs/promises'; +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'url'; +import yaml from 'js-yaml'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const execAsync = promisify(exec); + +const configContent = fs.readFileSync( + path.join(__dirname, '../ao-build-config.yml'), + 'utf-8', +); + +const config = yaml.load(configContent); + +const repoUrl = 'https://github.com/permaweb/aos.git'; +const commitHash = config.aos_git_hash; +const tempRepoDir = path.resolve('temp-repo'); +const processTargetDir = path.resolve('tools/fixtures/aos-process'); +const configSourceFile = path.resolve('ao-build-config.yml'); +const configDestFile = path.join(processTargetDir, 'config.yml'); + +async function copyAosProcess() { + try { + // Step 1: Remove existing `aos-process` directory + console.log(`Removing existing directory: ${processTargetDir}`); + await rm(processTargetDir, { recursive: true, force: true }); + + // Step 2: Clone the repository into a temporary directory + console.log(`Cloning repository: ${repoUrl}`); + await execAsync(`git clone ${repoUrl} ${tempRepoDir}`); + + // Step 3: Checkout the specific commit hash + console.log(`Checking out commit: ${commitHash}`); + await execAsync(`git checkout ${commitHash}`, { cwd: tempRepoDir }); + + // Step 4: Move the `process` directory to the target location + const processDir = path.join(tempRepoDir, 'process'); + console.log(`Moving ${processDir} to ${processTargetDir}`); + await rename(processDir, processTargetDir); + + // Step 5: Remove the temporary repository + console.log(`Removing temporary directory: ${tempRepoDir}`); + await rm(tempRepoDir, { recursive: true, force: true }); + + // Step 6: Copy the build config file to the target directory + console.log(`Copying ${configSourceFile} to ${configDestFile}`); + await copyFile(configSourceFile, configDestFile); + + console.log('Successfully copied aos process and config.'); + } catch (error) { + console.error('Error during copy-aos-process:', error); + process.exit(1); + } +} + +copyAosProcess();