M package.json => package.json +1 -1
@@ 1,6 1,6 @@
{
"name": "@0xc/dialogflow-as-code",
- "version": "3.0.0-beta1",
+ "version": "3.0.0-beta2",
"main": "dist/index.js",
"scripts": {
"convert": "TS_NODE_FILES=true ts-node src/converter/cli.ts",
D src/.npmignore => src/.npmignore +0 -0
M src/converter/converter/templates/import-template.ts => src/converter/converter/templates/import-template.ts +2 -2
@@ 1,9 1,9 @@
import { VariableNamer } from "../variable-namer";
-import * as manifest from "../../../../package.json";
+import { loadPackageJson } from "../../../util/load-package-json";
export class ImportTemplate extends VariableNamer {
private _imports: { [key: string]: Set<string> } = {};
- private package: string = manifest.name;
+ private package: string = loadPackageJson().name;
protected templateImports(): string {
const importList: string[] = [];
A src/util/load-package-json.ts => src/util/load-package-json.ts +31 -0
@@ 0,0 1,31 @@
+/**
+ * Lazily loads the package manifest from package.json, resolving to
+ * default values to be used in the case an error occurs. In some cases
+ * these may not be necessary so requiring a filesystem read on
+ * start-up is likely too greedy.
+ */
+
+import { readFileSync } from "fs";
+import { join } from "path";
+
+const defaultManifest = { name: "@0xc/dialogflow-as-code", version: "‾\\_⪽⪾_/‾" };
+let manifest: PackageManifest | null = null;
+
+export function loadPackageJson(): PackageManifest {
+ if (manifest) {
+ return manifest;
+ }
+
+ try {
+ manifest = JSON.parse(readFileSync(join(__dirname, "..", "..", "package.json"), { encoding: "utf8" }))
+ } finally {
+ manifest = manifest ? manifest : defaultManifest;
+ }
+
+ return manifest;
+}
+
+export interface PackageManifest {
+ name: string;
+ version: string;
+}<
\ No newline at end of file
M src/util/version.ts => src/util/version.ts +4 -6
@@ 1,7 1,5 @@
-export function getVersion() {
- let version: string | undefined;
- try {
- version = require("../../package.json").version;
- } catch {}
- return version ? version : "‾\\_⪽⪾_/‾";
+import { loadPackageJson } from "./load-package-json";
+
+export function getVersion(): string {
+ return loadPackageJson().version;
}
M tsconfig.json => tsconfig.json +3 -4
@@ 9,16 9,15 @@
"lib": ["es2015", "es2017"],
"module": "commonjs",
"noUnusedLocals": true,
- "outDir": "./dist",
+ "outDir": "dist",
"removeComments": true,
"resolveJsonModule": true,
"sourceMap": true,
"strict": true,
- "target": "es2017",
- "incremental": true
+ "target": "es2017"
},
"include": [
- "./src"
+ "src/**/*.ts"
],
"exclude": ["node_modules", "!node_modules/@types", "dist"]
}