From b9f4c48dac30b1533af8923e052f4da592825db4 Mon Sep 17 00:00:00 2001 From: Fabio Will Date: Thu, 12 Nov 2020 20:51:47 -0300 Subject: [PATCH 1/4] Add Download DCU and Create Site Settings and Stack --- .gitignore | 3 +- index.js | 20 ++++++---- src/ccw.js | 6 +++ src/constants.js | 8 +++- src/dcu.js | 86 ++++++++++++++++++++++++++++++++++++++-- src/occEnv.js | 14 ++++--- src/services/cc-admin.js | 2 +- src/setup.js | 13 +++++- 8 files changed, 132 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 40b878d..5b04c74 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +.idea +node_modules/ diff --git a/index.js b/index.js index 404a7f1..727c77c 100755 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ program .description('An application to help you with your daily OCC development.') .option('-s, --start', 'start the environment setup') .option('-d, --dev', 'start watcher + Browsersync') - .option('-c, --create ', 'create widget or element [widget|element]') + .option('-c, --create --dir ', 'create widget or element [widget|element|siteSettings|stack]') .option('-r, --refresh ', 'refresh path') .option('-p, --putAll ', 'upload the entire path') .option('-e, --env ', 'start the environment manager [change|config|current]') @@ -30,19 +30,19 @@ if (program.start) { if (program.dev) { dev.start(); } - + if(program.grab) { dcu.grab(); } - + if (program.refresh) { dcu.refresh(program.refresh); } - + if (program.putAll) { dcu.putAll(program.putAll); } - + if (program.transfer) { dcu.transfer(program.transfer); } @@ -60,8 +60,9 @@ if (program.start) { break; } } - + if (program.create) { + console.log(program.dir); switch (program.create) { case 'widget': ccw.createWidget(); @@ -69,9 +70,14 @@ if (program.start) { case 'element': ccw.createElement(); break; + case 'siteSettings': + ccw.createSiteSettings(); + break; + case 'stack': + ccw.createStack(); } } - + if (program.env) { switch (program.env) { case 'config': diff --git a/src/ccw.js b/src/ccw.js index aa54a4c..9830f68 100644 --- a/src/ccw.js +++ b/src/ccw.js @@ -11,6 +11,12 @@ const Methods = { createElement: () => { childProcess.execSync(`${CCW_BASE_COMMAND} -e`, { stdio: 'inherit' }); }, + createSiteSettings: () => { + childProcess.execSync(`${CCW_BASE_COMMAND} -t`, { stdio: 'inherit' }); + }, + createStack: () => { + childProcess.execSync(`${CCW_BASE_COMMAND} -s`, { stdio: 'inherit' }); + }, }; exports.ccw = Methods; diff --git a/src/constants.js b/src/constants.js index 85f6bcd..449b6e7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,5 +1,8 @@ exports.CONSTANTS = { ENVS: ['TEST', 'STAGE', 'PROD', 'NOENV'], + FILES: { + DCU: './DesignCodeUtility.zip', + }, PATHS: { SRC: './src', SSE: './sse', @@ -10,5 +13,6 @@ exports.CONSTANTS = { LOGIN: '/login', SSE_LIST: '/serverExtensions', SSE_UPLOAD: '/serverExtensions', - } -} \ No newline at end of file + DCU: '/occs-admin/js/DesignCodeUtility.zip', + }, +} diff --git a/src/dcu.js b/src/dcu.js index 1d83359..49a8c67 100644 --- a/src/dcu.js +++ b/src/dcu.js @@ -1,11 +1,91 @@ require('dotenv').config(); +const axios = require('axios'); +const fs = require('fs'); +const extract = require('extract-zip'); const shell = require('shelljs'); const { CONSTANTS } = require('./constants'); const { occEnv } = require('./occEnv'); +const dcu = 'DesignCodeUtility'; const DCU_BASE_COMMAND = `node ${CONSTANTS.PATHS.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${process.env.OCC_ADMIN_URL} -k ${process.env.OCC_APP_KEY}`; const Methods = { + + get: async (env) => { + env = env || process.env.ACTIVE_ENV; + + const response = await axios.get(`${process.env[`OCC_${env}_ADMIN_URL`]}${CONSTANTS.ENDPOINT.DCU}`, { + responseType: 'stream', + }).catch(err => { + if (err.response.status === 404) { + console.log(`Design Code Utility not found in ${env}.`); + } else { + console.log(`Design Code Utility error in ${env}.`); + } + }); + + return new Promise((resolve, reject) => { + if (response && response.data) { + const writer = fs.createWriteStream(CONSTANTS.FILES.DCU); + response.data.pipe(writer); + let error = null; + writer.on('error', err => { + error = err; + console.log('Download not completed. Please try again.'); + writer.close(); + reject(err); + }); + writer.on('close', async () => { + if (!error) { + resolve(true); + } + }); + } + }); + }, + + download: async () => { + if (fs.existsSync(CONSTANTS.FILES.DCU)) { + console.log(`Delete: DCU`); + await Methods.delete(); + } + + console.log(`Downloading: DCU`); + await Methods.get(); + + console.log(`Extracting: DCU`); + await Methods.unzip(); + + console.log(`Install: DCU`); + await Methods.install(); + }, + + unzip: async () => { + if (fs.existsSync(CONSTANTS.FILES.DCU)) { + await extract(CONSTANTS.FILES.DCU, { dir: `${process.cwd()}/${dcu}` }); + } else { + console.log('DCU required to extract.') + } + }, + + install: async () => { + return new Promise((resolve) => { + shell.cd(`./${dcu}`, { + async: false, + }); + shell.exec(`npm i`, { + async: false, + }, () => { + console.log('Installed: DCU') + resolve(true); + }); + }); + }, + + delete: async () => { + fs.rmdirSync(`./${dcu}`, { recursive: true }); + }, + grab: (adminUrl, appKey) => { var finalShellScript = `${DCU_BASE_COMMAND} -g -c`; if (adminUrl && appKey) { @@ -27,7 +107,7 @@ const Methods = { async: false, }); }, - + putAll: path => { shell.exec(`${DCU_BASE_COMMAND} -m "${path.replace(/\/$/g, '')}"`, { async: false, @@ -36,7 +116,7 @@ const Methods = { transfer: async path => { const { selectedEnv } = await occEnv.selector("Select an environment to transfer:"); - + if (occEnv.validate(selectedEnv)) { const { url, appKey } = occEnv.get(selectedEnv); finalShellScript = `node ${CONSTANTS.PATHS.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${url} -k ${appKey} -x "${path}" -o`; @@ -49,4 +129,4 @@ const Methods = { } }; -exports.dcu = Methods; \ No newline at end of file +exports.dcu = Methods; diff --git a/src/occEnv.js b/src/occEnv.js index bd25818..500cbdc 100644 --- a/src/occEnv.js +++ b/src/occEnv.js @@ -8,9 +8,7 @@ const Methods = { const keys = Object.keys(obj); let file = ''; keys.forEach(item => { - file += ` - ${item}=${obj[item]} - `; + file += `${item}=${obj[item]}\n`; }); return file; }, @@ -23,6 +21,10 @@ const Methods = { return fs.existsSync('./src'); }, + hasDCU: () => { + return fs.existsSync('./DesignCodeUtility'); + }, + createSrc: () => { return fs.mkdirSync('./src'); }, @@ -77,7 +79,7 @@ const Methods = { var { selectedEnv } = await Methods.selector(); environment = selectedEnv; } - + if (Methods.validate(environment)) { Methods.writeEnvFile({ ACTIVE_ENV: environment, @@ -147,8 +149,10 @@ const Methods = { }); } + process.env = {...process.env, ...envFile}; + fs.writeFileSync('.env', Methods.parseToEnvFile(envFile)); } } -exports.occEnv = Methods; \ No newline at end of file +exports.occEnv = Methods; diff --git a/src/services/cc-admin.js b/src/services/cc-admin.js index 9c7a921..a4bb1b1 100644 --- a/src/services/cc-admin.js +++ b/src/services/cc-admin.js @@ -22,4 +22,4 @@ exports.ccAdminApi = { STAGE, PROD, NOENV, -}; \ No newline at end of file +}; diff --git a/src/setup.js b/src/setup.js index 607fd19..58a8dc1 100644 --- a/src/setup.js +++ b/src/setup.js @@ -18,6 +18,11 @@ const Methods = { occEnv.writeEnvFile(envFile); + if (!occEnv.hasDCU()) { + console.log('Download DCU...'); + await dcu.download(); + } + if (!occEnv.hasSrc()) { console.log('Creating src folder...'); occEnv.createSrc(); @@ -27,9 +32,15 @@ const Methods = { console.log('Your project is ready!'); } } else { + + // if (!occEnv.hasDCU()) { + console.log('Download DCU...'); + await dcu.download(); + // } + console.log('.env found, delete it and try again.'); } } } -exports.setup = Methods; \ No newline at end of file +exports.setup = Methods; From c39ddeede6e5bf689b77c7b7ecfcbb5c55f3d71b Mon Sep 17 00:00:00 2001 From: Fabio Will Date: Thu, 12 Nov 2020 21:30:44 -0300 Subject: [PATCH 2/4] WIP: Fixs Messages --- src/ccw.js | 2 +- src/constants.js | 11 ++++++++--- src/dcu.js | 26 +++++++++++++------------- src/occEnv.js | 6 +++--- src/setup.js | 18 +++++++++--------- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/src/ccw.js b/src/ccw.js index 9830f68..ca0548c 100644 --- a/src/ccw.js +++ b/src/ccw.js @@ -2,7 +2,7 @@ require('dotenv').config(); const childProcess = require('child_process'); const { CONSTANTS } = require('./constants'); -const CCW_BASE_COMMAND = `node ${CONSTANTS.PATHS.CCW} -b ${CONSTANTS.PATHS.SRC} -n ${process.env.OCC_ADMIN_URL} -k ${process.env.OCC_APP_KEY}`; +const CCW_BASE_COMMAND = `node ${CONSTANTS.FILES.CCW} -b ${CONSTANTS.PATHS.SRC} -n ${process.env.OCC_ADMIN_URL} -k ${process.env.OCC_APP_KEY}`; const Methods = { createWidget: () => { diff --git a/src/constants.js b/src/constants.js index 449b6e7..4c6985a 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,13 +1,18 @@ exports.CONSTANTS = { ENVS: ['TEST', 'STAGE', 'PROD', 'NOENV'], + COLORS: { + TITLE: '\x1b[33m\x1b[1m%s\x1b[0m', + SUCCESS: '\x1b[32m\x1b[1m%s\x1b[0m', + }, FILES: { - DCU: './DesignCodeUtility.zip', + DCU_ZIP: './DesignCodeUtility.zip', + DCU: './DesignCodeUtility/dcuIndex.js', + CCW: './DesignCodeUtility/ccwIndex.js', }, PATHS: { SRC: './src', SSE: './sse', - DCU: './DesignCodeUtility/dcuIndex.js', - CCW: './DesignCodeUtility/ccwIndex.js', + DCU: './DesignCodeUtility', }, ENDPOINT: { LOGIN: '/login', diff --git a/src/dcu.js b/src/dcu.js index 49a8c67..0e47e22 100644 --- a/src/dcu.js +++ b/src/dcu.js @@ -6,8 +6,7 @@ const shell = require('shelljs'); const { CONSTANTS } = require('./constants'); const { occEnv } = require('./occEnv'); -const dcu = 'DesignCodeUtility'; -const DCU_BASE_COMMAND = `node ${CONSTANTS.PATHS.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${process.env.OCC_ADMIN_URL} -k ${process.env.OCC_APP_KEY}`; +const DCU_BASE_COMMAND = `node ${CONSTANTS.FILES.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${process.env.OCC_ADMIN_URL} -k ${process.env.OCC_APP_KEY}`; const Methods = { @@ -26,7 +25,7 @@ const Methods = { return new Promise((resolve, reject) => { if (response && response.data) { - const writer = fs.createWriteStream(CONSTANTS.FILES.DCU); + const writer = fs.createWriteStream(CONSTANTS.FILES.DCU_ZIP); response.data.pipe(writer); let error = null; writer.on('error', err => { @@ -45,15 +44,15 @@ const Methods = { }, download: async () => { - if (fs.existsSync(CONSTANTS.FILES.DCU)) { - console.log(`Delete: DCU`); + if (fs.existsSync(CONSTANTS.FILES.DCU_ZIP)) { + console.log(`🗑️ Delete: DCU`); await Methods.delete(); } - console.log(`Downloading: DCU`); + console.log(`🤟 Downloading: DCU`); await Methods.get(); - console.log(`Extracting: DCU`); + console.log(`🤖 Extracting: DCU`); await Methods.unzip(); console.log(`Install: DCU`); @@ -61,8 +60,8 @@ const Methods = { }, unzip: async () => { - if (fs.existsSync(CONSTANTS.FILES.DCU)) { - await extract(CONSTANTS.FILES.DCU, { dir: `${process.cwd()}/${dcu}` }); + if (fs.existsSync(CONSTANTS.FILES.DCU_ZIP)) { + await extract(CONSTANTS.FILES.DCU_ZIP, { dir: `${process.cwd()}/${CONSTANTS.PATHS.DCU}` }); } else { console.log('DCU required to extract.') } @@ -70,7 +69,7 @@ const Methods = { install: async () => { return new Promise((resolve) => { - shell.cd(`./${dcu}`, { + shell.cd(CONSTANTS.PATHS.DCU, { async: false, }); shell.exec(`npm i`, { @@ -83,13 +82,14 @@ const Methods = { }, delete: async () => { - fs.rmdirSync(`./${dcu}`, { recursive: true }); + fs.unlinkSync(CONSTANTS.FILES.DCU_ZIP); + fs.rmdirSync(CONSTANTS.PATHS.DCU, { recursive: true }); }, grab: (adminUrl, appKey) => { var finalShellScript = `${DCU_BASE_COMMAND} -g -c`; if (adminUrl && appKey) { - finalShellScript = `node ${CONSTANTS.PATHS.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${adminUrl} -k ${appKey} -c -g` + finalShellScript = `node ${CONSTANTS.FILES.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${adminUrl} -k ${appKey} -c -g` } shell.exec(finalShellScript, { async: false @@ -119,7 +119,7 @@ const Methods = { if (occEnv.validate(selectedEnv)) { const { url, appKey } = occEnv.get(selectedEnv); - finalShellScript = `node ${CONSTANTS.PATHS.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${url} -k ${appKey} -x "${path}" -o`; + finalShellScript = `node ${CONSTANTS.FILES.DCU} -b ${CONSTANTS.PATHS.SRC} -n ${url} -k ${appKey} -x "${path}" -o`; shell.exec(finalShellScript, { async: false, }); diff --git a/src/occEnv.js b/src/occEnv.js index 500cbdc..1ea8824 100644 --- a/src/occEnv.js +++ b/src/occEnv.js @@ -18,15 +18,15 @@ const Methods = { }, hasSrc: () => { - return fs.existsSync('./src'); + return fs.existsSync(CONSTANTS.PATHS.SRC); }, hasDCU: () => { - return fs.existsSync('./DesignCodeUtility'); + return fs.existsSync(CONSTANTS.PATHS.DCU); }, createSrc: () => { - return fs.mkdirSync('./src'); + return fs.mkdirSync(CONSTANTS.PATHS.SRC); }, selector: message => { diff --git a/src/setup.js b/src/setup.js index 58a8dc1..9aa1a0e 100644 --- a/src/setup.js +++ b/src/setup.js @@ -1,6 +1,6 @@ -const fs = require('fs'); const { occEnv } = require('./occEnv'); const { dcu } = require('./dcu'); +const { CONSTANTS } = require('./constants'); const Methods = { start: async () => { @@ -19,22 +19,22 @@ const Methods = { occEnv.writeEnvFile(envFile); if (!occEnv.hasDCU()) { - console.log('Download DCU...'); + console.log(CONSTANTS.COLORS.TITLE, 'Download DCU...'); await dcu.download(); } - if (!occEnv.hasSrc()) { - console.log('Creating src folder...'); + // if (!occEnv.hasSrc()) { + console.log(CONSTANTS.COLORS.TITLE, 'Creating src folder...'); occEnv.createSrc(); - console.log('Grabbing your files, please wait.'); + console.log(CONSTANTS.COLORS.TITLE, 'Grabbing your files, please wait.'); dcu.grab(adminUrl, appKey); - } else { - console.log('Your project is ready!'); - } + // } else { + console.log(CONSTANTS.COLORS.SUCCESS, 'Your project is ready!'); + // } } else { // if (!occEnv.hasDCU()) { - console.log('Download DCU...'); + console.log(CONSTANTS.COLORS.TITLE, 'Download DCU...'); await dcu.download(); // } From f1e2c427d38cea8f1552e9376dd6402209dbe124 Mon Sep 17 00:00:00 2001 From: Fabio Will Date: Fri, 13 Nov 2020 11:16:07 -0300 Subject: [PATCH 3/4] Add Service to add site settings, stack --- index.js | 5 ++--- src/ccw.js | 10 ++++++++-- src/constants.js | 2 ++ src/dcu.js | 19 ++++++++++--------- src/setup.js | 12 +++--------- src/sse.js | 43 +++++++++++++++++++++---------------------- 6 files changed, 46 insertions(+), 45 deletions(-) diff --git a/index.js b/index.js index 727c77c..9081f3a 100755 --- a/index.js +++ b/index.js @@ -14,7 +14,7 @@ program .description('An application to help you with your daily OCC development.') .option('-s, --start', 'start the environment setup') .option('-d, --dev', 'start watcher + Browsersync') - .option('-c, --create --dir ', 'create widget or element [widget|element|siteSettings|stack]') + .option('-c, --create ', 'create widget or element [widget|element|siteSettings|stack]') .option('-r, --refresh ', 'refresh path') .option('-p, --putAll ', 'upload the entire path') .option('-e, --env ', 'start the environment manager [change|config|current]') @@ -62,13 +62,12 @@ if (program.start) { } if (program.create) { - console.log(program.dir); switch (program.create) { case 'widget': ccw.createWidget(); break; case 'element': - ccw.createElement(); + ccw.createElement(program.args); break; case 'siteSettings': ccw.createSiteSettings(); diff --git a/src/ccw.js b/src/ccw.js index ca0548c..e1316fe 100644 --- a/src/ccw.js +++ b/src/ccw.js @@ -1,4 +1,5 @@ require('dotenv').config(); +const fs = require('fs'); const childProcess = require('child_process'); const { CONSTANTS } = require('./constants'); @@ -8,8 +9,13 @@ const Methods = { createWidget: () => { childProcess.execSync(`${CCW_BASE_COMMAND} -w`, { stdio: 'inherit' }); }, - createElement: () => { - childProcess.execSync(`${CCW_BASE_COMMAND} -e`, { stdio: 'inherit' }); + createElement: (args) => { + const path = args[0] ? args[0] : null; + if(path && !fs.existsSync(path)) { + console.log(CONSTANTS.COLORS.ERROR, 'No such directory'); + return; + } + childProcess.execSync(`${CCW_BASE_COMMAND} -e ${path}`, { stdio: 'inherit' }); }, createSiteSettings: () => { childProcess.execSync(`${CCW_BASE_COMMAND} -t`, { stdio: 'inherit' }); diff --git a/src/constants.js b/src/constants.js index 4c6985a..addebea 100644 --- a/src/constants.js +++ b/src/constants.js @@ -3,11 +3,13 @@ exports.CONSTANTS = { COLORS: { TITLE: '\x1b[33m\x1b[1m%s\x1b[0m', SUCCESS: '\x1b[32m\x1b[1m%s\x1b[0m', + ERROR: '\x1b[31m\x1b[1m%s\x1b[0m', }, FILES: { DCU_ZIP: './DesignCodeUtility.zip', DCU: './DesignCodeUtility/dcuIndex.js', CCW: './DesignCodeUtility/ccwIndex.js', + PLSU: './DesignCodeUtility/plsuIndex.js', }, PATHS: { SRC: './src', diff --git a/src/dcu.js b/src/dcu.js index 0e47e22..d736ff4 100644 --- a/src/dcu.js +++ b/src/dcu.js @@ -17,9 +17,9 @@ const Methods = { responseType: 'stream', }).catch(err => { if (err.response.status === 404) { - console.log(`Design Code Utility not found in ${env}.`); + console.log(CONSTANTS.COLORS.ERROR, `Design Code Utility not found in ${env}.`); } else { - console.log(`Design Code Utility error in ${env}.`); + console.log(CONSTANTS.COLORS.ERROR, `Design Code Utility error in ${env}.`); } }); @@ -30,7 +30,7 @@ const Methods = { let error = null; writer.on('error', err => { error = err; - console.log('Download not completed. Please try again.'); + console.log(CONSTANTS.COLORS.ERROR, 'Download not completed. Please try again.'); writer.close(); reject(err); }); @@ -45,14 +45,14 @@ const Methods = { download: async () => { if (fs.existsSync(CONSTANTS.FILES.DCU_ZIP)) { - console.log(`🗑️ Delete: DCU`); + console.log(`Delete: DCU`); await Methods.delete(); } - console.log(`🤟 Downloading: DCU`); + console.log(`Downloading: DCU`); await Methods.get(); - console.log(`🤖 Extracting: DCU`); + console.log(`Extracting: DCU`); await Methods.unzip(); console.log(`Install: DCU`); @@ -63,7 +63,7 @@ const Methods = { if (fs.existsSync(CONSTANTS.FILES.DCU_ZIP)) { await extract(CONSTANTS.FILES.DCU_ZIP, { dir: `${process.cwd()}/${CONSTANTS.PATHS.DCU}` }); } else { - console.log('DCU required to extract.') + console.log(CONSTANTS.COLORS.ERROR, 'DCU required to extract.') } }, @@ -75,7 +75,8 @@ const Methods = { shell.exec(`npm i`, { async: false, }, () => { - console.log('Installed: DCU') + fs.chmodSync(process.cwd(), 0o755); + console.log(CONSTANTS.COLORS.SUCCESS, 'Installed: DCU') resolve(true); }); }); @@ -124,7 +125,7 @@ const Methods = { async: false, }); } else { - console.log(`${selectedEnv} is not configured.`); + console.log(CONSTANTS.COLORS.ERROR, `${selectedEnv} is not configured.`); } } }; diff --git a/src/setup.js b/src/setup.js index 9aa1a0e..01c553e 100644 --- a/src/setup.js +++ b/src/setup.js @@ -23,21 +23,15 @@ const Methods = { await dcu.download(); } - // if (!occEnv.hasSrc()) { + if (!occEnv.hasSrc()) { console.log(CONSTANTS.COLORS.TITLE, 'Creating src folder...'); occEnv.createSrc(); console.log(CONSTANTS.COLORS.TITLE, 'Grabbing your files, please wait.'); dcu.grab(adminUrl, appKey); - // } else { + } else { console.log(CONSTANTS.COLORS.SUCCESS, 'Your project is ready!'); - // } + } } else { - - // if (!occEnv.hasDCU()) { - console.log(CONSTANTS.COLORS.TITLE, 'Download DCU...'); - await dcu.download(); - // } - console.log('.env found, delete it and try again.'); } } diff --git a/src/sse.js b/src/sse.js index 4ff5e8f..cfe4c08 100644 --- a/src/sse.js +++ b/src/sse.js @@ -63,7 +63,7 @@ const Methods = { get: async (sse, isBackup, env) => { env = env || process.env.ACTIVE_ENV; - + if (sse) { sse = sse.indexOf('.zip') !== -1 ? sse : `${sse}.zip`; const token = await auth.login(env); @@ -76,9 +76,9 @@ const Methods = { }).catch(err => { if (err.response.status === 404) { if (isBackup) { - console.log(`Backup not completed. ${sse} not found in ${env}.`); + console.log(CONSTANTS.COLORS.ERROR, `Backup not completed. ${sse} not found in ${env}.`); } else { - console.log(`${sse} not found in ${env}.`); + console.log(CONSTANTS.COLORS.ERROR, `${sse} not found in ${env}.`); } } }); @@ -91,13 +91,13 @@ const Methods = { if (!Methods.hasFolder()) { Methods.createFolder(); } - + await new Promise((resolve, reject) => { response.data.pipe(writer); let error = null; writer.on('error', err => { error = err; - console.log('Download not completed. Please try again.'); + console.log(CONSTANTS.COLORS.ERROR, 'Download not completed. Please try again.'); writer.close(); reject(err); }); @@ -107,9 +107,9 @@ const Methods = { } }); }); - } + } } else { - console.log('SSE required to download.') + console.log(CONSTANTS.COLORS.ERROR, 'SSE required to download.') } }, @@ -118,7 +118,7 @@ const Methods = { if (sse) { fs.unlinkSync(`${CONSTANTS.PATHS.SSE}/${sse}`); } else { - console.log('SSE required to delete.') + console.log(CONSTANTS.COLORS.ERROR, 'SSE required to delete.') } } else { console.log('occ CLI only deletes .zip files.'); @@ -144,7 +144,7 @@ const Methods = { if (sse) { await extract(`${CONSTANTS.PATHS.SSE}/${sse}`, { dir: `${process.cwd()}/${CONSTANTS.PATHS.SSE}/${sse.replace('.zip', '')}` }); } else { - console.log('SSE required to extract.') + console.log(CONSTANTS.COLORS.ERROR, 'SSE required to extract.') } }, @@ -153,13 +153,13 @@ const Methods = { const { selectedSSE } = await Methods.selector('server'); sse = selectedSSE; } - + console.log(`Downloading: ${sse}`); await Methods.get(sse); - + console.log(`Extracting: ${sse}`); await Methods.unzip(sse); - + console.log(`Deleting: ${sse}`); Methods.delete(sse); }, @@ -176,14 +176,13 @@ const Methods = { if (sse) { console.log(`Making a backup copy for ${sse} from ${env}...`); await Methods.get(sseType === 'zip' ? sse : `${sse}.zip`, true, env); - + if (sseType === 'folder') { console.log(`Zipping ${sse}...`); await Methods.zip(sse); sse = `${sse}.zip`; - sseType = 'zip'; } - + console.log(`Uploading ${sse} to ${env}, please wait. This may take a while...`); const token = await auth.login(env); const data = new FormData(); @@ -198,9 +197,9 @@ const Methods = { ...data.getHeaders(), } }).catch(err => { - console.log('SSE UPLOAD ERROR: \n', err.response.data); + console.log(CONSTANTS.COLORS.ERROR, 'SSE UPLOAD ERROR: \n', err.response.data); }); - + Methods.delete(`${sse}`); } @@ -218,7 +217,7 @@ const Methods = { const { selectedSSE } = await Methods.selector('server'); sse = selectedSSE; } - + const { confirm } = await inquirer.prompt([{ type: 'confirm', name: 'confirm', @@ -230,15 +229,15 @@ const Methods = { await Methods.get(sse); await Methods.upload(sse, targetEnv); } - + } else { - console.log(`${targetEnv} is not configured.`); + console.log(CONSTANTS.COLORS.ERROR, `${targetEnv} is not configured.`); } } else { - console.log(`Target environment can't be equal to current.`); + console.log(CONSTANTS.COLORS.ERROR, `Target environment can't be equal to current.`); } }, }; -exports.sse = Methods; \ No newline at end of file +exports.sse = Methods; From 5ff2d690893fb18e27236397b32b8c8845d0136c Mon Sep 17 00:00:00 2001 From: Fabio Will Date: Fri, 13 Nov 2020 11:36:08 -0300 Subject: [PATCH 4/4] Resolve fix when download DCU, back to root path --- src/dcu.js | 1 + src/occEnv.js | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/dcu.js b/src/dcu.js index d736ff4..be2ad4a 100644 --- a/src/dcu.js +++ b/src/dcu.js @@ -77,6 +77,7 @@ const Methods = { }, () => { fs.chmodSync(process.cwd(), 0o755); console.log(CONSTANTS.COLORS.SUCCESS, 'Installed: DCU') + shell.cd('..', { async: false }); resolve(true); }); }); diff --git a/src/occEnv.js b/src/occEnv.js index 1ea8824..67651f9 100644 --- a/src/occEnv.js +++ b/src/occEnv.js @@ -29,6 +29,16 @@ const Methods = { return fs.mkdirSync(CONSTANTS.PATHS.SRC); }, + confirm: message => { + return inquirer + .prompt([{ + type: 'list', + name: 'selectedEnv', + message: message || 'Refresh SRC path:', + choices: ['YES', 'NO'], + }]); + }, + selector: message => { return inquirer .prompt([{