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

fix: bin installation from git #1667

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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 .changeset/beige-actors-march.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/forc": patch
"@fuel-ts/fuel-core": patch
---

Fixing installation from git branches
2 changes: 1 addition & 1 deletion packages/forc/lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { spawn } from 'child_process';

// eslint-disable-next-line import/extensions
import binPath from './index.js';
import { binPath } from './shared.js';

const args = process.argv.slice(2);
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);
8 changes: 0 additions & 8 deletions packages/forc/lib/index.js

This file was deleted.

29 changes: 13 additions & 16 deletions packages/forc/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { execSync } from 'child_process';
import { cpSync } from 'fs';
import fs from 'fs/promises';
import path, { join, dirname } from 'path';
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const __dirname = dirname(fileURLToPath(import.meta.url));

export const binPath = join(__dirname, '../forc-binaries/forc');

const platforms = {
darwin: {
arm64: 'darwin_arm64',
Expand All @@ -18,10 +19,6 @@ const platforms = {
},
};

const binPath = join(__dirname, '../forc-binaries/forc');

export default binPath;

export const getPkgPlatform = () => {
if (process.platform !== 'darwin' && process.platform !== 'linux') {
throw new Error(
Expand All @@ -36,28 +33,28 @@ export const getPkgPlatform = () => {
return platforms[process.platform][process.arch];
};

const versionFilePath = path.join(__dirname, '../VERSION');
const versionFilePath = join(__dirname, '../VERSION');

export const getCurrentVersion = async () => {
const versionContents = await fs.readFile(versionFilePath, 'utf8');
export const getCurrentVersion = () => {
const versionContents = readFileSync(versionFilePath, 'utf8');
const forcVersion = versionContents.match(/^.+$/m)?.[0] || versionContents;
return forcVersion;
};

export const setCurrentVersion = async (version) => {
await fs.writeFile(versionFilePath, version);
export const setCurrentVersion = (version) => {
writeFileSync(versionFilePath, version);
};

export const isGitBranch = (versionFileContents) => versionFileContents.indexOf('git:') !== -1;

const swayRepoUrl = 'https://github.com/fuellabs/sway.git';

export const buildFromGitBranch = (branchName) => {
fs.rmSync('sway-repo', { recursive: true, force: true });
fs.rmSync('forc-binaries', { recursive: true, force: true });
rmSync('sway-repo', { recursive: true, force: true });
rmSync('forc-binaries', { recursive: true, force: true });
execSync(`git clone --branch ${branchName} ${swayRepoUrl} sway-repo`);
execSync(`cd sway-repo && cargo build`);
fs.mkdirSync('forc-binaries');
mkdirSync('forc-binaries');
cpSync('sway-repo/target/debug/forc', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-deploy', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-doc', 'forc-binaries');
Expand All @@ -66,5 +63,5 @@ export const buildFromGitBranch = (branchName) => {
cpSync('sway-repo/target/debug/forc-run', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-submit', 'forc-binaries');
cpSync('sway-repo/target/debug/forc-tx', 'forc-binaries');
fs.rmSync('sway-repo', { recursive: true, force: true });
rmSync('sway-repo', { recursive: true, force: true });
};
2 changes: 1 addition & 1 deletion packages/fuel-core/lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { spawn } from 'child_process';

// eslint-disable-next-line import/extensions
import binPath from './index.js';
import { binPath } from './shared.js';

const args = process.argv.slice(2);
spawn(binPath, args, { stdio: 'inherit' }).on('exit', process.exit);
8 changes: 0 additions & 8 deletions packages/fuel-core/lib/index.js

This file was deleted.

15 changes: 8 additions & 7 deletions packages/fuel-core/lib/shared.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { execSync } from 'child_process';
import { cpSync, rmSync } from 'fs';
import fs from 'fs/promises';
import { cpSync, mkdirSync, rmSync, readFileSync, writeFileSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';

// eslint-disable-next-line @typescript-eslint/naming-convention
export const __dirname = dirname(fileURLToPath(import.meta.url));

export const binPath = join(__dirname, '../fuel-core-binaries/fuel-core');

const platforms = {
darwin: {
arm64: 'aarch64-apple-darwin',
Expand Down Expand Up @@ -34,13 +35,13 @@ export const getPkgPlatform = () => {

const versionFilePath = join(__dirname, '../VERSION');

export const getCurrentVersion = async () => {
const fuelCoreVersion = await fs.readFile(versionFilePath, 'utf8');
export const getCurrentVersion = () => {
const fuelCoreVersion = readFileSync(versionFilePath, 'utf8');
return fuelCoreVersion.trim();
};

export const setCurrentVersion = async (version) => {
await fs.writeFile(versionFilePath, version);
export const setCurrentVersion = (version) => {
writeFileSync(versionFilePath, version);
};

export const isGitBranch = (versionFileContents) => versionFileContents.indexOf('git:') !== -1;
Expand All @@ -52,7 +53,7 @@ export const buildFromGitBranch = (branchName) => {
rmSync('fuel-core-binaries', { recursive: true, force: true });
execSync(`git clone --branch ${branchName} ${fuelCoreRepoUrl} fuel-core-repo`, { silent: true });
execSync(`cd fuel-core-repo && cargo build`, { silent: true });
fs.mkdirSync('fuel-core-binaries');
mkdirSync('fuel-core-binaries');
cpSync('fuel-core-repo/target/debug/fuel-core', 'fuel-core-binaries/fuel-core');
rmSync('fuel-core-repo', { recursive: true, force: true });
};
Loading