Import type of package.json

This commit is contained in:
Robert
2023-09-18 15:47:37 +01:00
parent b9367095cf
commit f195e93d91
2 changed files with 5 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ import {
} from "fs-extra";
import { resolve, join } from "path";
import { isDevBuild } from "./dev";
import type * as packageJsonType from "../package.json";
export interface DeployedPackage {
distPath: string;
@@ -46,31 +47,13 @@ async function copyPackage(
);
}
interface packageJson {
name: string;
version: string;
}
async function readPackageJson(packageJsonPath: string): Promise<packageJson> {
const packageJson: packageJson = JSON.parse(
await readFile(packageJsonPath, "utf8"),
);
if (!packageJson.name) {
throw new Error(`${packageJsonPath} is missing the 'name' field`);
}
if (!packageJson.version) {
throw new Error(`${packageJsonPath} is missing the 'version' field`);
}
return packageJson;
}
export async function deployPackage(
packageJsonPath: string,
): Promise<DeployedPackage> {
try {
const packageJson = await readPackageJson(packageJsonPath);
const packageJson: typeof packageJsonType = JSON.parse(
await readFile(packageJsonPath, "utf8"),
);
const distDir = join(__dirname, "../../../dist");
await mkdirs(distDir);

View File

@@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "."
"rootDir": ".."
},
"include": ["*.ts"]
}