From ebbe79d3f9529a754085e8501eace736db5e86ab Mon Sep 17 00:00:00 2001 From: Jeromy Cannon Date: Wed, 23 Oct 2024 10:06:10 +0100 Subject: [PATCH] fix missing file issues when running solo from npm install -g Signed-off-by: Jeromy Cannon --- package.json | 2 +- resources/post-build-script.js | 18 +++++++++++++++++- src/core/constants.ts | 14 +++++++------- src/core/helpers.ts | 6 +----- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 617c68676..14de865b5 100644 --- a/package.json +++ b/package.json @@ -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" diff --git a/resources/post-build-script.js b/resources/post-build-script.js index 71a8d77e2..c7adac99c 100644 --- a/resources/post-build-script.js +++ b/resources/post-build-script.js @@ -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) { @@ -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') diff --git a/src/core/constants.ts b/src/core/constants.ts index 1164d53fe..d0e6a45f9 100644 --- a/src/core/constants.ts +++ b/src/core/constants.ts @@ -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') @@ -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 = 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' @@ -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 } diff --git a/src/core/helpers.ts b/src/core/helpers.ts index 4e8addfbd..d454f8c92 100644 --- a/src/core/helpers.ts +++ b/src/core/helpers.ts @@ -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' @@ -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((resolve) => { setTimeout(resolve, ms)