diff --git a/Makefile b/Makefile index 08a3ec5..39815c3 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,8 @@ lib/test/output.ts: lib/test/makeOutput.ts scripts/oldSpecToBuilder.ts npm run buildOutput buildOutput: lib/test/output.ts fmt - echo 'done' + echo 'done' + bundle: clean $(TS_FILES) package.json .FORCE node_modules test fmt npx tsc diff --git a/lib/test/makeOutput.ts b/lib/test/makeOutput.ts index 2364d4e..b2e2447 100644 --- a/lib/test/makeOutput.ts +++ b/lib/test/makeOutput.ts @@ -1,6 +1,6 @@ -import { writeConvertedFileFromOld } from "../../scripts/oldSpecToBuilder" +import { oldSpecToBuilder } from "../../scripts/oldSpecToBuilder" -writeConvertedFileFromOld( +oldSpecToBuilder( "./lib/test/output.ts", // Make the location { // Put the config here diff --git a/lib/test/output.test.ts b/lib/test/output.test.ts index 1e629b2..b25d81e 100644 --- a/lib/test/output.test.ts +++ b/lib/test/output.test.ts @@ -7,6 +7,7 @@ import { import { deepMerge } from "../util" import { InputSpec, matchInputSpec } from "./output" import * as _I from "../index" +import { camelCase } from "../../scripts/oldSpecToBuilder" export type IfEquals = (() => G extends T ? 1 @@ -127,3 +128,24 @@ describe("Inputs", () => { ).toThrowError() }) }) + +describe("camelCase", () => { + test("'EquipmentClass name'", () => { + expect(camelCase("EquipmentClass name")).toEqual("equipmentClassName") + }) + test("'Equipment className'", () => { + expect(camelCase("Equipment className")).toEqual("equipmentClassName") + }) + test("'equipment class name'", () => { + expect(camelCase("equipment class name")).toEqual("equipmentClassName") + }) + test("'Equipment Class Name'", () => { + expect(camelCase("Equipment Class Name")).toEqual("equipmentClassName") + }) + test("'hyphen-name-format'", () => { + expect(camelCase("hyphen-name-format")).toEqual("hyphenNameFormat") + }) + test("'underscore_name_format'", () => { + expect(camelCase("underscore_name_format")).toEqual("underscoreNameFormat") + }) +}) diff --git a/package-lock.json b/package-lock.json index 4719108..22ee7f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,14 +10,11 @@ "license": "MIT", "dependencies": { "@iarna/toml": "^2.2.5", - "deepmerge": "^4.3.1", - "lodash": "^4.17.21", "ts-matches": "^5.4.1", "yaml": "^2.2.1" }, "devDependencies": { "@types/jest": "^29.4.0", - "@types/lodash": "^4.14.191", "jest": "^29.4.3", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", @@ -1529,12 +1526,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "node_modules/@types/lodash": { - "version": "4.14.192", - "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.14.192.tgz", - "integrity": "sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==", - "dev": true - }, "node_modules/@types/node": { "version": "18.15.10", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.10.tgz", @@ -2252,6 +2243,7 @@ "version": "4.3.1", "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.3.1.tgz", "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", + "dev": true, "engines": { "node": ">=0.10.0" } @@ -3572,11 +3564,6 @@ "node": ">=8" } }, - "node_modules/lodash": { - "version": "4.17.21", - "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", - "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==" - }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", diff --git a/package.json b/package.json index e5dc90b..748aa3c 100644 --- a/package.json +++ b/package.json @@ -21,8 +21,6 @@ "homepage": "https://github.com/Start9Labs/start-sdk#readme", "dependencies": { "@iarna/toml": "^2.2.5", - "deepmerge": "^4.3.1", - "lodash": "^4.17.21", "ts-matches": "^5.4.1", "yaml": "^2.2.1" }, @@ -34,7 +32,6 @@ }, "devDependencies": { "@types/jest": "^29.4.0", - "@types/lodash": "^4.14.191", "jest": "^29.4.3", "ts-jest": "^29.0.5", "ts-node": "^10.9.1", diff --git a/scripts/oldSpecToBuilder.ts b/scripts/oldSpecToBuilder.ts index 609be53..e39deb9 100644 --- a/scripts/oldSpecToBuilder.ts +++ b/scripts/oldSpecToBuilder.ts @@ -1,11 +1,19 @@ -import camelCase from "lodash/camelCase" import * as fs from "fs" -import { string } from "ts-matches" -export async function writeConvertedFileFromOld( +export function camelCase(value: string) { + return value.replace( + /^([A-Z])|[\s-_](\w)/g, + function (match, p1, p2, offset) { + if (p2) return p2.toUpperCase() + return p1.toLowerCase() + }, + ) +} + +export async function oldSpecToBuilder( file: string, inputData: Promise | any, - options: Parameters[1], + options?: Parameters[1], ) { await fs.writeFile( file, @@ -14,6 +22,10 @@ export async function writeConvertedFileFromOld( ) } +function isString(x: unknown): x is string { + return typeof x === "string" +} + export default async function makeFileContentFromOld( inputData: Promise | any, { startSdk = "start-sdk", nested = true } = {}, @@ -145,7 +157,7 @@ export default async function makeFileContentFromOld( ]) const values = Object.fromEntries( Array.from(allValueNames) - .filter(string.test) + .filter(isString) .map((key) => [key, value?.spec?.["value-names"]?.[key] || key]), ) return `Value.select(${JSON.stringify( @@ -264,7 +276,7 @@ export default async function makeFileContentFromOld( ) const values = Object.fromEntries( Array.from(allValueNames) - .filter(string.test) + .filter(isString) .map((key: string) => [ key, value?.spec?.["value-names"]?.[key] || key, @@ -383,3 +395,9 @@ function rangeToTodoComment(range: string | undefined) { if (!range) return "" return `/* TODO: Convert range for this value (${range})*/` } + +// oldSpecToBuilder( +// "./config.ts", +// // Put config here +// {}, +// )