2020-03-05 08:25:00 +03:00
|
|
|
#!/usr/bin/env node
|
2020-03-16 05:58:00 +03:00
|
|
|
|
|
|
|
const cmd = require('./build/cmd')
|
|
|
|
const fs = require('fs').promises
|
2022-01-10 12:18:34 +03:00
|
|
|
const path = require('path')
|
|
|
|
const os = require('os')
|
2020-03-16 05:58:00 +03:00
|
|
|
const fss = require('fs')
|
|
|
|
const paths = require('./build/paths')
|
|
|
|
|
2022-03-29 05:15:08 +03:00
|
|
|
process.on('unhandledRejection', error => { throw(error.stack) })
|
2020-03-05 08:25:00 +03:00
|
|
|
|
|
|
|
let args = process.argv.slice(2)
|
|
|
|
|
2020-10-26 04:18:40 +03:00
|
|
|
let skip_validation = '--skip-version-validation'
|
2020-03-05 08:25:00 +03:00
|
|
|
async function init () {
|
2020-10-26 04:18:40 +03:00
|
|
|
if(!args.includes(skip_validation)) {
|
|
|
|
cmd.section('Version Validation')
|
|
|
|
console.log("Use the `" + skip_validation + "` flag to skip it.")
|
|
|
|
console.log("Querying npm for the latest LTS versions.")
|
2021-03-30 17:16:46 +03:00
|
|
|
let [node_lts_version,npm_lts_version] = await cmd.get_node_lts_version()
|
2020-10-26 04:18:40 +03:00
|
|
|
console.log("Checking versions of installed packages.")
|
2021-03-30 17:16:46 +03:00
|
|
|
await cmd.check_version('node',node_lts_version)
|
2020-10-26 04:18:40 +03:00
|
|
|
await cmd.check_version('npm',npm_lts_version)
|
2022-03-18 16:45:56 +03:00
|
|
|
await cmd.check_version('rustc','1.61.0-nightly',{
|
2020-10-26 04:18:40 +03:00
|
|
|
preprocess:(v)=>v.substring(6,20)
|
2020-03-16 05:58:00 +03:00
|
|
|
})
|
2020-03-05 08:25:00 +03:00
|
|
|
}
|
|
|
|
|
2021-02-02 08:07:43 +03:00
|
|
|
let initialized = fss.existsSync(paths.dist.buildInit)
|
2020-03-05 08:25:00 +03:00
|
|
|
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 () => {
|
2020-03-05 08:25:00 +03:00
|
|
|
await cmd.run('npm',['install'])
|
|
|
|
})
|
2021-02-02 08:07:43 +03:00
|
|
|
await fs.mkdir(paths.dist.root, {recursive:true})
|
|
|
|
await fs.open(paths.dist.buildInit,'w')
|
2020-03-05 08:25:00 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 12:18:34 +03:00
|
|
|
// 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'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-05 08:25:00 +03:00
|
|
|
async function main() {
|
2022-01-10 12:18:34 +03:00
|
|
|
throwIfInvalidRootLocation()
|
2020-03-05 08:25:00 +03:00
|
|
|
await init()
|
2020-03-16 05:58:00 +03:00
|
|
|
cmd.run('node',[paths.script.run].concat(args))
|
2020-03-05 08:25:00 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|