Skip to content

Commit

Permalink
Wire commands directly without gulp and process.exit on errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Apr 12, 2019
1 parent 1bf50dc commit e9ce691
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1,834 deletions.
19 changes: 9 additions & 10 deletions gulpfile.js → index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const gulp = require("gulp");
const { InMemoryKeyStore, KeyPair } = require('nearlib');
const neardev = require('nearlib/dev');
const UnencryptedFileSystemKeyStore = require('./unencrypted_file_system_keystore');
Expand All @@ -11,7 +10,7 @@ ncp.limit = 16;

// TODO: Fix promisified wrappers to handle error properly

gulp.task('newProject', async function() {
exports.newProject = async function() {
// Need to wait for the copy to finish, otherwise next tasks do not find files.
const proj_dir = yargs.argv.project_dir;
const source_dir = __dirname + "/blank_project";
Expand All @@ -22,20 +21,19 @@ gulp.task('newProject', async function() {
})};
await copyDirFn();
console.log('Copying project files complete.')
});
};

gulp.task('clean', async function(done) {
exports.clean = async function() {
const rmDirFn = () => {
return new Promise(resolve => {
rimraf(yargs.argv.out_dir, response => resolve(response));
})};
await rmDirFn();
console.log("Clean complete.");
done();
});
};

// Only works for dev environments
gulp.task('createDevAccount', async function(argv) {
exports.createDevAccount = async function(argv) {
const keyPair = await KeyPair.fromRandomSeed();
const accountId = argv.account_id;
const nodeUrl = argv.node_url;
Expand All @@ -54,15 +52,15 @@ gulp.task('createDevAccount', async function(argv) {
await neardev.createAccountWithLocalNodeConnection(accountId, keyPair.getPublicKey());
const keyStore = new UnencryptedFileSystemKeyStore();
keyStore.setKey(accountId, keyPair);
});
};

async function deployContractAndWaitForTransaction(accountId, data, near) {
const deployContractResult = await near.deployContract(accountId, data);
const waitResult = await near.waitForTransactionResult(deployContractResult);
return waitResult;
}

gulp.task('deploy', async function(argv) {
exports.deploy = async function(argv) {
const keyStore = new UnencryptedFileSystemKeyStore();
let accountId = argv.account_id;
if (!accountId) {
Expand Down Expand Up @@ -96,5 +94,6 @@ gulp.task('deploy', async function(argv) {
console.log("Deployment succeeded.");
} else {
console.log("Deployment transaction did not succeed: ", res);
process.exit(1);
}
});
};
70 changes: 16 additions & 54 deletions near
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#!/usr/bin/env node

const gulp = require('gulp');
const gulpfile = require('./gulpfile') // import the gulp file
const yargs = require('yargs');
const main = require('.');

const exitOnError = async function(promise) {
try {
await promise;
} catch (e) {
console.log("Error: ", e);
process.exit(1);
}
}

const deploy = {
command: 'deploy',
Expand All @@ -23,17 +30,7 @@ const deploy = {
desc: 'Your developer account id. If you have only one account, that one will be selected by default',
type: 'string',
}),
handler: (argv) => {
gulp.on('error', function(e) {
console.log("Deploy failed. Error:")
console.log(e.error);
});
if (gulp.task('deploy')) {
const result = gulp.task('deploy')(argv).catch(console.log);
} else {
throw "Unexpected error: deploy task not found in gulpfile."
}
}
handler: (argv) => exitOnError(main.deploy(argv))
};

const { spawn } = require('child_process');
Expand Down Expand Up @@ -67,19 +64,8 @@ const createAccount = {
desc: 'Unique identifier for the new account',
type: 'string',
required: true
})
,
handler: (argv) => {
gulp.on('error', function(e) {
console.log("Create account failed. Error:")
console.log(e.error);
});
if (gulp.task('createDevAccount')) {
const result = gulp.task('createDevAccount')(argv).catch(console.log);
} else {
throw "Unexpected error: createDevAccount task not found in gulpfile."
}
}
}),
handler: (argv) => exitOnError(main.createDevAccount(argv))
};

const clean = {
Expand All @@ -90,20 +76,8 @@ const clean = {
desc: 'build directory',
type: 'string',
default: './out'
})
,
handler: (argv) => {
gulp.on('error', function(e) {
console.log("Clean failed. Error:")
console.log(e.error);
});
if (gulp.task('clean')) {
const result = gulp.task('clean')(() => {})
.catch(console.log);
} else {
throw "Unexpected error: clean task not found in gulpfile."
}
}
}),
handler: (argv) => exitOnError(main.clean(argv))
};

const newProject = {
Expand All @@ -114,20 +88,8 @@ const newProject = {
desc: 'project directory',
type: 'string',
default: '.'
})
,
handler: (argv) => {
console.log(__dirname);
gulp.on('error', function(e) {
console.log("Create new project failed. Error:")
console.log(e.error);
});
if (gulp.task('newProject')) {
const result = gulp.task('newProject')(argv).catch(console.log);
} else {
throw "Unexpected error: clean task not found in gulpfile."
}
}
}),
handler: (argv) => exitOnError(main.newProject(argv))
};

yargs // eslint-disable-line
Expand Down

0 comments on commit e9ce691

Please sign in to comment.