diff --git a/README.md b/README.md index 350452d..a47bbb0 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Generate a distribution.json for Helios. 1. Clone the repository 2. Install the dependencies (`npm i`) -3. Create a `.env` file at the root directory and set the required values. +3. Create a `.env` file at the root directory of the cloned folder and set the required values. Example ```properties diff --git a/package-lock.json b/package-lock.json index 69395e8..2254b7b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -60,15 +60,15 @@ "dev": true }, "@types/node": { - "version": "12.12.25", - "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.25.tgz", - "integrity": "sha512-nf1LMGZvgFX186geVZR1xMZKKblJiRfiASTHw85zED2kI1yDKHDwTKMdkaCbTlXoRKlGKaDfYywt+V0As30q3w==", + "version": "12.12.26", + "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.26.tgz", + "integrity": "sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA==", "dev": true }, "@types/yargs": { - "version": "15.0.1", - "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.1.tgz", - "integrity": "sha512-sYlwNU7zYi6eZbMzFvG6eHD7VsEvFdoDtlD7eI1JTg7YNnuguzmiGsc6MPSq5l8n+h21AsNof0je+9sgOe4+dg==", + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/@types/yargs/-/yargs-15.0.3.tgz", + "integrity": "sha512-XCMQRK6kfpNBixHLyHUsGmXrpEmFFxzMrcnSXFMziHd8CoNJo8l16FkHyQq4x+xbM7E2XL83/O78OD8u+iZTdQ==", "dev": true, "requires": { "@types/yargs-parser": "*" @@ -81,12 +81,12 @@ "dev": true }, "@typescript-eslint/eslint-plugin": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.17.0.tgz", - "integrity": "sha512-tg/OMOtPeXlvk0ES8mZzEZ4gd1ruSE03nsKcK+teJhxYv5CPCXK6Mb/OK6NpB4+CqGTHs4MVeoSZXNFqpT1PyQ==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-2.18.0.tgz", + "integrity": "sha512-kuO8WQjV+RCZvAXVRJfXWiJ8iYEtfHlKgcqqqXg9uUkIolEHuUaMmm8/lcO4xwCOtaw6mY0gStn2Lg4/eUXXYQ==", "dev": true, "requires": { - "@typescript-eslint/experimental-utils": "2.17.0", + "@typescript-eslint/experimental-utils": "2.18.0", "eslint-utils": "^1.4.3", "functional-red-black-tree": "^1.0.1", "regexpp": "^3.0.0", @@ -102,32 +102,32 @@ } }, "@typescript-eslint/experimental-utils": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.17.0.tgz", - "integrity": "sha512-2bNf+mZ/3mj5/3CP56v+ldRK3vFy9jOvmCPs/Gr2DeSJh+asPZrhFniv4QmQsHWQFPJFWhFHgkGgJeRmK4m8iQ==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/experimental-utils/-/experimental-utils-2.18.0.tgz", + "integrity": "sha512-J6MopKPHuJYmQUkANLip7g9I82ZLe1naCbxZZW3O2sIxTiq/9YYoOELEKY7oPg0hJ0V/AQ225h2z0Yp+RRMXhw==", "dev": true, "requires": { "@types/json-schema": "^7.0.3", - "@typescript-eslint/typescript-estree": "2.17.0", + "@typescript-eslint/typescript-estree": "2.18.0", "eslint-scope": "^5.0.0" } }, "@typescript-eslint/parser": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.17.0.tgz", - "integrity": "sha512-k1g3gRQ4fwfJoIfgUpz78AovicSWKFANmvTfkAHP24MgJHjWfZI6ya7tsQZt1sLczvP4G9BE5G5MgADHdmJB/w==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-2.18.0.tgz", + "integrity": "sha512-SJJPxFMEYEWkM6pGfcnjLU+NJIPo+Ko1QrCBL+i0+zV30ggLD90huEmMMhKLHBpESWy9lVEeWlQibweNQzyc+A==", "dev": true, "requires": { "@types/eslint-visitor-keys": "^1.0.0", - "@typescript-eslint/experimental-utils": "2.17.0", - "@typescript-eslint/typescript-estree": "2.17.0", + "@typescript-eslint/experimental-utils": "2.18.0", + "@typescript-eslint/typescript-estree": "2.18.0", "eslint-visitor-keys": "^1.1.0" } }, "@typescript-eslint/typescript-estree": { - "version": "2.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.17.0.tgz", - "integrity": "sha512-g0eVRULGnEEUakxRfJO0s0Hr1LLQqsI6OrkiCLpdHtdJJek+wyd8mb00vedqAoWldeDcOcP8plqw8/jx9Gr3Lw==", + "version": "2.18.0", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-2.18.0.tgz", + "integrity": "sha512-gVHylf7FDb8VSi2ypFuEL3hOtoC4HkZZ5dOjXvVjoyKdRrvXAOPSzpNRnKMfaUUEiSLP8UF9j9X9EDLxC0lfZg==", "dev": true, "requires": { "debug": "^4.1.1", @@ -2090,9 +2090,9 @@ } }, "rimraf": { - "version": "3.0.0", - "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.0.tgz", - "integrity": "sha512-NDGVxTsjqfunkds7CqsOiEnxln4Bo7Nddl3XhS4pXg5OzwkLqJ971ZVAAnB+DDLnF76N+VnDEiBHaVV8I06SUg==", + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.1.tgz", + "integrity": "sha512-IQ4ikL8SjBiEDZfk+DFVwqRK8md24RWMEJkdSlgNLkyyAImcjf8SWvU1qFMDOb4igBClbTQ/ugPqXcRwdFTxZw==", "dev": true, "requires": { "glob": "^7.1.3" diff --git a/package.json b/package.json index 9be928a..53e1762 100644 --- a/package.json +++ b/package.json @@ -28,12 +28,12 @@ "devDependencies": { "@types/adm-zip": "^0.4.32", "@types/fs-extra": "^8.0.1", - "@types/node": "^12.12.25", - "@types/yargs": "^15.0.1", - "@typescript-eslint/eslint-plugin": "^2.17.0", - "@typescript-eslint/parser": "^2.17.0", + "@types/node": "^12.12.26", + "@types/yargs": "^15.0.3", + "@typescript-eslint/eslint-plugin": "^2.18.0", + "@typescript-eslint/parser": "^2.18.0", "eslint": "^6.8.0", - "rimraf": "^3.0.0", + "rimraf": "^3.0.1", "typescript": "^3.7.5" }, "dependencies": { @@ -43,6 +43,6 @@ "fs-extra": "^8.1.0", "toml": "^3.0.0", "yargs": "^15.1.0", - "helios-distribution-types": "1.0.0-pre.1" + "helios-distribution-types": "^1.0.0-pre.1" } } diff --git a/src/model/struct/model/module/file.struct.ts b/src/model/struct/model/module/file.struct.ts index 9a797d4..9e05e43 100644 --- a/src/model/struct/model/module/file.struct.ts +++ b/src/model/struct/model/module/file.struct.ts @@ -1,9 +1,10 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { Stats } from 'fs' -import { Type } from 'helios-distribution-types' -import { join } from 'path' -import { resolve } from 'url' +import { Type, Module } from 'helios-distribution-types' +import { resolve as resolveURL } from 'url' import { ModuleStructure } from './module.struct' +import { readdir, stat } from 'fs-extra' +import { join, resolve } from 'path' export class MiscFileStructure extends ModuleStructure { @@ -15,6 +16,29 @@ export class MiscFileStructure extends ModuleStructure { super(absoluteRoot, relativeRoot, 'files', baseUrl, Type.File) } + public async getSpecModel(): Promise { + if (this.resolvedModels == null) { + this.resolvedModels = await this.recursiveModuleScan(this.containerDirectory) + } + + return this.resolvedModels + } + + protected async recursiveModuleScan(dir: string): Promise { + let acc: Module[] = [] + const subdirs = await readdir(dir) + for (const file of subdirs) { + const filePath = resolve(dir, file) + const stats = await stat(filePath) + if (stats.isDirectory()) { + acc = acc.concat(await this.recursiveModuleScan(filePath)) + } else { + acc.push(await this.parseModule(file, filePath, stats)) + } + } + return acc + } + protected async getModuleId(name: string, path: string, stats: Stats, buf: Buffer): Promise { return name } @@ -22,10 +46,10 @@ export class MiscFileStructure extends ModuleStructure { return name } protected async getModuleUrl(name: string, path: string, stats: Stats): Promise { - return resolve(this.baseUrl, join(this.relativeRoot, name)) + return resolveURL(this.baseUrl, join(this.relativeRoot, name)) } protected async getModulePath(name: string, path: string, stats: Stats): Promise { - return name + return path.substr(this.containerDirectory.length+1).replace(/\\/g, '/') } } diff --git a/src/model/struct/model/module/module.struct.ts b/src/model/struct/model/module/module.struct.ts index 2d5965b..233b235 100644 --- a/src/model/struct/model/module/module.struct.ts +++ b/src/model/struct/model/module/module.struct.ts @@ -33,6 +33,29 @@ export abstract class ModuleStructure extends BaseModelStructure { protected async abstract getModuleUrl(name: string, path: string, stats: Stats): Promise protected async abstract getModulePath(name: string, path: string, stats: Stats): Promise + protected async parseModule(file: string, filePath: string, stats: Stats): Promise { + const buf = await readFile(filePath) + const mdl: Module = { + id: await this.getModuleId(file, filePath, stats, buf), + name: await this.getModuleName(file, filePath, stats, buf), + type: this.type, + required: { + value: false, + def: false + }, + artifact: { + size: stats.size, + MD5: createHash('md5').update(buf).digest('hex'), + url: await this.getModuleUrl(file, filePath, stats) + } + } + const pth = await this.getModulePath(file, filePath, stats) + if (pth) { + mdl.artifact.path = pth + } + return mdl + } + private async _doModuleRetrieval(): Promise { const accumulator: Module[] = [] @@ -43,26 +66,7 @@ export abstract class ModuleStructure extends BaseModelStructure { const filePath = resolve(this.containerDirectory, file) const stats = await lstat(filePath) if (stats.isFile()) { - const buf = await readFile(filePath) - const mdl: Module = { - id: await this.getModuleId(file, filePath, stats, buf), - name: await this.getModuleName(file, filePath, stats, buf), - type: this.type, - required: { - value: false, - def: false - }, - artifact: { - size: stats.size, - MD5: createHash('md5').update(buf).digest('hex'), - url: await this.getModuleUrl(file, filePath, stats) - } - } - const pth = await this.getModulePath(file, filePath, stats) - if (pth) { - mdl.artifact.path = pth - } - accumulator.push(mdl) + accumulator.push(await this.parseModule(file, filePath, stats)) } } }