Skip to content

Commit

Permalink
put node files under /utils
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyan-dfinity committed Sep 11, 2024
1 parent a1013ff commit fea0349
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 17 deletions.
6 changes: 4 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,10 @@ export function App() {
logger.log(`moc version ${MOC_VERSION}`);
logger.log(`base library version ${baseInfo.version}`);
await container.initFiles();
await container.run_cmd("npm", ["install"]);
await container.run_cmd("npm", ["run", "build"]);
await container.run_cmd("npm", ["install"], {
cwd: "utils",
output: false,
});
//await container.run_cmd("node", ["uploadAsset.js", "dist"]);
// fetch code after loading base library
if (hasUrlParams) {
Expand Down
3 changes: 0 additions & 3 deletions src/components/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,9 @@ export function Editor({
try {
const { files, env } = generateNonMotokoFilesToWebContainer(state);
console.log(files);
await container.container!.fs.mkdir("user", { recursive: true });
await container.container!.mount(files, { mountPoint: "user" });
await container.run_cmd("npm", ["install"], { cwd: "user" });
await container.run_cmd("npm", ["run", "build"], { cwd: "user", env });
const read = await container.container!.fs.readdir("/");
console.log(read);
} catch (e) {
logger.log(e.message);
}
Expand Down
27 changes: 15 additions & 12 deletions src/webcontainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Container {
import: "default",
eager: true,
});
const files: FileSystemTree = Object.entries(nodeFiles).reduce(
const utilsFiles: FileSystemTree = Object.entries(nodeFiles).reduce(
(acc, [key, value]) => {
const fileName = key.replace("./node/", "");
acc[fileName] = {
Expand All @@ -35,26 +35,29 @@ export class Container {
},
{},
);
files["etc"] = {
directory: {
hosts: {
file: {
contents: "127.0.0.1 mylocalhost.com",
const files: FileSystemTree = {
utils: {
directory: utilsFiles,
},
user: {
directory: {},
},
etc: {
directory: {
hosts: {
file: {
contents: "127.0.0.1 mylocalhost.com",
},
},
},
},
};
files["index.html"] = {
file: {
contents: "<p>Hello World</p>",
},
};
await this.container!.mount(files);
}

async run_cmd(cmd: string, args: string[], options?: SpawnOptions) {
await this.init();
this.terminal.writeln(`$ ${cmd} ${args.join(" ")}`);
this.terminal.writeln(`/${options?.cwd ?? ""}$ ${cmd} ${args.join(" ")}`);
const installProcess = await this.container!.spawn(cmd, args, options);
installProcess.output.pipeTo(
new WritableStream({
Expand Down

0 comments on commit fea0349

Please sign in to comment.