Skip to content

Commit

Permalink
chore: rollback unintended code-style changes
Browse files Browse the repository at this point in the history
  • Loading branch information
thepiwo committed May 16, 2023
1 parent 1f7a164 commit a4fd777
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 88 deletions.
27 changes: 5 additions & 22 deletions src/cli/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ const addInitOption = (program) => {
program
.command('init')
.description('Initialize AEproject')
.argument(
'[folder]',
'project name for folder to be created',
constants.artifactsDest,
)
.argument('[folder]', 'project name for folder to be created', constants.artifactsDest)
.option('--update', 'update project files')
.action(async (folder, option) => {
await init.run(folder, option.update);
Expand All @@ -34,24 +30,11 @@ const addTestOption = (program) => {
const addEnvOption = (program) => {
program
.command('env')
.description(
'Running a local network. Without any argument started with default configuration',
)
.description('Running a local network. Without any argument started with default configuration')
.option('--stop', 'Stop the node')
.option(
'--info',
'Displays information about your current node status if any, and absolute path where it has been started from',
)
.option(
'--nodeVersion [nodeVersion]',
`Specify node version, default is ${nodeConfig.imageVersion}`,
nodeConfig.imageVersion,
)
.option(
'--compilerVersion [compilerVersion]',
`Specify compiler version, default is ${compilerConfig.imageVersion}`,
compilerConfig.imageVersion,
)
.option('--info', 'Displays information about your current node status if any, and absolute path where it has been started from')
.option('--nodeVersion [nodeVersion]', `Specify node version, default is ${nodeConfig.imageVersion}`, nodeConfig.imageVersion)
.option('--compilerVersion [compilerVersion]', `Specify compiler version, default is ${compilerConfig.imageVersion}`, compilerConfig.imageVersion)
.action(async (options) => {
await env.run(options);
});
Expand Down
32 changes: 7 additions & 25 deletions src/env/env.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,14 @@
const { spawn, exec } = require('promisify-child-process');

const {
print,
printError,
ensureNodeAndCompilerAvailable,
} = require('../utils/utils');
const {
nodeConfiguration,
compilerConfiguration,
proxyConfiguration,
} = require('../config/node-config.json');
const { print, printError, ensureNodeAndCompilerAvailable } = require('../utils/utils');
const { nodeConfiguration, compilerConfiguration, proxyConfiguration } = require('../config/node-config.json');

let dockerComposeCmd = 'docker compose';

async function getDockerCompose() {
const dockerSpaceCompose = await spawn('docker', ['compose']).catch(() => ({
code: 1,
}));
const dockerSpaceCompose = await spawn('docker', ['compose']).catch(() => ({ code: 1 }));
if (dockerSpaceCompose.code === 0) return;
const dockerMinusCompose = await spawn('docker-compose').catch(() => ({
code: 1,
}));
const dockerMinusCompose = await spawn('docker-compose').catch(() => ({ code: 1 }));
if (dockerMinusCompose.code === 0) {
dockerComposeCmd = 'docker-compose';
return;
Expand Down Expand Up @@ -87,12 +75,8 @@ async function startEnv(nodeVersion, compilerVersion) {
print('===== starting env =====');

await getDockerCompose();
await exec(
`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} pull`,
);
await exec(
`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} up -d --wait`,
);
await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} pull`);
await exec(`NODE_TAG=${nodeVersion} COMPILER_TAG=${compilerVersion} ${dockerComposeCmd} up -d --wait`);

await ensureNodeAndCompilerAvailable();

Expand All @@ -102,9 +86,7 @@ async function startEnv(nodeVersion, compilerVersion) {

async function printInfo(running) {
if (!running) {
printError(
'===== Compiler or Node is not running! ===== \n===== Please run the relevant command for your image! =====',
);
printError('===== Compiler or Node is not running! ===== \n===== Please run the relevant command for your image! =====');
return;
}

Expand Down
36 changes: 11 additions & 25 deletions src/init/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ const { exec } = require('promisify-child-process');
const constants = require('./constants.json');
const { print } = require('../utils/utils');

const {
copyFolderRecursiveSync,
deleteWithPrompt,
} = require('../utils/fs-utils');
const { copyFolderRecursiveSync, deleteWithPrompt } = require('../utils/fs-utils');

async function run(folder, update) {
checkNodeVersion();
Expand Down Expand Up @@ -43,9 +40,7 @@ const createAEprojectProjectStructure = async (folder) => {
await installDependencies(folder);

print('===== aeproject successfully initialized =====');
print(
'test/exampleTest.js and contract/ExampleContract.aes have been added as example how to use aeproject',
);
print('test/exampleTest.js and contract/ExampleContract.aes have been added as example how to use aeproject');
};

const updateAEprojectProjectLibraries = async (folder, update) => {
Expand All @@ -55,9 +50,7 @@ const updateAEprojectProjectLibraries = async (folder, update) => {
await installDependencies(folder, update);

print('===== aeproject sucessfully initalized =====');
print(
'test/exampleTest.js and contract/ExampleContract.aes have been added as example how to use aeproject',
);
print('test/exampleTest.js and contract/ExampleContract.aes have been added as example how to use aeproject');
};

const installDependencies = async (folder, update = false) => {
Expand All @@ -70,9 +63,7 @@ const installDependencies = async (folder, update = false) => {
constants.dependencies.map((dependency) => installPromises.push(`${npm} install ${dependency}`));
constants.devDependencies.map((dependency) => installPromises.push(`${npm} install --save-dev ${dependency}`));
constants.uninstallDependencies.map((dependency) => installPromises.push(`${npm} uninstall ${dependency}`));
installPromises.push(
'npx npm-add-script -k "test" -v "mocha ./test/**/*.js --timeout 0 --exit" --force',
);
installPromises.push('npx npm-add-script -k "test" -v "mocha ./test/**/*.js --timeout 0 --exit" --force');
}

await installPromises.reduce(async (promiseAcc, command) => {
Expand All @@ -86,25 +77,20 @@ const installDependencies = async (folder, update = false) => {
const setupArtifacts = async (folder) => {
print('===== creating project file and directory structure =====');

await copyFolderRecursiveSync(
`${__dirname}${constants.updateArtifactsDir}`,
path.join(constants.artifactsDest, folder),
);
await copyFolderRecursiveSync(
`${__dirname}${constants.artifactsDir}`,
path.join(constants.artifactsDest, folder),
);
await copyFolderRecursiveSync(`${__dirname}${constants.updateArtifactsDir}`, path.join(constants.artifactsDest, folder));
await copyFolderRecursiveSync(`${__dirname}${constants.artifactsDir}`, path.join(constants.artifactsDest, folder));
};

const updateArtifacts = async (folder) => {
print('===== updating project file and directory structure =====');

const fileSource = `${__dirname}${constants.updateArtifactsDir}`;

await constants.deleteArtifacts.reduce(async (promiseAcc, artifact) => {
await promiseAcc;
await deleteWithPrompt(artifact);
}, Promise.resolve());
await constants.deleteArtifacts
.reduce(async (promiseAcc, artifact) => {
await promiseAcc;
await deleteWithPrompt(artifact);
}, Promise.resolve());

await copyFolderRecursiveSync(fileSource, folder);
};
Expand Down
22 changes: 6 additions & 16 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,12 @@ export const getContractContent = (contractPath) => fs.readFileSync(contractPath

export const getFilesystem = (contractPath) => {
const defaultIncludes = [
'List.aes',
'Option.aes',
'String.aes',
'Func.aes',
'Pair.aes',
'Triple.aes',
'BLS12_381.aes',
'Frac.aes',
'Set.aes',
'List.aes', 'Option.aes', 'String.aes',
'Func.aes', 'Pair.aes', 'Triple.aes',
'BLS12_381.aes', 'Frac.aes', 'Set.aes',
'Bitwise.aes',
];

const rgx = /^include\s+"([\w/.-]+)"/gim;
const rgxIncludePath = /"([\w/.-]+)"/i;
const rgxMainPath = /.*\//g;
Expand All @@ -43,15 +38,10 @@ export const getFilesystem = (contractPath) => {

// eslint-disable-next-line no-console
console.log(`==> Adding include to filesystem: ${includeRelativePath[1]}`);
const includePath = path.resolve(
`${contractPathMatch[0]}/${includeRelativePath[1]}`,
);
const includePath = path.resolve(`${contractPathMatch[0]}/${includeRelativePath[1]}`);

try {
filesystem[includeRelativePath[1]] = fs.readFileSync(
includePath,
'utf-8',
);
filesystem[includeRelativePath[1]] = fs.readFileSync(includePath, 'utf-8');
} catch (error) {
throw Error(`File to include '${includeRelativePath[1]}' not found.`);
}
Expand Down

0 comments on commit a4fd777

Please sign in to comment.