Skip to content

Commit

Permalink
bake version info into bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Dec 31, 2023
1 parent a4b2ade commit 55ac11c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions src/@types/global.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

declare const POWFAUCET_VERSION: string;
18 changes: 12 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path, { dirname, basename } from "path";
import { fileURLToPath } from "url";
import { isMainThread, workerData } from "node:worker_threads";
import { loadFaucetConfig, setAppBasePath } from "./config/FaucetConfig.js";
import { faucetConfig, loadFaucetConfig, setAppBasePath } from "./config/FaucetConfig.js";
import { FaucetWorkers } from "./common/FaucetWorker.js";
import { EthWalletManager } from "./eth/EthWalletManager.js";
import { FaucetHttpServer } from "./webserv/FaucetHttpServer.js";
Expand All @@ -20,13 +20,19 @@ import { FaucetStatus } from "./services/FaucetStatus.js";
}
else {
try {
let importUrl = fileURLToPath(import.meta.url);
const __dirname = dirname(importUrl);
let srcfile: string;
if(typeof require !== "undefined") {
srcfile = require.main.filename;
} else {
srcfile = fileURLToPath(import.meta.url);
}
let basepath = path.join(dirname(srcfile), "..");

setAppBasePath(path.join(__dirname, ".."))
loadFaucetConfig()
setAppBasePath(basepath);
loadFaucetConfig();
ServiceManager.GetService(FaucetProcess).emitLog(FaucetLogLevel.INFO, "Initializing PoWFaucet v" + faucetConfig.faucetVersion + " (AppBasePath: " + faucetConfig.appBasePath + ", InternalBasePath: " + basepath + ")");
ServiceManager.GetService(FaucetProcess).initialize();
ServiceManager.GetService(FaucetWorkers).initialize(importUrl);
ServiceManager.GetService(FaucetWorkers).initialize(srcfile);
ServiceManager.GetService(FaucetStatus).initialize();
ServiceManager.GetService(FaucetStatsLog).initialize();
await ServiceManager.GetService(FaucetDatabase).initialize();
Expand Down
12 changes: 9 additions & 3 deletions src/config/FaucetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ let cliArgs = (function() {
})();


let packageJson = JSON.parse(fs.readFileSync(path.join(".", "package.json"), 'utf8'));
let internalBasePath = path.join(".");
let basePath: string;
if(cliArgs['datadir']) {
Expand Down Expand Up @@ -56,7 +55,14 @@ export function setAppBasePath(basePath: string) {
export function loadFaucetConfig(loadDefaultsOnly?: boolean) {
let config: IConfigSchema;
let configFile = faucetConfigFile;
debugger;

let faucetVersion: string;
if(typeof POWFAUCET_VERSION !== "undefined") {

Check failure on line 60 in src/config/FaucetConfig.ts

View workflow job for this annotation

GitHub Actions / Run Tests

Cannot find name 'POWFAUCET_VERSION'. Did you mean 'faucetVersion'?
faucetVersion = POWFAUCET_VERSION;

Check failure on line 61 in src/config/FaucetConfig.ts

View workflow job for this annotation

GitHub Actions / Run Tests

Cannot find name 'POWFAUCET_VERSION'. Did you mean 'faucetVersion'?
} else {
let packageJson = JSON.parse(fs.readFileSync(path.join(internalBasePath, "package.json"), 'utf8'));
faucetVersion = packageJson.version;
}

if(!fs.existsSync(configFile) && !loadDefaultsOnly) {
// create copy of faucet-config.example.yml
Expand Down Expand Up @@ -103,7 +109,7 @@ export function loadFaucetConfig(loadDefaultsOnly?: boolean) {
faucetConfig = {} as any;
Object.assign(faucetConfig, getDefaultConfig(), config, {
appBasePath: basePath,
faucetVersion: packageJson.version,
faucetVersion: faucetVersion,
} as any);
}

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"lib": ["es2015"],
"include": [
"src/@types",
"src/app.ts",
"src/tools/migrateDB.ts"
],
Expand Down
12 changes: 9 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import path, { dirname } from 'path'
import path, { dirname } from 'path';
import fs from 'fs';
import { fileURLToPath } from "url";
import webpack from "webpack";

let importUrl = fileURLToPath(import.meta.url);
const __dirname = dirname(importUrl);
const basedir = dirname(importUrl);

let packageJson = JSON.parse(fs.readFileSync(path.join(basedir, "package.json"), 'utf8'));

export default {
entry: './dist/app.js',
Expand All @@ -13,11 +16,14 @@ export default {
},
output: {
filename: 'powfaucet.cjs',
path: path.resolve(__dirname, 'bundle'),
path: path.resolve(basedir, 'bundle'),
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new webpack.DefinePlugin({
POWFAUCET_VERSION: JSON.stringify(packageJson.version),
}),
],
};

0 comments on commit 55ac11c

Please sign in to comment.