Add option to install a generated distro to the local Helios data folder

* Run g distro with --installLocal to have the generated file be copied into the local helios data folder.
* New property required in the .env, HELIOS_DATA_FOLDER
* Added two launch configurations to vs code.
This commit is contained in:
Daniel Scalzi
2020-06-29 18:07:46 -04:00
parent c470c22f14
commit bac2480c1b
4 changed files with 78 additions and 11 deletions

22
.vscode/launch.json vendored
View File

@@ -7,14 +7,26 @@
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"name": "Generate Distribution",
"program": "${workspaceFolder}\\src\\index.ts",
"args": [
"g",
"distro",
"xyz"
"g", "distro"
],
"preLaunchTask": "compile",
"preLaunchTask": "build",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],
"outputCapture": "std",
},
{
"type": "node",
"request": "launch",
"name": "Install Dev Distribution",
"program": "${workspaceFolder}\\src\\index.ts",
"args": [
"g", "distro", "dev_distribution", "--installLocal"
],
"preLaunchTask": "build",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
],

10
.vscode/tasks.json vendored
View File

@@ -13,6 +13,16 @@
"presentation": {
"reveal": "silent"
}
},
{
"label": "build",
"type": "npm",
"script": "build",
"group": "build",
"problemMatcher": [],
"presentation": {
"reveal": "silent"
}
}
]
}

View File

@@ -25,6 +25,7 @@ Example
JAVA_EXECUTABLE=C:\Program Files\AdoptOpenJDK\jdk-8.0.232.09-hotspot\bin\java.exe
ROOT=D:\TestRoot2
BASE_URL=http://localhost:8080/
HELIOS_DATA_FOLDER=C:\Users\user\AppData\Roaming\Helios Launcher
```
## Usage
@@ -121,11 +122,20 @@ Arguments:
* `name` The name of the distribution file.
* OPTIONAL (default: `distribution`)
Options:
* `--installLocal` Have the application install a copy of the generated distribution to the Helios data folder.
* OPTIONAL (default: false)
* This is useful to easily test the new distribution.json in dev mode on Helios.
* Tip: Set name to `dev_distribution` when using this option.
>
> Example Usage
>
> `generate distro`
>
> `generate distro dev_distribution --installLocal`
>
---

View File

@@ -20,6 +20,13 @@ function getRoot(): string {
return resolvePath(process.env.ROOT as string)
}
function getHeliosDataFolder(): string | null {
if(process.env.HELIOS_DATA_FOLDER) {
return resolvePath(process.env.HELIOS_DATA_FOLDER as string)
}
return null
}
function getBaseURL(): string {
let baseUrl = process.env.BASE_URL as string
// Users must provide protocol in all other instances.
@@ -33,6 +40,16 @@ function getBaseURL(): string {
return (new URL(baseUrl)).toString()
}
function installLocalOption(yargs: yargs.Argv) {
return yargs.option('installLocal', {
describe: 'Install the generated distribution to your local Helios data folder.',
type: 'boolean',
demandOption: false,
global: false,
default: false
})
}
// function rootOption(yargs: yargs.Argv) {
// return yargs.option('root', {
// describe: 'File structure root.',
@@ -177,8 +194,7 @@ const generateDistroCommand: yargs.CommandModule = {
command: 'distro [name]',
describe: 'Generate a distribution index from the root file structure.',
builder: (yargs) => {
// yargs = rootOption(yargs)
// yargs = baseUrlOption(yargs)
yargs = installLocalOption(yargs)
yargs = namePositional(yargs)
return yargs
},
@@ -186,17 +202,36 @@ const generateDistroCommand: yargs.CommandModule = {
argv.root = getRoot()
argv.baseUrl = getBaseURL()
const finalName = `${argv.name}.json`
logger.debug(`Root set to ${argv.root}`)
logger.debug(`Base Url set to ${argv.baseUrl}`)
logger.debug(`Invoked generate distro name ${argv.name}.json.`)
logger.debug(`Install option set to ${argv.install}`)
logger.debug(`Invoked generate distro name ${finalName}.`)
const doLocalInstall = argv.installLocal as boolean
const heliosDataFolder = getHeliosDataFolder()
if(doLocalInstall && heliosDataFolder == null) {
logger.error('You MUST specify HELIOS_DATA_FOLDER in your .env when using the --install option.')
return
}
try {
const distributionStruct = new DistributionStructure(argv.root as string, argv.baseUrl as string)
const distro = await distributionStruct.getSpecModel()
const distroPath = resolvePath(argv.root as string, `${argv.name}.json`)
writeFile(distroPath, JSON.stringify(distro, null, 2))
logger.info(`Successfully generated ${argv.name}.json`)
const distroOut = JSON.stringify(distro, null, 2)
const distroPath = resolvePath(argv.root as string, finalName)
writeFile(distroPath, distroOut)
logger.info(`Successfully generated ${finalName}`)
logger.info(`Saved to ${distroPath}`)
logger.debug('Preview:\n', distro)
if(doLocalInstall) {
const finalDestination = resolvePath(heliosDataFolder!, finalName)
logger.info(`Installing distribution to ${finalDestination}`)
writeFile(finalDestination, distroOut)
logger.info('Success!')
}
} catch (error) {
logger.error(`Failed to generate distribution with root ${argv.root}.`, error)
}