Implement recursive scan for File modules.
Ex. store resourcepacks at /files/resourcepacks/MyPack.zip Added as a module with destination path resourcepacks/MyPack.zip
This commit is contained in:
@@ -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
|
||||
|
||||
50
package-lock.json
generated
50
package-lock.json
generated
@@ -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"
|
||||
|
||||
12
package.json
12
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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Module[]> {
|
||||
if (this.resolvedModels == null) {
|
||||
this.resolvedModels = await this.recursiveModuleScan(this.containerDirectory)
|
||||
}
|
||||
|
||||
return this.resolvedModels
|
||||
}
|
||||
|
||||
protected async recursiveModuleScan(dir: string): Promise<Module[]> {
|
||||
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<string> {
|
||||
return name
|
||||
}
|
||||
@@ -22,10 +46,10 @@ export class MiscFileStructure extends ModuleStructure {
|
||||
return name
|
||||
}
|
||||
protected async getModuleUrl(name: string, path: string, stats: Stats): Promise<string> {
|
||||
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<string | null> {
|
||||
return name
|
||||
return path.substr(this.containerDirectory.length+1).replace(/\\/g, '/')
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,16 +33,7 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
|
||||
protected async abstract getModuleUrl(name: string, path: string, stats: Stats): Promise<string>
|
||||
protected async abstract getModulePath(name: string, path: string, stats: Stats): Promise<string | null>
|
||||
|
||||
private async _doModuleRetrieval(): Promise<Module[]> {
|
||||
|
||||
const accumulator: Module[] = []
|
||||
|
||||
if (await pathExists(this.containerDirectory)) {
|
||||
const files = await readdir(this.containerDirectory)
|
||||
for (const file of files) {
|
||||
const filePath = resolve(this.containerDirectory, file)
|
||||
const stats = await lstat(filePath)
|
||||
if (stats.isFile()) {
|
||||
protected async parseModule(file: string, filePath: string, stats: Stats): Promise<Module> {
|
||||
const buf = await readFile(filePath)
|
||||
const mdl: Module = {
|
||||
id: await this.getModuleId(file, filePath, stats, buf),
|
||||
@@ -62,7 +53,20 @@ export abstract class ModuleStructure extends BaseModelStructure<Module> {
|
||||
if (pth) {
|
||||
mdl.artifact.path = pth
|
||||
}
|
||||
accumulator.push(mdl)
|
||||
return mdl
|
||||
}
|
||||
|
||||
private async _doModuleRetrieval(): Promise<Module[]> {
|
||||
|
||||
const accumulator: Module[] = []
|
||||
|
||||
if (await pathExists(this.containerDirectory)) {
|
||||
const files = await readdir(this.containerDirectory)
|
||||
for (const file of files) {
|
||||
const filePath = resolve(this.containerDirectory, file)
|
||||
const stats = await lstat(filePath)
|
||||
if (stats.isFile()) {
|
||||
accumulator.push(await this.parseModule(file, filePath, stats))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user