Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Commit

Permalink
fix: build now start from scratch dist folder
Browse files Browse the repository at this point in the history
  • Loading branch information
lachrist committed Nov 17, 2021
1 parent b89d63a commit 2520cf7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/component/index.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import { writeEntryPointAsync } from "./static.mjs";

const generateWriteAsync = (branch) => async (component, blueprint) => {
Expand Down
26 changes: 23 additions & 3 deletions build/schema/index.mjs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { readFileSync, writeFileSync } from "fs";
import { readFile as readFileAsync, writeFile as writeFileAsync, mkdir as mkdirAsync } from "fs/promises";
import { fileURLToPath } from "url";
import { dirname as getDirname } from "path";
import YAML from "yaml";
import Ajv from "ajv";
import GenerateStandaloneCode from "ajv/dist/standalone/index.js";
import { spawn } from "child_process";

const { default: generateStandaloneCode } = GenerateStandaloneCode;

const { stringify: stringifyJSON } = JSON;
Expand All @@ -12,14 +14,32 @@ const { parse: parseYAML } = YAML;
const __filename = fileURLToPath(import.meta.url);
const __dirname = getDirname(__filename);

const schema = parseYAML(readFileSync(`${__dirname}/schema.yml`, "utf8"));
await new Promise((resolve, reject) => {
const child = spawn("rm", ["-rf", "./dist"], {stdio:"inherit"});
child.on("error", reject);
child.on("exit", (code, signal) => {
if (signal !== null) {
reject(new Error("Removing dist directory killed"));
} else if (code !== 0) {
reject(new Error("Failed to remove dist directory"));
} else {
resolve(undefined);
}
});
});

await mkdirAsync("./dist");

await mkdirAsync("./dist/node");

const schema = parseYAML(await readFileAsync(`${__dirname}/schema.yml`, "utf8"));

const ajv = new Ajv({ code: { source: true }, verbose: true });
// {code:{source:true}, verbose:true}
ajv.addSchema(schema);
generateStandaloneCode(ajv);

writeFileSync(
await writeFileAsync(
`${__dirname}/../../dist/schema.mjs`,
`export const schema = ${stringifyJSON(schema, null, 2)};`,
"utf8",
Expand Down

0 comments on commit 2520cf7

Please sign in to comment.