Skip to content

Commit

Permalink
Refactored to make code a bit easier to read. Let prettier run on som…
Browse files Browse the repository at this point in the history
…e of the files.
  • Loading branch information
thekevinbrown committed Apr 29, 2019
1 parent 3367fbe commit 96d74f5
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 33 deletions.
84 changes: 53 additions & 31 deletions src/cli/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ export const buildImage = async () => {
await writeFile(
path.join(TEMP_DOCKER_DIRECTORY, 'Dockerfile'),
`
FROM ubuntu:18.04
FROM ubuntu:18.04
RUN apt-get update && apt-get install -y --no-install-recommends wget curl ca-certificates
RUN wget ${ConfigManager.cdt} && apt-get install -y ./*.deb && rm -f *.deb
RUN wget ${ConfigManager.eos} && apt-get install -y ./*.deb && rm -f *.deb
RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
`
RUN apt-get update && apt-get install -y --no-install-recommends wget curl ca-certificates
RUN wget ${ConfigManager.cdt} && apt-get install -y ./*.deb && rm -f *.deb
RUN wget ${ConfigManager.eos} && apt-get install -y ./*.deb && rm -f *.deb
RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
`.replace(/\t/gm, '')
);
// Execute docker build process
await docker.command(`build -t ${await dockerImageName()} "${TEMP_DOCKER_DIRECTORY}"`);
Expand All @@ -108,7 +108,19 @@ RUN apt-get clean && rm -rf /tmp/* /var/tmp/* && rm -rf /var/lib/apt/lists/*
*/
export const startContainer = async () => {
await docker.command(
`run --rm --name lamington -d -p 8888:8888 -p 9876:9876 --mount type=bind,src="${WORKING_DIRECTORY}",dst=/opt/eosio/bin/project --mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts -w "/opt/eosio/bin/" ${await dockerImageName()} /bin/bash -c "./scripts/init_blockchain.sh"`
`run
--rm
--name lamington
-d
-p 8888:8888
-p 9876:9876
--mount type=bind,src="${WORKING_DIRECTORY}",dst=/opt/eosio/bin/project
--mount type=bind,src="${__dirname}/../scripts",dst=/opt/eosio/bin/scripts
-w "/opt/eosio/bin/"
${await dockerImageName()}
/bin/bash -c "./scripts/init_blockchain.sh"`
.replace(/\n/gm, '')
.replace(/\t/gm, ' ')
);
};

Expand All @@ -118,12 +130,16 @@ export const startContainer = async () => {
* @author Mitch Pierias <github.com/MitchPierias>
* @returns Docker command promise
*/
export const stopContainer = () => {
export const stopContainer = async () => {
spinner.create('Stopping Lamington');
return docker.command('stop lamington')
.then(() => spinner.end('Stopped Lamington'))
.catch(err => spinner.fail(err));
}

try {
await docker.command('stop lamington');
spinner.end('Stopped Lamington');
} catch (err) {
spinner.fail(err);
}
};

/**
* Sleeps the process until the EOS instance is available
Expand Down Expand Up @@ -174,6 +190,9 @@ export const startEos = async () => {
// Create build result cache directories
await mkdirp(path.join(WORKING_DIRECTORY, '.lamington', 'compiled_contracts'));
await mkdirp(path.join(WORKING_DIRECTORY, '.lamington', 'data'));

spinner.create('Starting EOS Docker container');

// Ensure an EOSIO build image exists
if (!(await imageExists())) {
console.log('--------------------------------------------------------------');
Expand Down Expand Up @@ -206,7 +225,7 @@ export const startEos = async () => {
==================================================== \n'
);
} catch (error) {
spinner.fail('Could not start EOS blockchain. Error: '+error);
spinner.fail('Could not start EOS blockchain. Error: ' + error);
process.exit(1);
}
};
Expand Down Expand Up @@ -266,7 +285,7 @@ export const runTests = async () => {
* @note Should be configurable with a RegExp or something to prevent all C++ files being compiled
* @param contracts Optional contract paths to build
*/
export const buildAll = async (contracts?:string[]) => {
export const buildAll = async (contracts?: string[]) => {
// Find all contract files
contracts = await glob('./**/*.cpp');
const errors = [];
Expand All @@ -288,7 +307,9 @@ export const buildAll = async (contracts?:string[]) => {
// Print each error message and source
for (const error of errors) console.error(error.message, '\n', ' -> ', error.error);
// Terminate the current process
throw new Error(`${errors.length} contract${(errors.length>0)?'s':''} failed to compile. Quitting.`)
throw new Error(
`${errors.length} contract${errors.length > 0 ? 's' : ''} failed to compile. Quitting.`
);
}
};

Expand All @@ -300,8 +321,7 @@ export const buildAll = async (contracts?:string[]) => {
* @param filePath Path to file
* @returns Identifier path
*/
export const pathToIdentifier = (filePath: string) =>
filePath.substr(0, filePath.lastIndexOf('.'));
export const pathToIdentifier = (filePath: string) => filePath.substr(0, filePath.lastIndexOf('.'));

/**
* Builds contract resources for contract at path
Expand Down Expand Up @@ -331,19 +351,21 @@ export const compileContract = async (contractPath: string) => {
// Get the base filename from path and log status
const basename = path.basename(contractPath, '.cpp');
// Pull docker images
await docker.command(
// Arg 1 is filename, arg 2 is contract name.
`exec lamington /opt/eosio/bin/scripts/compile_contract.sh "/${path.join(
'opt',
'eosio',
'bin',
'project',
contractPath
)}" "${path.dirname(contractPath)}" "${basename}"`
).catch(err => {
spinner.fail("Failed to compile");
throw new Error(`Failed to compile ${basename}`)
});
await docker
.command(
// Arg 1 is filename, arg 2 is contract name.
`exec lamington /opt/eosio/bin/scripts/compile_contract.sh "/${path.join(
'opt',
'eosio',
'bin',
'project',
contractPath
)}" "${path.dirname(contractPath)}" "${basename}"`
)
.catch(err => {
spinner.fail('Failed to compile');
throw new Error(`Failed to compile ${basename}`);
});
// Notify build task completed
spinner.end(`Compiled contract`);
}
};
3 changes: 1 addition & 2 deletions src/contracts/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export interface ContractActionOptions {
* Adds additional functionality to the EOSJS `Contract` class
*/
export class Contract implements EOSJSContract {

/** @hidden EOSJS api reference */
private _eos: Api;
/** @hidden Current contract account */
Expand Down Expand Up @@ -77,7 +76,7 @@ export class Contract implements EOSJSContract {
} got ${arguments.length}.`
);
}

if (arguments.length > action.fields.length + 1) {
throw new Error(
`Too many arguments supplied to ${action.name}. Expected ${action.fields.length} got ${
Expand Down

0 comments on commit 96d74f5

Please sign in to comment.