Skip to content
Snippets Groups Projects
Verified Commit 2a30f7a9 authored by Mateusz Tyszczak's avatar Mateusz Tyszczak :scroll:
Browse files

Add comb config

parent ff729893
No related branches found
No related tags found
No related merge requests found
{
"$id": "https://gitlab.syncad.com/hive/comb/-/blob/main/config-schema.json",
"title": "Hive Comb plugin configuration",
"description": "Provides common configuration for Hive blockchain applications",
"type": "object",
"properties": {
"useGitlabPackageRegistry": {
"title": "Use GitLab package registry instead of npmjs",
"description": "When set to true, postinstall script will update .npmrc file with GitLab registry URL for all @hiveio-scoped packages to download from instead of npmjs registry. Default: true",
"type": "boolean",
"default": true
}
}
}
......@@ -8,7 +8,7 @@
"private": false,
"packageManager": "pnpm@9.15.4+sha512.b2dc20e2fc72b3e18848459b37359a32064663e5627a51e4c74b2c29dd8e8e0491483c3abb40789cfd578bf362fb6ba8261b05f0387d76792ed6e23ea3b1b6a0",
"scripts": {
"prebuild": "husky",
"prebuild": "husky && json2ts -i config-schema.json -o dist/config.ts",
"build": "tsc",
"postbuild": "rollup -c && size-limit",
"postinstall": "node ./dist/bundle/index.js"
......@@ -40,6 +40,7 @@
"@types/semver": "^7.5.8",
"@types/yargs": "^17.0.33",
"husky": "^9.1.7",
"json-schema-to-typescript": "^15.0.4",
"rollup": "^4.34.8",
"size-limit": "^11.1.6",
"typescript": "^5.7.3"
......@@ -54,7 +55,7 @@
"path": [
"./dist/bundle"
],
"limit": "5800 kB",
"limit": "50 kB",
"brotli": false
}
],
......@@ -73,7 +74,8 @@
"files": [
"LICENSE.md",
"README.md",
"dist/bundle"
"dist/bundle",
"config-schema.json"
],
"repository": {
"type": "git",
......
......@@ -42,6 +42,9 @@ importers:
husky:
specifier: ^9.1.7
version: 9.1.7
json-schema-to-typescript:
specifier: ^15.0.4
version: 15.0.4
rollup:
specifier: ^4.34.8
version: 4.34.8
......@@ -54,6 +57,10 @@ importers:
packages:
'@apidevtools/json-schema-ref-parser@11.9.1':
resolution: {integrity: sha512-OvyhwtYaWSTfo8NfibmFlgl+pIMaBOmN0OwZ3CPaGscEK3B8FCVDuQ7zgxY8seU/1kfSvNWnyB0DtKJyNLxX7g==}
engines: {node: '>= 16'}
'@colors/colors@1.6.0':
resolution: {integrity: sha512-Ir+AOibqzrIsL6ajt3Rz3LskB7OiMVHqltZmspbW/TJuTVuyOMirVqAkjfY6JISiLHgyNqicAC8AyHHGzNd/dA==}
engines: {node: '>=0.1.90'}
......@@ -64,6 +71,9 @@ packages:
'@jridgewell/sourcemap-codec@1.5.0':
resolution: {integrity: sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==}
'@jsdevtools/ono@7.1.3':
resolution: {integrity: sha512-4JQNk+3mVzK3xh2rqd6RB4J46qUR19azEHBneZyTZM+c456qOrbbM/5xcR8huNCCcbVt7+UmizG6GuUvPvKUYg==}
'@rollup/plugin-commonjs@28.0.2':
resolution: {integrity: sha512-BEFI2EDqzl+vA1rl97IDRZ61AIwGH093d9nz8+dThxJNH8oSoB7MjWvPCX3dkaK1/RCJ/1v/R1XB15FuSs0fQw==}
engines: {node: '>=16.0.0 || 14 >= 14.17'}
......@@ -204,6 +214,12 @@ packages:
'@types/estree@1.0.6':
resolution: {integrity: sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==}
'@types/json-schema@7.0.15':
resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==}
'@types/lodash@4.17.15':
resolution: {integrity: sha512-w/P33JFeySuhN6JLkysYUK2gEmy9kHHFN7E8ro0tkfmlDOgxBDzWEZ/J8cWA+fHqFevpswDTFZnDx+R9lbL6xw==}
'@types/node@22.13.4':
resolution: {integrity: sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==}
......@@ -230,6 +246,9 @@ packages:
resolution: {integrity: sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==}
engines: {node: '>=8'}
argparse@2.0.1:
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
async@3.2.6:
resolution: {integrity: sha512-htCUDlxyyCLMgaM3xXg0C0LW2xqfuQ6p05pCEIsXuyQ+a1koYKTuBMzRNwmybfLgvJDMd0r1LTn4+E0Ti6C2AA==}
......@@ -332,10 +351,18 @@ packages:
resolution: {integrity: sha512-UfoeMA6fIJ8wTYFEUjelnaGI67v6+N7qXJEvQuIGa99l4xsCruSYOVSQ0uPANn4dAzm8lkYPaKLrrijLq7x23w==}
engines: {node: '>= 0.4'}
is-extglob@2.1.1:
resolution: {integrity: sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==}
engines: {node: '>=0.10.0'}
is-fullwidth-code-point@3.0.0:
resolution: {integrity: sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==}
engines: {node: '>=8'}
is-glob@4.0.3:
resolution: {integrity: sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==}
engines: {node: '>=0.10.0'}
is-module@1.0.0:
resolution: {integrity: sha512-51ypPSPCoTEIN9dy5Oy+h4pShgJmPCygKfyRCISBI+JoWT/2oJvK8QPxmwv7b/p239jXrm9M1mlQbyKJ5A152g==}
......@@ -350,6 +377,15 @@ packages:
resolution: {integrity: sha512-rg9zJN+G4n2nfJl5MW3BMygZX56zKPNVEYYqq7adpmMh4Jn2QNEwhvQlFy6jPVdcod7txZtKHWnyZiA3a0zP7A==}
hasBin: true
js-yaml@4.1.0:
resolution: {integrity: sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==}
hasBin: true
json-schema-to-typescript@15.0.4:
resolution: {integrity: sha512-Su9oK8DR4xCmDsLlyvadkXzX6+GGXJpbhwoLtOGArAG61dvbW4YQmSEno2y66ahpIdmLMg6YUf/QHLgiwvkrHQ==}
engines: {node: '>=16.0.0'}
hasBin: true
kuler@2.0.0:
resolution: {integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A==}
......@@ -357,6 +393,9 @@ packages:
resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==}
engines: {node: '>=14'}
lodash@4.17.21:
resolution: {integrity: sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==}
logform@2.7.0:
resolution: {integrity: sha512-TFYA4jnP7PVbmlBIfhlSe+WKxs9dklXMTEGcBCIvLhE/Tn3H6Gk1norupVW7m5Cnd4bLcr08AytbyV/xj7f/kQ==}
engines: {node: '>= 12.0.0'}
......@@ -364,6 +403,9 @@ packages:
magic-string@0.30.17:
resolution: {integrity: sha512-sNPKHvyjVf7gyjwS4xGTaW/mCnF8wnjtifKBEhxfZ7E/S8tQ0rssrwGNn6q8JH/ohItJfSQp9mBtQYuTlH5QnA==}
minimist@1.2.8:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
ms@2.1.3:
resolution: {integrity: sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==}
......@@ -383,6 +425,11 @@ packages:
resolution: {integrity: sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==}
engines: {node: '>=12'}
prettier@3.5.1:
resolution: {integrity: sha512-hPpFQvHwL3Qv5AdRvBFMhnKo4tYxp0ReXiPn2bxkiohEX6mBeBwEpBSQTkD458RaaDKQMYSp4hX4UtfUTA5wDw==}
engines: {node: '>=14'}
hasBin: true
readable-stream@3.6.2:
resolution: {integrity: sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==}
engines: {node: '>= 6'}
......@@ -491,6 +538,12 @@ packages:
snapshots:
'@apidevtools/json-schema-ref-parser@11.9.1':
dependencies:
'@jsdevtools/ono': 7.1.3
'@types/json-schema': 7.0.15
js-yaml: 4.1.0
'@colors/colors@1.6.0': {}
'@dabh/diagnostics@2.0.3':
......@@ -501,6 +554,8 @@ snapshots:
'@jridgewell/sourcemap-codec@1.5.0': {}
'@jsdevtools/ono@7.1.3': {}
'@rollup/plugin-commonjs@28.0.2(rollup@4.34.8)':
dependencies:
'@rollup/pluginutils': 5.1.4(rollup@4.34.8)
......@@ -600,6 +655,10 @@ snapshots:
'@types/estree@1.0.6': {}
'@types/json-schema@7.0.15': {}
'@types/lodash@4.17.15': {}
'@types/node@22.13.4':
dependencies:
undici-types: 6.20.0
......@@ -622,6 +681,8 @@ snapshots:
dependencies:
color-convert: 2.0.1
argparse@2.0.1: {}
async@3.2.6: {}
bytes-iec@3.1.1: {}
......@@ -704,8 +765,14 @@ snapshots:
dependencies:
hasown: 2.0.2
is-extglob@2.1.1: {}
is-fullwidth-code-point@3.0.0: {}
is-glob@4.0.3:
dependencies:
is-extglob: 2.1.1
is-module@1.0.0: {}
is-reference@1.2.1:
......@@ -716,10 +783,28 @@ snapshots:
jiti@2.4.2: {}
js-yaml@4.1.0:
dependencies:
argparse: 2.0.1
json-schema-to-typescript@15.0.4:
dependencies:
'@apidevtools/json-schema-ref-parser': 11.9.1
'@types/json-schema': 7.0.15
'@types/lodash': 4.17.15
is-glob: 4.0.3
js-yaml: 4.1.0
lodash: 4.17.21
minimist: 1.2.8
prettier: 3.5.1
tinyglobby: 0.2.10
kuler@2.0.0: {}
lilconfig@3.1.3: {}
lodash@4.17.21: {}
logform@2.7.0:
dependencies:
'@colors/colors': 1.6.0
......@@ -733,6 +818,8 @@ snapshots:
dependencies:
'@jridgewell/sourcemap-codec': 1.5.0
minimist@1.2.8: {}
ms@2.1.3: {}
nanospinner@1.2.2:
......@@ -749,6 +836,8 @@ snapshots:
picomatch@4.0.2: {}
prettier@3.5.1: {}
readable-stream@3.6.2:
dependencies:
inherits: 2.0.4
......
......@@ -8,5 +8,6 @@ export enum EXIT_CODES {
PATH_ENV_NOT_SET = 7,
CHILD_PROCESS_COMMAND_ERROR = 8,
NEW_CONTEXT_EVAL_ERROR = 9,
UNKNOWN_PACKAGE_MANAGER = 10
UNKNOWN_PACKAGE_MANAGER = 10,
CONFIG_PARSE_ERROR = 11
}
#!/usr/bin/env node
// import { isAbsolute, normalize, join } from "node:path";
import { isAbsolute, normalize, join } from "node:path";
import { parseOptions }from "./parse-args.js";
import { checkOS } from "./stages/check-os.js";
import { checkNodeVersion, checkPnpmVersion } from "./stages/check-node-version.js";
import { logger } from "./utils/logger.js";
import { validateConfig } from "./utils/parse-app-config.js";
const argv = await parseOptions();
if (argv.verbose)
logger.level = 'verbose';
// Create absolute path to project root
const projectRoot = process.env.COMB_PROJECT_ROOT ? process.env.COMB_PROJECT_ROOT : (isAbsolute(argv.projectRoot) ? argv.projectRoot : normalize(join(process.cwd(), argv.projectRoot)));
const config = validateConfig(isAbsolute(argv.config) ? argv.config : normalize(join(projectRoot, argv.config)));
// First check the OS and Node.js and pnpm versions
checkOS();
checkNodeVersion();
checkPnpmVersion();
// Create absolute path to project root
// const projectRoot = isAbsolute(argv.projectRoot) ? argv.projectRoot : normalize(join(process.cwd(), argv.projectRoot));
if (config.useGitlabPackageRegistry) {
logger.info('🍱 Ensuring GitLab package registry applied for @hiveio-scoped packages');
// TODO: Implement updating .npmrc with GitLab package registry
}
import yargs from "yargs";
import { hideBin }from "yargs/helpers";
import { DEFAULT_COMB_CONFIG_FILENAME } from "./utils/parse-app-config.js";
export const parseOptions = () => yargs(hideBin(process.argv))
.option("project-root", {
alias: "P",
type: "string",
description: "Project root directory. Defaults to the CWD (current working directory) when not provided. Used to locate your project files and main package.json entry",
description: "Project root directory. Defaults to the CWD (current working directory) when not provided. "
+ "Used to locate your project files and main package.json entry. You can also set it via the COMB_PROJECT_ROOT environment variable.",
default: "."
})
.option("config", {
alias: "c",
type: "string",
description: "Config file to use. Defaults to comb.config.json in the project root directory.",
default: DEFAULT_COMB_CONFIG_FILENAME
})
.option("verbose", {
alias: "v",
type: "boolean",
......
export const iterate = <T extends Record<string, any>>(source: T, target: T): T => {
if (typeof target !== "object")
return source;
for(const itKey in (target as T)) {
if(typeof target[itKey] !== "object") {
source[itKey] = target[itKey] as any;
continue;
}
if ("params" in target[itKey])
source[itKey] = target[itKey] as any;
else {
if (source[itKey] === undefined)
source[itKey] = {} as any;
iterate(source[itKey] as any, target[itKey]);
}
}
return source;
};
import ourConfigSchema from "../../config-schema.json" with { type: "json" };
import Ajv from "ajv";
import { existsSync, readFileSync } from 'node:fs';
import { logger } from "./logger.js";
import { EXIT_CODES } from "../exit-codes.js";
import type { HiveCombPluginConfiguration } from "../../dist/config.js";
import { iterate } from "./iterate.js";
export const DEFAULT_COMB_CONFIG_FILENAME = 'comb.config.json';
export const DEFAULT_CONFIGURATION: HiveCombPluginConfiguration = {
useGitlabPackageRegistry: true
};
export const validateConfig = (otherConfigPath: string): HiveCombPluginConfiguration => {
try {
const source = structuredClone(DEFAULT_CONFIGURATION);
if (!existsSync(otherConfigPath))
return source;
const data = JSON.parse(readFileSync(otherConfigPath, 'utf8'));
const ajv = new Ajv();
const validate = ajv.compile(ourConfigSchema);
const valid = validate(data);
if (!valid) {
logger.error(`❌ Error parsing config file: ${validate.errors!.length} validation errors found: "${validate.errors!.map(error => error.message!).join('", "')}" 🔧`);
process.exit(EXIT_CODES.CONFIG_PARSE_ERROR);
}
return iterate(source, data);
} catch (error) {
logger.error(`❌ Error parsing config file: ${error instanceof Error ? error.message : error} 🔧`);
process.exit(EXIT_CODES.CONFIG_PARSE_ERROR);
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment