Skip to content

Commit

Permalink
fix error when running setup and build
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebarkmin committed May 20, 2024
1 parent 4a3a21f commit 88d13ce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
5 changes: 5 additions & 0 deletions .changeset/fresh-lies-joke.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"hyperbook": patch
---

fix error when running setup and build
22 changes: 11 additions & 11 deletions packages/hyperbook/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { readHyperbook } from "./helpers/read-hyperbook";
import { hyperproject, vfile } from "@hyperbook/fs";
import { runArchive } from "./archive";
import { makeDir } from "./helpers/make-dir";
import rimraf from "rimraf";
import { rimraf } from "rimraf";
import { Link, Hyperproject } from "@hyperbook/types";
import { makeEnv } from "./helpers/make-env";

export async function runBuildProject(
project: Hyperproject,
rootProject: Hyperproject,
out?: string
out?: string,
): Promise<void> {
const name = hyperproject.getName(project);
if (project.type === "book") {
Expand All @@ -24,7 +24,7 @@ export async function runBuildProject(
} else {
if (!out) {
out = project.src;
rimraf.sync(path.join(out, ".hyperbook", "out"));
await rimraf(path.join(out, ".hyperbook", "out"));
}
console.log(`${chalk.blue(`[${name}]`)} Building Library.`);
for (const p of project.projects) {
Expand All @@ -38,7 +38,7 @@ async function runBuild(
rootProject: Hyperproject,
basePath?: string,
prefix?: string,
out?: string
out?: string,
): Promise<void> {
const setup = isSetup(root, rootProject);
if (!setup) {
Expand Down Expand Up @@ -73,7 +73,7 @@ module.exports = {
ignoreBuildErrors: true,
}
}
`
`,
);

vfile.clean(root);
Expand All @@ -98,12 +98,12 @@ module.exports = {
path.join(root, ".hyperbook", "hyperbook.json"),
{
force: true,
}
},
);

fs.writeFileSync(
path.join(root, ".hyperbook", "hyperbook.json"),
JSON.stringify(hyperbookJson, null, 2)
JSON.stringify(hyperbookJson, null, 2),
);

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -155,8 +155,8 @@ module.exports = {
if (!out) {
process.stdout.write(
`${chalk.green(
`[${prefix}]`
)} Export successful. Files written to ${normalOut}.\n`
`[${prefix}]`,
)} Export successful. Files written to ${normalOut}.\n`,
);
resolve();
} else {
Expand All @@ -166,8 +166,8 @@ module.exports = {
fs.cpSync(normalOut, newOut, { recursive: true, force: true });
process.stdout.write(
`${chalk.green(
`[${prefix}]`
)} Export successful. Files written to ${newOut}.\n`
`[${prefix}]`,
)} Export successful. Files written to ${newOut}.\n`,
);
resolve();
})
Expand Down
4 changes: 2 additions & 2 deletions packages/hyperbook/helpers/git.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import { execSync } from "child_process";
import path from "path";
import rimraf from "rimraf";
import { sync } from "rimraf";

function isInGitRepository(): boolean {
try {
Expand Down Expand Up @@ -40,7 +40,7 @@ export function tryGitInit(root: string): boolean {
} catch (e) {
if (didInit) {
try {
rimraf.sync(path.join(root, ".git"));
sync(path.join(root, ".git"));
} catch (_) {}
}
return false;
Expand Down
32 changes: 16 additions & 16 deletions packages/hyperbook/setup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import rimraf from "rimraf";
import { rimraf } from "rimraf";
import chalk from "chalk";
import cpy from "cpy";
import fs from "fs/promises";
Expand All @@ -12,14 +12,14 @@ import { Hyperproject } from "@hyperbook/types";

export async function runSetupProject(
project: Hyperproject,
rootProject?: Hyperproject
rootProject?: Hyperproject,
) {
const name = hyperproject.getName(project);
console.log(`${chalk.blue(`[${name}]`)} Setup Project.`);
const projectRoot = path.join(project.src, ".hyperbook");
const root = path.join(rootProject?.src || "", ".hyperbook");

rimraf.sync(projectRoot);
await rimraf(projectRoot);

const filesPath = path.join(__dirname, "templates");
await makeDir(projectRoot);
Expand All @@ -38,8 +38,8 @@ export async function runSetupProject(
"..",
"platforms",
"web",
"package.json"
)
"package.json",
),
)
.then((f) => JSON.parse(f.toString()));

Expand All @@ -55,8 +55,8 @@ export async function runSetupProject(
},
},
null,
2
)
2,
),
);
} else {
if (!rootProject) {
Expand All @@ -65,15 +65,15 @@ export async function runSetupProject(
} else {
await makeSymlink(
path.join(root, "node_modules"),
path.join(projectRoot, "node_modules")
path.join(projectRoot, "node_modules"),
);
}
}

if (project.type === "library") {
await makeSymlink(
path.join(project.src, "hyperlibrary.json"),
path.join(projectRoot, "hyperlibrary.json")
path.join(projectRoot, "hyperlibrary.json"),
);

for (const p of project.projects) {
Expand All @@ -85,30 +85,30 @@ export async function runSetupProject(

await makeSymlink(
path.join(project.src, "archives"),
path.join(projectRoot, "archives")
path.join(projectRoot, "archives"),
);
await makeSymlink(
path.join(project.src, "book"),
path.join(projectRoot, "book")
path.join(projectRoot, "book"),
);
await makeSymlink(
path.join(project.src, "glossary"),
path.join(projectRoot, "glossary")
path.join(projectRoot, "glossary"),
);
await makeSymlink(
path.join(project.src, "snippets"),
path.join(projectRoot, "snippets")
path.join(projectRoot, "snippets"),
);
await makeSymlink(
path.join(project.src, "templates"),
path.join(projectRoot, "templates")
path.join(projectRoot, "templates"),
);
await makeSymlink(
path.join(project.src, "public"),
path.join(projectRoot, "public")
path.join(projectRoot, "public"),
);
await makeSymlink(
path.join(project.src, "hyperbook.json"),
path.join(projectRoot, "hyperbook.json")
path.join(projectRoot, "hyperbook.json"),
);
}

0 comments on commit 88d13ce

Please sign in to comment.