Import type of package.json
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
|||||||
} from "fs-extra";
|
} from "fs-extra";
|
||||||
import { resolve, join } from "path";
|
import { resolve, join } from "path";
|
||||||
import { isDevBuild } from "./dev";
|
import { isDevBuild } from "./dev";
|
||||||
|
import type * as packageJsonType from "../package.json";
|
||||||
|
|
||||||
export interface DeployedPackage {
|
export interface DeployedPackage {
|
||||||
distPath: string;
|
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(
|
export async function deployPackage(
|
||||||
packageJsonPath: string,
|
packageJsonPath: string,
|
||||||
): Promise<DeployedPackage> {
|
): Promise<DeployedPackage> {
|
||||||
try {
|
try {
|
||||||
const packageJson = await readPackageJson(packageJsonPath);
|
const packageJson: typeof packageJsonType = JSON.parse(
|
||||||
|
await readFile(packageJsonPath, "utf8"),
|
||||||
|
);
|
||||||
|
|
||||||
const distDir = join(__dirname, "../../../dist");
|
const distDir = join(__dirname, "../../../dist");
|
||||||
await mkdirs(distDir);
|
await mkdirs(distDir);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"$schema": "https://json.schemastore.org/tsconfig",
|
"$schema": "https://json.schemastore.org/tsconfig",
|
||||||
"extends": "../tsconfig.json",
|
"extends": "../tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"rootDir": "."
|
"rootDir": ".."
|
||||||
},
|
},
|
||||||
"include": ["*.ts"]
|
"include": ["*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user