Skip to content

Commit

Permalink
fix(tools): move package script to tool script and leverage ao-build-…
Browse files Browse the repository at this point in the history
…config
  • Loading branch information
atticusofsparta committed Jan 13, 2025
1 parent 1459a1c commit ea8ecbe
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
62 changes: 62 additions & 0 deletions tools/copy-aos-process.mjs
Original file line number Diff line number Diff line change
@@ -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();

0 comments on commit ea8ecbe

Please sign in to comment.