Errors removed, exports optimized

This commit is contained in:
2024-10-05 22:43:27 +05:30
parent 19298dba53
commit 9beff06cc1
9 changed files with 150 additions and 51 deletions

12
build-tools/build.sh Executable file
View File

@@ -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

View File

@@ -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

View File

@@ -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)
}

12
package-lock.json generated
View File

@@ -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": {

View File

@@ -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": {

16
publish-local.sh Executable file
View File

@@ -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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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",