Skip to content
This repository has been archived by the owner on Apr 18, 2021. It is now read-only.

Commit

Permalink
feat: make gen-script can get files from directory path #113
Browse files Browse the repository at this point in the history
  • Loading branch information
JhChoy committed Mar 3, 2019
1 parent 3e5a120 commit 0d0bfb0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/vvisp/scripts/gen-script/generateApis.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ module.exports = async function(files, abiDir, jsDir, templatePath, options) {
const fs = require('fs-extra');
const { compile } = require('@haechi-labs/vvisp-utils');

const output = await compile(files, options); // TODO: get all files if it is directory
const output = await compile(files, options);

for (let i = 0; i < files.length; i++) {
const className = path.parse(files[i]).name;
const abi = output.contracts[files[i] + ':' + className].interface;
let abi;
try {
abi = output.contracts[files[i] + ':' + className].interface;
} catch (e) {
continue;
}

const jsonPath = path.join(abiDir, className + '.json');
const jsPath = path.join(jsDir, className + '.js');
Expand Down
18 changes: 17 additions & 1 deletion packages/vvisp/scripts/gen-script/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
module.exports = async function(files, options) {
const path = require('path');
const _ = require('lodash');
const fs = require('fs-extra');

const { printOrSilent } = require('@haechi-labs/vvisp-utils');
const { getAllFiles, printOrSilent } = require('@haechi-labs/vvisp-utils');
const { getJsApis, render, rollingUp } = require('./utils');
const generateApis = require('./generateApis');

options = require('../utils/injectConfig')(options);

const TEMPLATE = {
backScript: path.join(__dirname, '../../template/script.mustache'),
backIndex: path.join(__dirname, '../../template/index.js'),
frontScript: path.join(__dirname, '../../template/front.mustache'),
frontIndex: path.join(__dirname, '../../template/frontIndex.mustache')
};

for (let i = 0; i < files.length; i++) {
const file = files[i];
if (fs.statSync(file).isDirectory()) {
files = _.without(files, file);
files = _.union(
files,
getAllFiles(file, filePath => {
return path.parse(filePath).ext === '.sol';
})
);
}
}

if (options.front) {
await atFront(files, options);
} else {
Expand Down

0 comments on commit 0d0bfb0

Please sign in to comment.