Skip to content

Commit

Permalink
fix: new index file for npm
Browse files Browse the repository at this point in the history
  • Loading branch information
MirandaWood committed Dec 2, 2022
1 parent 127b216 commit 9853fe9
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
60 changes: 60 additions & 0 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

import fs from 'fs';
import path from 'path';

import mkdirs from './bin/mkdirs.mjs';
import compile from './built/index.js';
import { FilingError } from './built/error/errors.js';

// This function is used to export into the published npm package
// (it's basically a replacement for ./bin/index that npm understands)
// locally, always use the command line zappify as defined in package.json
export const zappify = (input, _zappName = input, output = './zapps', modify = false) => {

const inputFilePath = input;
const modifyAST = modify;
const inputFileName = path.parse(inputFilePath).name;
const zappName = _zappName || inputFileName;
const outputDirPath = `${output}/${zappName}`;
const configDirPath = `${outputDirPath}/config`;
const migrationsDirPath = `${outputDirPath}/migrations`;
const parseDirPath = `${outputDirPath}/parse`;
const circuitsDirPath = `${outputDirPath}/circuits`;
const contractsDirPath = `${outputDirPath}/contracts`;
const orchestrationDirPath = `${outputDirPath}/orchestration`;

const options = {
zappName,
inputFileName,
inputFilePath,
outputDirPath,
parseDirPath,
circuitsDirPath,
contractsDirPath,
orchestrationDirPath,
modifyAST,
};

if (!fs.existsSync(inputFilePath))
throw new FilingError(`inputFilePath "${inputFilePath}" does not exist.`);

if (path.parse(inputFilePath).ext !== '.zol')
if (path.parse(inputFilePath).ext === '.sol') {
console.warn(`We'd ordinarily expect a '.zol' file as input, but we'll try to compile this '.sol' file...`);
} else {
throw new FilingError(`Invalid input file extension. Expected '.zol' (a 'zappable' solidity file). Got '${path.parse(inputFilePath).ext}'.`);
}
fs.rmSync(parseDirPath, { recursive: true, force: true });
fs.rmSync(circuitsDirPath, { recursive: true, force: true });
fs.rmSync(contractsDirPath, { recursive: true, force: true });
fs.rmSync(orchestrationDirPath, { recursive: true, force: true });
fs.rmSync(configDirPath, { recursive: true, force: true });
fs.rmSync(migrationsDirPath, { recursive: true, force: true });

mkdirs(options);

compile(options)

}


15 changes: 12 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@eyblockchain/starlight",
"version": "0.0.1",
"description": "Create a zApp from Solidity",
"main": "built/index.js",
"main": "./index.mjs",
"scripts": {
"write-vk": "node /app/write-vk.mjs -i assign",
"test": "mocha",
Expand All @@ -21,9 +21,18 @@
"publishConfig": {
"registry": "https://npm.pkg.github.com"
},
"files": ["./built/**/*"],
"files": [
"./built/**/*",
"./index.mjs"
],
"release": {
"branches": ["master", {"name": "miranda/npm", "prerelease": "beta"}]
"branches": [
"master",
{
"name": "miranda/npm",
"prerelease": "beta"
}
]
},
"keywords": [
"private contract",
Expand Down

0 comments on commit 9853fe9

Please sign in to comment.