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

fixed some windows compatibility issues #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
22 changes: 13 additions & 9 deletions src/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import glob from 'glob';
import toml from 'toml';
import tomlify from 'tomlify-j0.4';

import { CONFIG_FILE, README_FILE, README_TARGET, DOXITYRC_FILE } from '../constants';
import { CONFIG_FILE, README_FILE, README_TARGET, DOXITYRC_FILE, DEFAULT_PAGES_DIR, DEFAULT_SRC_DIR } from '../constants';

import solc from './solc';
import parseAbi from './parse-abi';
Expand All @@ -31,7 +31,7 @@ function compile({ whitelist, contracts, output, target, version }) {
// let address;
// if (interaction) {
// try {
// const instance = require(`${process.env.PWD}/build/contracts/${contractName}.sol.js`);
// const instance = require(`${process.cwd()}/build/contracts/${contractName}.sol.js`);
// address = instance.all_networks[interaction.network].address;
// } catch (e) { /* do noithing */ }
// }
Expand All @@ -40,7 +40,7 @@ function compile({ whitelist, contracts, output, target, version }) {
const data = {
author,
title,
fileName: fileName.replace(process.env.PWD, ''),
fileName: fileName.replace(process.cwd(), ''),
// address,
name: contractName,
// only pass these if they are whitelisted
Expand All @@ -56,7 +56,7 @@ function compile({ whitelist, contracts, output, target, version }) {
// TODO find in a better way?
let pkgConfig = {};
try {
pkgConfig = JSON.parse(fs.readFileSync(`${process.env.PWD}/package.json`));
pkgConfig = JSON.parse(fs.readFileSync(`${process.cwd()}/package.json`));
} catch (e) {
// console.log('package.json not found, add one for more output');
}
Expand All @@ -73,7 +73,7 @@ function compile({ whitelist, contracts, output, target, version }) {
buildTime: new Date(),
};

const configFile = `${process.env.PWD}/${target}/${CONFIG_FILE}`;
const configFile = `${process.cwd()}/${target}/${CONFIG_FILE}`;

try { // try marginging with old config
config = { ...toml.parse(fs.readFileSync(configFile).toString()), ...config };
Expand All @@ -83,7 +83,7 @@ function compile({ whitelist, contracts, output, target, version }) {
}

try { // try marginging with doxity config
config = { ...config, ...JSON.parse(fs.readFileSync(`${process.env.PWD}/${DOXITYRC_FILE}`).toString()) };
config = { ...config, ...JSON.parse(fs.readFileSync(`${process.cwd()}/${DOXITYRC_FILE}`).toString()) };
} catch (e) { /* do nothing */ }

// write the config
Expand All @@ -92,8 +92,8 @@ function compile({ whitelist, contracts, output, target, version }) {

// copy the readme
try {
const readmeFile = glob.sync(`${process.env.PWD}/${README_FILE}`, { nocase: true })[0];
const readmeTarget = `${process.env.PWD}/${target}/${README_TARGET}`;
const readmeFile = glob.sync(`${process.cwd()}/${README_FILE}`, { nocase: true })[0];
const readmeTarget = `${process.cwd()}/${target}/${README_TARGET}`;
if (fs.existsSync(readmeTarget)) { fs.unlinkSync(readmeTarget); }
fs.writeFileSync(readmeTarget, fs.readFileSync(readmeFile));
} catch (e) {
Expand All @@ -104,7 +104,11 @@ function compile({ whitelist, contracts, output, target, version }) {
}

export default function (opts) {
const output = `${process.env.PWD}/${opts.target}/${opts.dir}`;
if (!opts.dir)
opts.dir = DEFAULT_PAGES_DIR;
if (!opts.src)
opts.src = DEFAULT_SRC_DIR;
const output = `${process.cwd()}/${opts.target}/${opts.dir}`;
if (!fs.existsSync(output)) { throw new Error(`Output directory ${output} not found, are you in the right directory?`); }
// clear out the output folder (remove all json files)
glob.sync(`${output}/*.json`).forEach(file => fs.unlinkSync(file));
Expand Down
6 changes: 3 additions & 3 deletions src/compile/solc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import compile from 'truffle-compile';
export default function (src) {
// detect if we're in a truffle project
return new Promise((resolve) => {
if (fs.existsSync(`${process.env.PWD}/truffle.js`)) {
if (fs.existsSync(`${process.cwd()}/truffle.js`)) {
const config = Config.default();
config.resolver = new Resolver(config);
config.rawData = true;
Expand All @@ -18,7 +18,7 @@ export default function (src) {
const { metadata, ...rest } = res[k].rawData;
const { output, settings } = JSON.parse(metadata);
const fN = Object.keys(settings.compilationTarget)[0];
const fileName = fN.indexOf(process.env.PWD) === 0 ? fN : `${process.env.PWD}/node_modules/${fN}`;
const fileName = fN.indexOf(process.cwd()) === 0 ? fN : `${process.cwd()}/node_modules/${fN}`;
return {
...o,
[k]: { ...rest, ...output, fileName },
Expand All @@ -35,7 +35,7 @@ export default function (src) {
const fileFragments = file.split('/');
const contractName = fileFragments[fileFragments.length - 1].split('.sol')[0];
const contract = res.contracts[k];
const fileName = `${process.env.PWD}/${k.split(':')[0]}`;
const fileName = `${process.cwd()}/${k.split(':')[0]}`;
return {
...o,
[contractName]: {
Expand Down
2 changes: 1 addition & 1 deletion src/develop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import childProcess from 'child_process';

export default function ({ target }) {
// TODO check we're in ther right folder.. ?
const runDev = childProcess.spawn('npm', ['run', 'develop'], { cwd: `${process.env.PWD}/${target}` });
const runDev = childProcess.spawn('npm', ['run', 'develop'], { cwd: `${process.cwd()}/${target}` });
runDev.stdout.pipe(process.stdout);
runDev.stderr.pipe(process.stderr);
runDev.on('close', () => process.exit());
Expand Down
4 changes: 4 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ export function clearDirectory(target) {
export function getFunctionSignature(signature) {
return new Keccak(256).update(signature).digest('hex').substr(0, 8);
}

export function getNpmCommandName() {
return /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function populateArguments(passed) {
// merge with .doxityrc
let saved = {};
try {
saved = JSON.parse(fs.readFileSync(`${process.env.PWD}/${DOXITYRC_FILE}`).toString());
saved = JSON.parse(fs.readFileSync(`${process.cwd()}/${DOXITYRC_FILE}`).toString());
} catch (e) {
console.log('.doxityrc not found or unreadable');
}
Expand Down
10 changes: 5 additions & 5 deletions src/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import request from 'request';
import path from 'path';
import targz from 'tar.gz';

import { clearDirectory } from './helpers';
import { clearDirectory, getNpmCommandName } from './helpers';

import { DOXITYRC_FILE } from './constants';

export default function (args) {
const { source, target } = args;
// TODO check folder exists...
const absoluteTarget = `${process.env.PWD}/${target}`;
const tmpTarget = path.resolve(`${process.env.PWD}/${target}/../doxity-tmp-${new Date()}`);
const absoluteTarget = `${process.cwd()}/${target}`;
const tmpTarget = path.resolve(`${process.cwd()}/${target}/../doxity-tmp`);
// clear the target dir
clearDirectory(absoluteTarget)
.then(() => {
Expand Down Expand Up @@ -41,14 +41,14 @@ export default function (args) {
process.stdout.write(`\r${seq[i]} ${message}`);
}, 1000 / 24);
// install the deps
const npmInstall = childProcess.spawn('npm', ['install'], { cwd: absoluteTarget });
const npmInstall = childProcess.spawn(getNpmCommandName(), ['install'], { cwd: absoluteTarget });
npmInstall.stdout.removeAllListeners('data');
npmInstall.stderr.removeAllListeners('data');
npmInstall.stdout.pipe(process.stdout);
npmInstall.stderr.pipe(process.stderr);
npmInstall.on('close', () => {
clearInterval(spinner);
const doxityrcFile = `${process.env.PWD}/${DOXITYRC_FILE}`;
const doxityrcFile = `${process.cwd()}/${DOXITYRC_FILE}`;
// overwrite doxityrc file
if (fs.existsSync(doxityrcFile)) { fs.unlinkSync(doxityrcFile); }
fs.writeFileSync(doxityrcFile, `${JSON.stringify(args, null, 2)}\n`);
Expand Down
8 changes: 4 additions & 4 deletions src/publish.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import fs from 'fs';
import childProcess from 'child_process';

import { clearDirectory } from './helpers';
import { clearDirectory, getNpmCommandName } from './helpers';

export default function ({ target, out }) {
// TODO check folder exists...
const cwd = `${process.env.PWD}/${target}`;
const cwd = `${process.cwd()}/${target}`;
const outputFolder = `${cwd}/public`;
const destFolder = `${process.env.PWD}/${out}`;
const destFolder = `${process.cwd()}/${out}`;
clearDirectory(destFolder).then(() => {
const runDev = childProcess.spawn('npm', ['run', 'build'], { cwd });
const runDev = childProcess.spawn(getNpmCommandName(), ['run', 'build'], { cwd });
runDev.stdout.pipe(process.stdout);
runDev.stderr.pipe(process.stderr);
runDev.on('close', () => {
Expand Down