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

Can't start a node. spawn just hangs #235

Closed
m00nwtchr opened this issue May 1, 2018 · 1 comment
Closed

Can't start a node. spawn just hangs #235

m00nwtchr opened this issue May 1, 2018 · 1 comment

Comments

@m00nwtchr
Copy link

m00nwtchr commented May 1, 2018

I have this code:

const pug = require("pug");
const IPFSFactory = require("ipfsd-ctl");
const ncp = require("ncp").ncp;

const fs = require("fs");
const path = require("path");

const src = "app/web_app/src";
const out = "build/web";

let ipfsd = IPFSFactory.create();

const walkSync = (dir, filelist = []) => {
	fs.readdirSync(dir).forEach(file => {
  
		filelist = fs.statSync(path.join(dir, file)).isDirectory()
			? walkSync(path.join(dir, file), filelist)
			: filelist.concat(path.join(dir, file));
  
	});
	return filelist;
};

let rmdirSync = (path) => {
	if (fs.existsSync(path)) {
		fs.readdirSync(path).forEach((file) => {
			let curPath = path + "/" + file;
			if (fs.lstatSync(curPath).isDirectory()) { // recurse
				rmdirSync(curPath);
			} else { // delete file
				fs.unlinkSync(curPath);
			}
		});
		fs.rmdirSync(path);
	}
};

if (fs.existsSync(out)) {
	console.log("Prebuild cleanup");
	rmdirSync(out);
}
console.log("Build start");
fs.mkdirSync(out);
fs.readdir(src, (err, files) => {
	files.forEach(file => {
		file = src+"/"+file;
		let p = path.parse(file);
		if (file.match(".*\\.pug")) {
			console.log("Rendering "+file);
			let html = pug.renderFile(file);

			console.log("Writing "+out+"/"+p.name+".html");
			fs.writeFileSync(out+"/"+p.name+".html", html);
		} else {
			console.log("Copying "+file+" to "+out+"/"+p.base);
			fs.lstat(file, (err, stat) => {
				if (stat.isDirectory()) {
					ncp(file, out+"/"+p.base);
				} else {
					fs.copyFileSync(file, out+"/"+p.base);
				}
			});
		}
	});

	console.log("Build Done!");
	console.log("Deploying to IPFS");
	console.log("Starting a IPFS node");
	ipfsd.spawn((err, ipfsNode) => {
		console.log("Starting the IPFS daemon");
		ipfsNode.start((err, ipfs) => {
			console.log("The daemon is up and running!");
			console.log("Adding files to IPFS...");
			const stream = ipfs.files.addReadableStream();

			stream.on("data", function (file) {
				console.log(file.path);
				console.log(file.hash);
			});

			fs.walkSync(out, (err, files) => {
				console.log(files.lenght+" files to add");
				files.forEach(file => {
					let p = path.parse(file);
					stream.write({
						path: "/"+file.substring(out.length),
						content: fs.readFileSync(file)
					});
				});
			});
			stream.end();
		});
	});
});

It's a build script meant to render all my pug files and then publish the web front end to IPFS.
but node seems to just freeze on ipfsd.spawn()
Output of the script:

Prebuild cleanup
Build start
Copying app/web_app/src/css to build/web/css
Rendering app/web_app/src/index.pug
Writing build/web/index.html
Copying app/web_app/src/js to build/web/js
Build Done!
Deploying to IPFS
Starting an IPFS node

It is worth noting that this happens only in the build script. My electron app doesn't freeze like that

@m00nwtchr
Copy link
Author

This is probably the same thing as #223 cause my node version is v10.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant