Import type of package.json
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "../tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"rootDir": "."
|
||||
"rootDir": ".."
|
||||
},
|
||||
"include": ["*.ts"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user