Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli bash replaced with node #285

Merged
merged 2 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions lib/cli/cli.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/cli/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import fs from "fs/promises";
import fs from "fs";
import path, { basename, dirname } from "path";

import { nodeResolve } from "@rollup/plugin-node-resolve";
Expand Down Expand Up @@ -64,9 +64,11 @@ export async function buildCom(
}

signale.await(`Creating ${TARGET_DIR} directory...`);
await executeCommand(`mkdir -p ${TARGET_DIR}`, verbose);
if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR, {});
}

signal.await(`Validating ${source} contract...`);
signal.await(`Validatig ${source} contract...`);
if (!await validateContract(source, verbose)) {
process.exit(1);
}
Expand Down Expand Up @@ -160,7 +162,7 @@ async function createMethodsHeaderFile(rollupTarget: string, verbose = false) {
""
);

await fs.writeFile(`${buildPath}/methods.h`, methods);
fs.writeFileSync(`${buildPath}/methods.h`, methods);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason to prefer writeFileSync over await writeFile?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they are the same, the only reason is consistency.
The main reason to move from bash to node scripts is Multiplatform (Windows) support.

}

async function createWasmContract(
Expand All @@ -184,11 +186,9 @@ async function createWasmContract(
const LIBS = `-lm`;

// copying builder.c file to the build folder
await executeCommand(
`cp ${ORIGINAL_BUILDER_PATH} ${NEW_BUILDER_PATH}`,
verbose
);
await executeCommand(`mv ${qjscTarget} build/code.h`, verbose);
fs.cpSync(ORIGINAL_BUILDER_PATH, NEW_BUILDER_PATH);

fs.renameSync(qjscTarget, "build/code.h");

await executeCommand(
`${CC} --target=wasm32-wasi -nostartfiles -Oz -flto ${DEFS} ${INCLUDES} ${SOURCES} ${LIBS} -Wl,--no-entry -Wl,--allow-undefined -Wl,-z,stack-size=${256 * 1024
Expand Down