Skip to content

Commit

Permalink
fix: fix missing file issues when running solo from npm install -g (#736
Browse files Browse the repository at this point in the history
)

Signed-off-by: Jeromy Cannon <jeromy@swirldslabs.com>
  • Loading branch information
jeromy-cannon authored Oct 23, 2024
1 parent 077f989 commit 2a5cfc1
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
"name": "@hashgraph/solo",
"version": "0.31.1",
"description": "An opinionated CLI tool to deploy and manage private Hedera Networks.",
"main": "dist/index.js",
"main": "./dist/src/index.js",
"type": "module",
"bin": {
"solo": "dist/solo.js"
"solo": "./dist/solo.js"
},
"publishConfig": {
"access": "public"
Expand Down
18 changes: 17 additions & 1 deletion resources/post-build-script.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
'use strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import {fileURLToPath} from 'node:url'

const __dirname = path.dirname(fileURLToPath(import.meta.url))

//! Target directory
const distDir = path.resolve(__dirname, '../dist')
const srcPackageJsonFilePath = path.resolve(__dirname, '../package.json')
const targetPackageJsonFilePath = path.join(distDir, 'package.json')
const srcResourcesDir = path.join(__dirname, '../resources')
const targetResourcesDir = path.join(distDir, 'resources')

/** @param {string} filePath */
function replaceTsWithJs(filePath) {
Expand All @@ -33,6 +37,18 @@ function traverseDirectory(dir) {
}
}

function copyPackageJson(srcPackageJsonFilePath, targetPackageJsonFilePath) {
fs.copyFileSync(srcPackageJsonFilePath, targetPackageJsonFilePath)
}

function copyResources(srcDir, targetDir) {
fs.cpSync(srcDir, targetDir, {recursive: true})
}

console.time('Copy package.json')
copyPackageJson(srcPackageJsonFilePath, targetPackageJsonFilePath)
console.time('Copy resources')
copyResources(srcResourcesDir, targetResourcesDir)
console.time('Successfully replaced .ts extensions with .js')
traverseDirectory(distDir)
console.timeEnd('Successfully replaced .ts extensions with .js')
16 changes: 9 additions & 7 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@

import { AccountId, FileId } from '@hashgraph/sdk'
import { color, type ListrLogger, PRESET_TIMER } from 'listr2'
import path, { normalize } from 'path'
import path, { dirname, normalize } from 'path'
import { fileURLToPath } from 'url'

export const ROOT_DIR = process.cwd()
export const ROOT_DIR = path.join(dirname(fileURLToPath(import.meta.url)), '..', '..')

// -------------------- solo related constants ---------------------------------------------------------------------
export const SOLO_HOME_DIR = process.env.SOLO_HOME || path.join(process.env.HOME as string, '.solo')
Expand Down Expand Up @@ -59,9 +60,9 @@ export const MIRROR_NODE_CHART_URL = 'https://hashgraph.github.io/hedera-mirror-
export const MIRROR_NODE_CHART = 'hedera-mirror'

export const DEFAULT_CHART_REPO: Map<string, string> = new Map()
.set(SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL)
.set(JSON_RPC_RELAY_CHART, JSON_RPC_RELAY_CHART_URL)
.set(MIRROR_NODE_CHART, MIRROR_NODE_CHART_URL)
.set(SOLO_TESTING_CHART, SOLO_TESTING_CHART_URL)
.set(JSON_RPC_RELAY_CHART, JSON_RPC_RELAY_CHART_URL)
.set(MIRROR_NODE_CHART, MIRROR_NODE_CHART_URL)

// ------------------- Hedera Account related ---------------------------------------------------------------------------------
export const OPERATOR_ID = process.env.SOLO_OPERATOR_ID || '0.0.2'
Expand Down Expand Up @@ -105,10 +106,11 @@ export const LISTR_DEFAULT_RENDERER_OPTION = {
timer: LISTR_DEFAULT_RENDERER_TIMER_OPTION
} as {
collapseSubtasks: boolean
timer: { condition: (duration: number) => boolean
timer: {
condition: (duration: number) => boolean
format: (duration: number) => any
field: string | ((args_0: number) => string)
args?: [ number ]
args?: [number]
},
logger: ListrLogger
}
Expand Down
9 changes: 4 additions & 5 deletions src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import util from 'util'
import { SoloError } from './errors.ts'
import * as semver from 'semver'
import { Templates } from './templates.ts'
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.ts'
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, ROOT_DIR, SOLO_LOGS_DIR } from './constants.ts'
import { constants, type K8 } from './index.ts'
import { FileContentsQuery, FileId, PrivateKey, ServiceEndpoint } from '@hashgraph/sdk'
import { Listr } from 'listr2'
Expand All @@ -30,8 +30,8 @@ import { type NodeAlias, type NodeAliases, type PodName } from '../types/aliases
import { type NodeDeleteConfigClass } from '../commands/node/configs.ts'
import { type CommandFlag } from '../types/index.ts'
import { type V1Pod } from '@kubernetes/client-node'
import { type SoloLogger } from './logging.js'
import { type NodeCommandHandlers } from '../commands/node/handlers.js'
import { type SoloLogger } from './logging.ts'
import { type NodeCommandHandlers } from '../commands/node/handlers.ts'

export function sleep (ms: number) {
return new Promise<void>((resolve) => {
Expand Down Expand Up @@ -65,8 +65,7 @@ export function cloneArray <T> (arr: T[]): T[] {
/** load package.json */
export function loadPackageJSON (): any {
try {
const rootDir = process.cwd()
const raw = fs.readFileSync(path.join(rootDir, 'package.json'))
const raw = fs.readFileSync(path.join(ROOT_DIR, 'package.json'))
return JSON.parse(raw.toString())
} catch (e: Error | any) {
throw new SoloError('failed to load package.json', e)
Expand Down

0 comments on commit 2a5cfc1

Please sign in to comment.