Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,5 @@ jobs:
- uses: actions/setup-node@master
with:
node-version: 'lts/*'
cache: 'npm'
- run: npm ci
- run: npm install
- run: npm test
14 changes: 11 additions & 3 deletions bin/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@ export default class Install extends CliCommand {
return new UiServer(this.options)
.on('exit', e => this.cleanUp(e))
}
if (this.options.devMode) {
console.log('IMPORTANT: dev mode flag currently has no effect when running in headless mode\n')
}
try {
if (!this.options.tag) this.options.tag = await this.getReleaseInput()

console.log(`Installing Adapt authoring tool ${this.options.tag} in ${this.options.cwd}`)
await this.cloneRepo()
if (this.options.devMode) await this.installDevModules()
await Utils.registerSuperUser(this.options)
await Utils.clearInstallState(this.options.cwd)

Expand All @@ -43,6 +41,16 @@ export default class Install extends CliCommand {
}
}

async installDevModules () {
const modules = await Utils.loadDevModulesConfig(this.options.cwd)
if (!modules?.length) {
console.log('Dev mode: no repos.json found in install root, skipping local modules')
return
}
console.log(`Dev mode: cloning ${modules.length} local modules from repos.json`)
await Utils.installLocalModules({ ...this.options, modules })
}

async handleExistingInstall () {
const checkpoint = await Utils.getInstallState(this.options.cwd)
if (checkpoint) {
Expand Down
2 changes: 2 additions & 0 deletions lib/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import importCore from './utils/importCore.js'
import { getInstallState, saveInstallState, clearInstallState } from './utils/installState.js'
import installLocalModules from './utils/installLocalModules.js'
import isModule from './utils/isModule.js'
import loadDevModulesConfig from './utils/loadDevModulesConfig.js'
import loadJson from './utils/loadJson.js'
import loadPackage from './utils/loadPackage.js'
import startApp from './utils/startApp.js'
Expand Down Expand Up @@ -41,6 +42,7 @@ export default {
importCore,
installLocalModules,
isModule,
loadDevModulesConfig,
loadJson,
loadPackage,
parseBody,
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/cloneRepo.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const GITHUB_ORG_URL = 'https://github.com/adapt-security'
const GITHUB_REPO = 'adapt-authoring'

export default async function cloneRepo (options) {
const url = `${GITHUB_ORG_URL}/${options.repo || GITHUB_REPO}.git`
const url = options.url || `${GITHUB_ORG_URL}/${options.repo || GITHUB_REPO}.git`
const tag = options.tag || 'master'
console.log(`Cloning ${url}#${tag} into ${options.cwd}`)
try {
Expand All @@ -16,4 +16,4 @@ export default async function cloneRepo (options) {
}
console.log('Installing npm dependencies')
await exec(`npm ${options.cleanInstall === false ? 'install' : 'ci'}`, options.cwd)
}
}
9 changes: 7 additions & 2 deletions lib/utils/installLocalModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import path from 'path'

export default async function installLocalModules (options) {
const dir = path.join(options.cwd, 'local_adapt_modules')
await Promise.all(options.modules.map(m => cloneRepo({ repo: m, cwd: path.join(dir, m), cleanInstall: false })))
await Promise.all(options.modules.map(m => {
const name = typeof m === 'string' ? m : m.name
const url = typeof m === 'string' ? undefined : m.url
const localDir = name.includes('/') ? name.split('/')[1] : name
return cloneRepo({ repo: name, url, cwd: path.join(dir, localDir), cleanInstall: false })
}))
return exec('npm install', options.cwd) // need to run another npm install to pull in the local repos
}
}
18 changes: 18 additions & 0 deletions lib/utils/loadDevModulesConfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from 'fs/promises'
import path from 'path'

/**
* Looks for a repos.json config file in the umbrella install root. Used by
* headless dev installs to determine which workspace modules to clone and
* where to clone them from. Returns null if the file isn't present, so the
* interactive/discovery flow can still run.
*/
export default async function loadDevModulesConfig (cwd) {
const configPath = path.resolve(cwd, 'repos.json')
try {
return JSON.parse(await fs.readFile(configPath, 'utf8'))
} catch (e) {
if (e.code === 'ENOENT') return null
throw e
}
}
Loading