Skip to content

Commit

Permalink
refactor(init)!: init command adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed Feb 7, 2022
1 parent 85f29c9 commit 8f2f47d
Show file tree
Hide file tree
Showing 42 changed files with 498 additions and 1,810 deletions.
114 changes: 114 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "@aeternity/aeproject",
"version": "4.0.0-alpha1",
"description": "aeternity smart contract testing tool",
"main": "src/lib/index.js",
"bin": {
"aeproject": "./src/cli.js"
},
Expand Down
2 changes: 1 addition & 1 deletion src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const program = require('commander');

const commands = require('./commands');
const commands = require('./cli/commands');
const packageJson = require('../package.json');

const setupVersion = () => {
Expand Down
61 changes: 8 additions & 53 deletions src/commands.js → src/cli/commands.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
const compile = require('./compile/compile');
const init = require('./init/init');
const testConfig = require('./test/test');
const env = require('./env/env/env');
const node = require('./env/env/node/node');
const compiler = require('./env/env/compiler/compiler');
const deploy = require('./deploy/deploy');
const config = require('./config');
const compile = require('../compile/compile');
const init = require('../init/init');
const testConfig = require('../test/test');
const env = require('../env/env');
const deploy = require('../deploy/deploy');
const config = require('../config/node-config.json');

const dockerIp = config.nodeConfiguration.dockerMachineIP;
const exportConfig = require('./export/export-config');
const aeprojectConfigDefaultFileName = require('./export/constants').aeprojectConfigFileName;
const txInspector = require('./tx-inspector/tx-inspector');
const compatibility = require('./compatibility/compatibility');
const txInspector = require('../tx-inspector/tx-inspector');
const compatibility = require('../compatibility/compatibility');

const nodeConfig = config.nodeConfiguration;
const compilerConfig = config.compilerConfiguration;
Expand Down Expand Up @@ -63,34 +59,6 @@ const addEnvOption = (program) => {
});
};

const addNodeOption = (program) => {
program
.command('node')
.description('Running a local node. Without any argument node will be run with --start argument')
.option('--stop', 'Stop the node')
.option('--start', 'Start the node')
.option('--info', 'Displays information about your current node status if any, and absolute path where it has been started from')
.option('--windows', 'Start the node in windows env')
.option('--docker-ip [default docker machine ip]', `Set docker machine IP, default is "${dockerIp}"`, dockerIp)
.option('--v [v]', `Specify node version, default is ${nodeConfig.imageVersion}`, nodeConfig.imageVersion)
.action(async (options) => {
await node.run(options);
});
};

const addCompilerOption = (program) => {
program
.command('compiler')
.description('Running a local compiler. Without any arguments compiler will be run with --start argument')
.option('--stop', 'Stop the node')
.option('--start', 'Start the node')
.option('--info', 'Displays information about your current node status if any, and absolute path where it has been started from')
.option('--v [v]', `Specify compiler version, default is ${compilerConfig.imageVersion}`, compilerConfig.imageVersion)
.action(async (options) => {
await compiler.run(options);
});
};

const addDeployOption = (program) => {
program
.command('deploy')
Expand All @@ -104,16 +72,6 @@ const addDeployOption = (program) => {
});
};

const addExportConfigOption = (program) => {
program
.command('export-config')
.description('Export miner account, few funded accounts and default node configuration.')
.option('--path [export path]', 'Path to export config file', aeprojectConfigDefaultFileName)
.action(async (options) => {
await exportConfig.run(options);
});
};

const addTxInspector = (program) => {
program
.command('inspect <tx>')
Expand Down Expand Up @@ -144,10 +102,7 @@ const initCommands = (program) => {
addCompileOption(program);
addTestOption(program);
addEnvOption(program);
addNodeOption(program);
addCompilerOption(program);
addDeployOption(program);
addExportConfigOption(program);
addTxInspector(program);
addCompatibility(program);
};
Expand Down
4 changes: 2 additions & 2 deletions src/compatibility/compatibility.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { exec } = require('promisify-child-process');
const { print } = require('../utils');
const { print } = require('../utils/utils');

const nodeConfig = require('../config').nodeConfiguration;
const nodeConfig = require('../config/node-config.json').nodeConfiguration;

async function run(option) {
let { nodeVersion } = option;
Expand Down
36 changes: 2 additions & 34 deletions src/compile/compile.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,8 @@
const { ContractCompilerAPI } = require('@aeternity/aepp-sdk');

const { printError, print } = require('../utils');
const utils = require('../utils');
const config = require('../config');

async function compileAndPrint(file, compiler) {
try {
const result = await compiler.compileContractAPI(utils.getContractContent(file), { filesystem: utils.getFilesystem(file) });
print(`Contract '${file}' has been successfully compiled.`);
print(`=> bytecode: ${result}`);
} catch (error) {
const errorMessage = utils.checkNestedProperty(error.response, 'data') ? JSON.parse(error.response.data)[0] : error.message;
printError(`Contract '${file}' has not been compiled.`);
printError(`=> reason: ${JSON.stringify(errorMessage)}`);
}
}
const config = require('../config/config.json');

async function run(path, compilerUrl = config.compilerUrl) {
print('===== Compiling contracts =====');
print('\r');
const compiler = await ContractCompilerAPI({ compilerUrl });
print(`Compiler URL: ${compilerUrl}`);
print(`Compiler version: ${await compiler.getCompilerVersion()}`);
print('\r');
print(`Contract path: ${path}`);

// TODO check async await correct
if (path.includes('.aes')) {
compileAndPrint(path, compiler);
} else {
print('\r');
const files = await utils.getFiles(`${process.cwd()}/${path}/`, '.*\.(aes)');
files.forEach(async (file) => {
compileAndPrint(file, compiler);
});
}
// TODO replace with ae cli
}

module.exports = {
Expand Down
Loading

0 comments on commit 8f2f47d

Please sign in to comment.