Skip to content

Commit

Permalink
fix missing file issues when running solo from npm install -g
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Oct 23, 2024
1 parent 3ed4120 commit ebbe79d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@hashgraph/solo",
"version": "0.31.2",
"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"
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, 'src', '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')
14 changes: 7 additions & 7 deletions src/core/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ import { color, type ListrLogger, PRESET_TIMER } from 'listr2'
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 CUR_FILE_DIR = dirname(fileURLToPath(import.meta.url))
export const SOLO_HOME_DIR = process.env.SOLO_HOME || path.join(process.env.HOME as string, '.solo')
export const SOLO_LOGS_DIR = path.join(SOLO_HOME_DIR, 'logs')
export const SOLO_CACHE_DIR = path.join(SOLO_HOME_DIR, 'cache')
Expand Down Expand Up @@ -63,9 +62,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 @@ -115,10 +114,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
6 changes: 1 addition & 5 deletions src/core/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@
*/
import fs from 'fs'
import os from 'os'
import path, * as paths from 'path'
import path from 'path'
import util from 'util'
import { SoloError } from './errors.ts'
import { fileURLToPath } from 'url'
import * as semver from 'semver'
import { Templates } from './templates.ts'
import { HEDERA_HAPI_PATH, ROOT_CONTAINER, SOLO_LOGS_DIR } from './constants.ts'
Expand All @@ -33,9 +32,6 @@ import { type NodeAlias, type NodeAliases, type PodName } from '../types/aliases
import { type NodeDeleteConfigClass } from '../commands/node.ts'
import { type CommandFlag } from '../types/index.js'

// cache current directory
const CUR_FILE_DIR = paths.dirname(fileURLToPath(import.meta.url))

export function sleep (ms: number) {
return new Promise<void>((resolve) => {
setTimeout(resolve, ms)
Expand Down

0 comments on commit ebbe79d

Please sign in to comment.