enso/run

61 lines
2.0 KiB
Plaintext
Raw Normal View History

#!/usr/bin/env node
const cmd = require('./build/cmd')
const fs = require('fs').promises
const path = require('path')
const os = require('os')
const fss = require('fs')
const paths = require('./build/paths')
process.on('unhandledRejection', error => { throw(error.stack) })
let args = process.argv.slice(2)
let skip_validation = '--skip-version-validation'
async function init () {
let skipValidationIndex = args.indexOf(skip_validation)
if (skipValidationIndex === -1) {
cmd.section('Version Validation')
console.log("Use the `" + skip_validation + "` flag to skip it.")
console.log("Querying npm for the latest LTS versions.")
let [node_lts_version,npm_lts_version] = await cmd.get_node_lts_version()
console.log("Checking versions of installed packages.")
await cmd.check_version('node',node_lts_version)
await cmd.check_version('npm',npm_lts_version)
await cmd.check_version('rustc','1.62.0-nightly',{
preprocess:(v)=>v.substring(6,20)
})
} else {
args.splice(skipValidationIndex, 1)
}
let initialized = fss.existsSync(paths.dist.buildInit)
if (!initialized) {
cmd.section('Initialization')
console.log('Installing build script dependencies.')
2021-10-30 18:06:21 +03:00
await cmd.with_cwd(paths.script.root, async () => {
await cmd.run('npm',['install'])
})
await fs.mkdir(paths.dist.root, {recursive:true})
await fs.open(paths.dist.buildInit,'w')
}
}
// Check the location of the repository root. It must not be located at `~/enso`, as this directory
// is used by project manager to store Enso's projects.
function throwIfInvalidRootLocation() {
let rootPath = path.resolve(__dirname)
let homeDir = os.homedir()
if (rootPath == path.resolve(homeDir, 'enso')) {
throw '~/enso location cannot be used as a repository root, please use a different location'
}
}
async function main() {
throwIfInvalidRootLocation()
await init()
cmd.run('node',[paths.script.run].concat(args))
}
main()