From 9beff06cc14ad7d1e653b3c9d0a330cdb09a7780 Mon Sep 17 00:00:00 2001 From: mohiit1502 Date: Sat, 5 Oct 2024 22:43:27 +0530 Subject: [PATCH] Errors removed, exports optimized --- build-tools/build.sh | 12 +++++ build-tools/generate-module.js | 33 +++++++++++++ build-tools/post-processor.js | 23 ++++++++++ package-lock.json | 12 ++--- package.json | 9 ++-- publish-local.sh | 16 +++++++ publish.sh | 10 +++- src/endpoints.ts | 84 ++++++++++++++++++---------------- vite.config.ts | 2 +- 9 files changed, 150 insertions(+), 51 deletions(-) create mode 100755 build-tools/build.sh create mode 100644 build-tools/generate-module.js create mode 100644 build-tools/post-processor.js create mode 100755 publish-local.sh diff --git a/build-tools/build.sh b/build-tools/build.sh new file mode 100755 index 0000000..0daf942 --- /dev/null +++ b/build-tools/build.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Get the directory of the current script +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" + +rm -rf build +npx tsc +vite build + +# Run Post processors: Update style imports in .js files, create component modules +node "$SCRIPT_DIR/post-processor.js" build/cjs +node "$SCRIPT_DIR/post-processor.js" build/es diff --git a/build-tools/generate-module.js b/build-tools/generate-module.js new file mode 100644 index 0000000..28d5c3a --- /dev/null +++ b/build-tools/generate-module.js @@ -0,0 +1,33 @@ +import { promises as fs } from "fs" +import { dirname, resolve } from "path" +import { fileURLToPath } from "url" + +const __filename = fileURLToPath(import.meta.url) +const __dirname = dirname(__filename) + +const exclusions = ["index.js"] + +async function generateModule(fileName) { + if (!exclusions.includes(fileName)) { + const dir = fileName.slice(0, -3) + const name = `@armco/configs/${dir}` + const packageJsonContent = { + name, + main: `../cjs/${dir}.js`, + module: `../es/${dir}.js`, + types: `../types/${dir}.d.ts`, + } + const dirPath = resolve(__dirname, `../build/${dir}`) + try { + await fs.mkdir(dirPath, { recursive: true }) + await fs.writeFile( + resolve(dirPath, "package.json"), + JSON.stringify(packageJsonContent, null, 2), + ) + } catch (error) { + console.error(`Error processing directory ${dirPath}:`, error) + } + } +} + +export default generateModule diff --git a/build-tools/post-processor.js b/build-tools/post-processor.js new file mode 100644 index 0000000..53c993f --- /dev/null +++ b/build-tools/post-processor.js @@ -0,0 +1,23 @@ +import { readdir } from "fs/promises" +import generateModule from "./generate-module.js" + +async function postProcessor(dir) { + try { + const files = await readdir(dir) + await Promise.all( + files.map(async (file) => { + await generateModule(file, dir) + }), + ) + } catch (error) { + console.error(`Error processing directory ${dir}:`, error) + } +} + +const targetDir = process.argv[2] +if (targetDir) { + postProcessor(targetDir) +} else { + console.error("Please provide the build directory to run post processor on.") + process.exit(1) +} diff --git a/package-lock.json b/package-lock.json index 1595eb3..d9177d9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,15 +1,15 @@ { "name": "@armco/configs", - "version": "0.0.3", + "version": "0.0.7", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@armco/configs", - "version": "0.0.3", + "version": "0.0.7", "license": "ISC", "dependencies": { - "@armco/types": "^0.0.9", + "@armco/types": "^0.0.10", "uuid": "^10.0.0" }, "devDependencies": { @@ -28,9 +28,9 @@ } }, "node_modules/@armco/types": { - "version": "0.0.9", - "resolved": "https://registry.npmjs.org/@armco/types/-/types-0.0.9.tgz", - "integrity": "sha512-RLCt0Q20Nm52sTUcKVhjzeq7sbojgryEeqqChATOW6yAkWCL5NrQ2RLXpK4veePz1RLdu1eTsWVy5fMGe85qQw==", + "version": "0.0.10", + "resolved": "https://registry.npmjs.org/@armco/types/-/types-0.0.10.tgz", + "integrity": "sha512-PKmehb5PsX6o6b3yaItCyDJxYy5nyXBduONnWv6slQwBMareFquGUcrCORPQhvnVLprCTs5aIZyPerZdjVuuxg==", "license": "MIT" }, "node_modules/@babel/helper-string-parser": { diff --git a/package.json b/package.json index 2513045..af21380 100644 --- a/package.json +++ b/package.json @@ -1,18 +1,19 @@ { "name": "@armco/configs", - "version": "0.0.3", + "version": "0.0.7", "type": "module", "main": "build/cjs/index.js", "module": "build/es/index.js", "types": "build/types/index.d.ts", "scripts": { - "build": "rm -rf build && tsc && vite build", + "build": "./build-tools/build.sh", "format": "prettier --write .", "lint": "eslint .", - "publish:sh": "./publish.sh" + "publish:sh": "./publish.sh", + "publish:local": "./publish-local.sh" }, "dependencies": { - "@armco/types": "^0.0.9", + "@armco/types": "^0.0.10", "uuid": "^10.0.0" }, "devDependencies": { diff --git a/publish-local.sh b/publish-local.sh new file mode 100755 index 0000000..46b66a6 --- /dev/null +++ b/publish-local.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +semver=${1:-patch} + +set -e + +npm run build +cp package.json build/ +sed -i '' -E 's/"build"/"*"/' build/package.json + +sed -i '' 's#"build/cjs/index.js"#"cjs/index.js"#' build/package.json +sed -i '' 's#"build/es/index.js"#"es/index.js"#' build/package.json +sed -i '' 's#"build/types/index.d.ts"#"types/index.d.ts"#' build/package.json + +cd build +npm pack --pack-destination ~/__Projects__/Common \ No newline at end of file diff --git a/publish.sh b/publish.sh index a0d2fb4..94621ea 100755 --- a/publish.sh +++ b/publish.sh @@ -2,7 +2,15 @@ semver=${1:-patch} -npm run build set -e npm --no-git-tag-version version ${semver} +npm run build +cp package.json build/ +sed -i '' -E 's/"build"/"*"/' build/package.json + +sed -i '' 's#"build/cjs/index.js"#"cjs/index.js"#' build/package.json +sed -i '' 's#"build/es/index.js"#"es/index.js"#' build/package.json +sed -i '' 's#"build/types/index.d.ts"#"types/index.d.ts"#' build/package.json + +cd build npm publish --access public --loglevel verbose diff --git a/src/endpoints.ts b/src/endpoints.ts index 7315ab8..2b73f3d 100644 --- a/src/endpoints.ts +++ b/src/endpoints.ts @@ -1,49 +1,45 @@ import { ApiConfig, WebConfig } from "@armco/types" -export const API_CONFIG: ApiConfig = { - HOST: { - development: "http://localhost:5000/api", - production: "https://api.armco.tech", - }, - STATIC_HOST: { - development: "http://localhost:5001/api", - production: "https://static.armco.tech", - }, - TASKER: { - development: "http://localhost:5002/api", - production: "https://tasks.armco.tech", - }, - CONFIG: { - development: "http://localhost:5003/api", - production: "https://config.armco.tech", - }, - IAM: { - development: "http://localhost:5004/api", - production: "https://iam.armco.tech", - }, - SEER: { - development: "http://localhost:5005/api", - production: "https://telemetry.armco.tech", - }, +export const HOST = { + development: "http://localhost:5000/api", + production: "https://api.armco.tech", +} +export const STATIC_HOST = { + development: "http://localhost:5001/api", + production: "https://static.armco.tech", +} +export const TASKER = { + development: "http://localhost:5002/api", + production: "https://tasks.armco.tech", +} +export const CONFIG = { + development: "http://localhost:5003/api", + production: "https://config.armco.tech", +} +export const IAM = { + development: "http://localhost:5004/api", + production: "https://iam.armco.tech", +} +export const SEER = { + development: "http://localhost:5005/api", + production: "https://telemetry.armco.tech", } export const ICON_ROOT = `${ - API_CONFIG.STATIC_HOST[process.env.NODE_ENV as "production" | "development"] + STATIC_HOST[process.env.NODE_ENV as "production" | "development"] }/icon` -export const WEB_CONFIG: WebConfig = { - ARMORY: { - development: "http://localhost:7992", - production: "https://armco.tech", - }, - IAM: { - development: "http://localhost:3001", - production: "https://iam.notabuck.com", - }, - FORESEER: { - development: "http://localhost:3002", - production: "https://seer.notabuck.com", - }, +export const ARMORY = { + development: "http://localhost:7992", + production: "https://armco.tech", +} +export const IAMCLIENT = { + development: "http://localhost:3001", + production: "https://iam.notabuck.com", +} +export const FORESEER = { + development: "http://localhost:3002", + production: "https://seer.notabuck.com", } export const ENDPOINTS = { @@ -97,3 +93,13 @@ export const ENDPOINTS = { FETCH: "/", }, } + +export const API_CONFIG: ApiConfig = { + HOST, STATIC_HOST, CONFIG, TASKER, IAM, SEER +} + +export const WEB_CONFIG: WebConfig = { + ARMORY, + IAM: IAMCLIENT, + FORESEER +} \ No newline at end of file diff --git a/vite.config.ts b/vite.config.ts index 898aab0..7cae700 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ }, rollupOptions: { treeshake: true, - external: ["react", "react/jsx-runtime", "react-dom"], + external: ["react", "react/jsx-runtime", "react-dom", "uuid"], output: [ { format: "es",