UNPKG

@arc-fusion/cli

Version:

CLI for running Arc Fusion on your local machine

63 lines (51 loc) 1.75 kB
'use strict' const fs = require('fs') const path = require('path') const ADMIN_RELEASE = require('./admin.json').version function fileExists (filePath) { try { fs.accessSync(filePath) return true } catch (e) { return false } } const COMMAND_ROOT = path.resolve('.') const FUSION_ROOT = path.dirname(__dirname) const BOOTSTRAP_ROOT = path.join(FUSION_ROOT, 'bootstrap') let LOCAL_SCRIPT_PATH try { // don't assume the command is being called from the project root // we should support commands being run from subdirectories // require.resolve automatically resolves symlinks, so isn't useful with `npm link @arc-fusion/cli` // (which is really helpful in testing) let possibleProjectRoot = COMMAND_ROOT while (possibleProjectRoot.length) { const localScriptPath = path.join(possibleProjectRoot, 'node_modules', '@arc-fusion', 'cli', 'bin', 'fusion.js') if (fileExists(localScriptPath)) { LOCAL_SCRIPT_PATH = localScriptPath break } possibleProjectRoot = possibleProjectRoot.substr(0, possibleProjectRoot.lastIndexOf(path.sep)) } } catch (e) {} const IS_GLOBAL = !LOCAL_SCRIPT_PATH const PROJECT_ROOT = (IS_GLOBAL) ? COMMAND_ROOT // remove node_modules/@arc-fusion/cli/bin/fusion.js from the local script path : LOCAL_SCRIPT_PATH.split(path.sep).slice(0, -5).join(path.sep) const REPO_NAME = path.basename(PROJECT_ROOT) const CACHE_VOLUME_NAME = `fusion_cache_${REPO_NAME}` require('dotenv').config({ path: path.join(PROJECT_ROOT, '.env') }) module.exports = { ADMIN_RELEASE, BOOTSTRAP_ROOT, COMMAND_ROOT, FUSION_RELEASE: process.env.FUSION_RELEASE || 'latest', FUSION_ROOT, IS_GLOBAL, LOCAL_SCRIPT_PATH, PROJECT_ROOT, REPO_NAME, CACHE_VOLUME_NAME }