UNPKG

enigen-occ-commerce-cli

Version:

A simple CLI to help with your daily OCC development.

67 lines (59 loc) 1.95 kB
require('dotenv').config() const shell = require('shelljs') const { CONSTANTS } = require('./constants') const { occEnv } = require('./occEnv') const childProcess = require('child_process') 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 = { grab: (adminUrl, appKey, GitRepo) => { if (!occEnv.hasSrc()) { occEnv.createSrc() if (process.env.GitRepo) { console.log('Initializing the git to the project ') childProcess.execSync( `git init ${CONSTANTS.PATHS.SRC} && cd ${CONSTANTS.PATHS.SRC} && git remote add origin ${process.env.GitRepo} && git fetch && git checkout develop`, { stdio: 'inherit' } ) } } 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` } shell.exec(finalShellScript, { async: false }) }, put: (file) => { shell.exec(`${DCU_BASE_COMMAND} -t "${file}"`, { async: false }) }, refresh: (path) => { shell.exec(`${DCU_BASE_COMMAND} -e "${path.replace(/\/$/g, '')}"`, { async: false }) }, putAll: (path) => { shell.exec(`${DCU_BASE_COMMAND} -m "${path.replace(/\/$/g, '')}"`, { async: false }) }, 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` shell.exec(finalShellScript, { async: false }) } else { console.log(`${selectedEnv} is not configured.`) } } } exports.dcu = Methods