Skip to content

Instantly share code, notes, and snippets.

@NicolasRitouet
Created January 4, 2018 14:18
Show Gist options
  • Save NicolasRitouet/7bad6244a6b857ed4254d24b71b01bfb to your computer and use it in GitHub Desktop.
Save NicolasRitouet/7bad6244a6b857ed4254d24b71b01bfb to your computer and use it in GitHub Desktop.
A node SDF cli wrapper
const spawn = require('cross-spawn');
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout,
});
const getNetsuiteDomain = require('./rest.js');
/**
* @param {Config} config The configuration object
* @return {Promise} Promise that will resolve after the SDF deployment is complete
*/
module.exports = async function doSDFUpload(config) {
let url = await getNetsuiteDomain(config, 'systemDomain');
return new Promise((resolve, reject) => {
let sdfcli = spawn(
'sdfcli',
[
'deploy',
'-url',
url,
'-account',
config.account,
'-email',
config.email,
'-role',
config.role,
'-project',
config.file,
'-np',
],
{ stdio: ['pipe'] }
)
.on('error', reject)
.on('close', () => {
readline.close();
resolve();
});
sdfcli.stdout.on('data', data => {
process.stdout.write(data);
let output = data.toString();
if (output.includes('Enter password')) {
console.log('******');
sdfcli.stdin.write(config.password + '\n');
}
if (output.includes('Type YES to proceed with deploy')) {
readline.question('', answer => sdfcli.stdin.write(answer + '\n'));
}
if (output.includes('You are deploying to a Production account')) {
readline.question('', answer => sdfcli.stdin.write(answer + '\n'));
}
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment