diff --git a/src/index.ts b/src/index.ts index fb68f06..f566c88 100644 --- a/src/index.ts +++ b/src/index.ts @@ -14,6 +14,14 @@ function rootOption(yargs: yargs.Argv) { }) } +function namePositional(yargs: yargs.Argv) { + return yargs.option('name', { + describe: 'Distribution index file name.', + type: 'string', + default: 'distribution' + }) +} + // ------------- // Init Commands @@ -80,15 +88,16 @@ const generateServerCommand: yargs.CommandModule = { } const generateDistroCommand: yargs.CommandModule = { - command: 'distro', + command: 'distro [name]', describe: 'Generate a distribution index from the root file structure.', builder: (yargs) => { yargs = rootOption(yargs) + yargs = namePositional(yargs) return yargs }, handler: (argv) => { console.log(`Root set to ${argv.root}`) - console.log('Invoked generate distro.') + console.log(`Invoked generate distro name ${argv.name}.json.`) } } @@ -106,6 +115,17 @@ const generateCommand: yargs.CommandModule = { } } +const validateCommand: yargs.CommandModule = { + command: 'validate [name]', + describe: 'Validate a distribution.json against the spec.', + builder: (yargs) => { + return namePositional(yargs) + }, + handler: (argv) => { + console.log(`Invoked validate with name ${argv.name}.json`) + } +} + // Registering yargs configuration. // tslint:disable-next-line:no-unused-expression yargs @@ -113,6 +133,7 @@ yargs .scriptName('') .command(initCommand) .command(generateCommand) +.command(validateCommand) .demandCommand() .help() .argv diff --git a/src/model/artifact.ts b/src/model/spec/artifact.ts similarity index 100% rename from src/model/artifact.ts rename to src/model/spec/artifact.ts diff --git a/src/model/distribution.ts b/src/model/spec/distribution.ts similarity index 97% rename from src/model/distribution.ts rename to src/model/spec/distribution.ts index 44c5a02..fabbe28 100644 --- a/src/model/distribution.ts +++ b/src/model/spec/distribution.ts @@ -7,7 +7,7 @@ export interface Distribution { /** * Global settings for Discord Rich Presence. */ - discord: { + discord?: { /** * Client ID for the Application registered with Discord. */ diff --git a/src/model/module.ts b/src/model/spec/module.ts similarity index 100% rename from src/model/module.ts rename to src/model/spec/module.ts diff --git a/src/model/required.ts b/src/model/spec/required.ts similarity index 100% rename from src/model/required.ts rename to src/model/spec/required.ts diff --git a/src/model/server.ts b/src/model/spec/server.ts similarity index 99% rename from src/model/server.ts rename to src/model/spec/server.ts index 58eca80..0e24fe2 100644 --- a/src/model/server.ts +++ b/src/model/spec/server.ts @@ -41,7 +41,7 @@ export interface Server { /** * Server specific settings used for Discord Rich Presence. */ - discord: { + discord?: { /** * Short ID for the server. Displayed on the second status line as Server: shortId. */ diff --git a/src/model/type.ts b/src/model/spec/type.ts similarity index 100% rename from src/model/type.ts rename to src/model/spec/type.ts diff --git a/src/model/struct/distribution.struct.ts b/src/model/struct/distribution.struct.ts new file mode 100644 index 0000000..8f217ed --- /dev/null +++ b/src/model/struct/distribution.struct.ts @@ -0,0 +1,25 @@ +import { Distribution } from '../spec/distribution' +import { ModelStructure } from './model.struct' +import { ServerStructure } from './server.struct' + +export class DistributionStructure implements ModelStructure { + + private servers: ServerStructure[] | undefined + + constructor( + private root: string + ) {} + + public getServers() { + return new ServerStructure(this.root).getSpecModel() + } + + public getSpecModel(): Distribution { + return { + version: '1.0.0', + rss: 'TODO', + servers: this.getServers() + } + } + +} diff --git a/src/model/struct/model.struct.ts b/src/model/struct/model.struct.ts new file mode 100644 index 0000000..179f531 --- /dev/null +++ b/src/model/struct/model.struct.ts @@ -0,0 +1,5 @@ +export interface ModelStructure { + + getSpecModel(): T + +} diff --git a/src/model/struct/server.struct.ts b/src/model/struct/server.struct.ts new file mode 100644 index 0000000..614bbf7 --- /dev/null +++ b/src/model/struct/server.struct.ts @@ -0,0 +1,25 @@ +import { resolve } from 'path' +import { Server } from '../spec/server' +import { ModelStructure } from './model.struct' + +export class ServerStructure implements ModelStructure { + + private servers: Server[] | undefined + + constructor( + private root: string + ) {} + + public getSpecModel(): Server[] { + if (this.servers == null) { + this.servers = this._doSeverRetrieval() + } + return this.servers + } + + private _doSeverRetrieval(): Server[] { + const base = resolve(this.root, 'servers') + return [] // TODO + } + +}