enigen-occ-commerce-cli
Version:
A simple CLI to help with your daily OCC development.
69 lines (63 loc) • 2 kB
JavaScript
const fs = require('fs')
const { occEnv } = require('./occEnv')
const { dcu } = require('./dcu')
const childProcess = require('child_process')
const { CONSTANTS } = require('./constants')
const Methods = {
start: async () => {
if (!occEnv.hasEnv()) {
var { selectedEnv } = await occEnv.selector()
console.log(selectedEnv)
var {
adminUrl,
appKey,
Storefront,
GitRepo
} = await occEnv.promptEnvInfos()
const envFile = {
ACTIVE_ENV: selectedEnv,
OCC_ADMIN_URL: adminUrl,
OCC_APP_KEY: appKey,
OCC_STOREFRONT_URL: Storefront,
GitRepo: GitRepo
}
envFile[`OCC_${selectedEnv}_ADMIN_URL`] = adminUrl
envFile[`OCC_${selectedEnv}_APP_KEY`] = appKey
envFile[`OCC_STOREFRONT_URL`] = Storefront
envFile[`GitRepo`] = GitRepo
occEnv.writeEnvFile(envFile)
if (!occEnv.hasSrc()) {
console.log('Pulling Design Code Utility...')
occEnv.createDcu()
console.log('Creating src folder...')
occEnv.createSrc()
if (adminUrl && appKey) {
if (GitRepo) {
console.log('Initializing the git to the project ')
childProcess.execSync(
`git init ${CONSTANTS.PATHS.SRC} && cd ${CONSTANTS.PATHS.SRC} && git remote add origin ${GitRepo} && git fetch && git checkout develop`,
{
stdio: 'inherit'
}
)
}
console.log('Grabbing your files, please wait.')
dcu.grab(adminUrl, appKey)
childProcess.execSync(
`cd ${CONSTANTS.PATHS.SRC} && git pull origin develop`,
{
stdio: 'inherit'
}
)
} else {
console.log('Make sure you have correct .env')
}
} else {
console.log('Your project is ready!')
}
} else {
console.log('.env found, delete it and try again.')
}
}
}
exports.setup = Methods