Skip to content

Commit

Permalink
Convert project to ESM (#58)
Browse files Browse the repository at this point in the history
* Convert to ESM, enforce file single naming convention.

* Update fs-extra esm usage.

* Fix minimatch import.

* fixes

* triple-beam issue is finally fixed.
  • Loading branch information
dscalzi committed Mar 17, 2023
1 parent 8296746 commit b55b7af
Show file tree
Hide file tree
Showing 34 changed files with 492 additions and 519 deletions.
600 changes: 308 additions & 292 deletions package-lock.json

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "nebula",
"version": "0.1.0",
"description": "Utility package to generate a distribution.json for Helios.",
"main": "dist/index.js",
"type": "module",
"exports": "./dist/index.js",
"scripts": {
"clean": "rimraf dist",
"tsc": "tsc",
Expand Down Expand Up @@ -30,28 +31,27 @@
"devDependencies": {
"@types/fs-extra": "^11.0.1",
"@types/luxon": "^3.2.0",
"@types/minimatch": "^5.1.2",
"@types/node": "^18.13.0",
"@types/node": "^18.15.3",
"@types/triple-beam": "^1.3.2",
"@types/yargs": "^17.0.22",
"@typescript-eslint/eslint-plugin": "^5.51.0",
"@typescript-eslint/parser": "^5.51.0",
"eslint": "^8.34.0",
"rimraf": "^4.1.2",
"typescript": "^4.9.5"
"@typescript-eslint/eslint-plugin": "^5.55.0",
"@typescript-eslint/parser": "^5.55.0",
"eslint": "^8.36.0",
"rimraf": "^4.4.0",
"typescript": "^5.0.2"
},
"dependencies": {
"dotenv": "^16.0.3",
"fs-extra": "^11.1.0",
"got": "^11.8.6",
"got": "^12.6.0",
"helios-distribution-types": "^1.1.0",
"luxon": "^3.2.1",
"minimatch": "^6.1.8",
"luxon": "^3.3.0",
"minimatch": "^7.4.2",
"node-stream-zip": "^1.15.0",
"toml": "^3.0.0",
"triple-beam": "^1.3.0",
"ts-json-schema-generator": "^1.2.0",
"winston": "^3.8.2",
"yargs": "^17.6.2"
"yargs": "^17.7.1"
}
}
54 changes: 28 additions & 26 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
/* tslint:disable:no-shadowed-variable */
import dotenv from 'dotenv'
import { writeFile } from 'fs-extra'
import { writeFile } from 'fs/promises'
import { resolve as resolvePath } from 'path'
import { URL } from 'url'
import { inspect } from 'util'
import yargs from 'yargs'
import { DistributionStructure } from './structure/spec_model/Distribution.struct'
import { ServerStructure } from './structure/spec_model/Server.struct'
import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry'
import { VersionUtil } from './util/versionutil'
import { MinecraftVersion } from './util/MinecraftVersion'
import { LoggerUtil } from './util/LoggerUtil'
import { generateSchemas } from './util/SchemaUtil'
import yargs from 'yargs/yargs'
import { Argv, CommandModule } from 'yargs'
import { hideBin } from 'yargs/helpers'
import { DistributionStructure } from './structure/spec_model/Distribution.struct.js'
import { ServerStructure } from './structure/spec_model/Server.struct.js'
import { VersionSegmentedRegistry } from './util/VersionSegmentedRegistry.js'
import { VersionUtil } from './util/VersionUtil.js'
import { MinecraftVersion } from './util/MinecraftVersion.js'
import { LoggerUtil } from './util/LoggerUtil.js'
import { generateSchemas } from './util/SchemaUtil.js'

dotenv.config()

Expand Down Expand Up @@ -41,7 +43,7 @@ function getBaseURL(): string {
return (new URL(baseUrl)).toString()
}

function installLocalOption(yargs: yargs.Argv): yargs.Argv {
function installLocalOption(yargs: Argv): Argv {
return yargs.option('installLocal', {
describe: 'Install the generated distribution to your local Helios data folder.',
type: 'boolean',
Expand All @@ -51,7 +53,7 @@ function installLocalOption(yargs: yargs.Argv): yargs.Argv {
})
}

function discardOutputOption(yargs: yargs.Argv): yargs.Argv {
function discardOutputOption(yargs: Argv): Argv {
return yargs.option('discardOutput', {
describe: 'Delete cached output after it is no longer required. May be useful if disk space is limited.',
type: 'boolean',
Expand All @@ -61,7 +63,7 @@ function discardOutputOption(yargs: yargs.Argv): yargs.Argv {
})
}

function invalidateCacheOption(yargs: yargs.Argv): yargs.Argv {
function invalidateCacheOption(yargs: Argv): Argv {
return yargs.option('invalidateCache', {
describe: 'Invalidate and delete existing caches as they are encountered. Requires fresh cache generation.',
type: 'boolean',
Expand All @@ -71,7 +73,7 @@ function invalidateCacheOption(yargs: yargs.Argv): yargs.Argv {
})
}

// function rootOption(yargs: yargs.Argv) {
// function rootOption(yargs: Argv) {
// return yargs.option('root', {
// describe: 'File structure root.',
// type: 'string',
Expand All @@ -83,7 +85,7 @@ function invalidateCacheOption(yargs: yargs.Argv): yargs.Argv {
// })
// }

// function baseUrlOption(yargs: yargs.Argv) {
// function baseUrlOption(yargs: Argv) {
// return yargs.option('baseUrl', {
// describe: 'Base url of your file host.',
// type: 'string',
Expand All @@ -106,7 +108,7 @@ function invalidateCacheOption(yargs: yargs.Argv): yargs.Argv {
// }

// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
function namePositional(yargs: yargs.Argv) {
function namePositional(yargs: Argv) {
return yargs.option('name', {
describe: 'Distribution index file name.',
type: 'string',
Expand All @@ -117,7 +119,7 @@ function namePositional(yargs: yargs.Argv) {
// -------------
// Init Commands

const initRootCommand: yargs.CommandModule = {
const initRootCommand: CommandModule = {
command: 'root',
describe: 'Generate an empty standard file structure.',
builder: (yargs) => {
Expand All @@ -139,7 +141,7 @@ const initRootCommand: yargs.CommandModule = {
}
}

const initCommand: yargs.CommandModule = {
const initCommand: CommandModule = {
command: 'init',
aliases: ['i'],
describe: 'Base init command.',
Expand All @@ -155,7 +157,7 @@ const initCommand: yargs.CommandModule = {
// -----------------
// Generate Commands

const generateServerCommand: yargs.CommandModule = {
const generateServerCommand: CommandModule = {
command: 'server <id> <version>',
describe: 'Generate a new server configuration.',
builder: (yargs) => {
Expand Down Expand Up @@ -205,7 +207,7 @@ const generateServerCommand: yargs.CommandModule = {
}
}

const generateDistroCommand: yargs.CommandModule = {
const generateDistroCommand: CommandModule = {
command: 'distro [name]',
describe: 'Generate a distribution index from the root file structure.',
builder: (yargs) => {
Expand Down Expand Up @@ -259,7 +261,7 @@ const generateDistroCommand: yargs.CommandModule = {
}
}

const generateSchemasCommand: yargs.CommandModule = {
const generateSchemasCommand: CommandModule = {
command: 'schemas',
describe: 'Generate json schemas.',
handler: async (argv) => {
Expand All @@ -278,7 +280,7 @@ const generateSchemasCommand: yargs.CommandModule = {
}
}

const generateCommand: yargs.CommandModule = {
const generateCommand: CommandModule = {
command: 'generate',
aliases: ['g'],
describe: 'Base generate command.',
Expand All @@ -293,7 +295,7 @@ const generateCommand: yargs.CommandModule = {
}
}

const validateCommand: yargs.CommandModule = {
const validateCommand: CommandModule = {
command: 'validate [name]',
describe: 'Validate a distribution.json against the spec.',
builder: (yargs) => {
Expand All @@ -304,7 +306,7 @@ const validateCommand: yargs.CommandModule = {
}
}

const latestForgeCommand: yargs.CommandModule = {
const latestForgeCommand: CommandModule = {
command: 'latest-forge <version>',
describe: 'Get the latest version of forge.',
handler: async (argv) => {
Expand All @@ -316,7 +318,7 @@ const latestForgeCommand: yargs.CommandModule = {
}
}

const recommendedForgeCommand: yargs.CommandModule = {
const recommendedForgeCommand: CommandModule = {
command: 'recommended-forge <version>',
describe: 'Get the recommended version of forge. Returns latest if there is no recommended build.',
handler: async (argv) => {
Expand All @@ -341,7 +343,7 @@ const recommendedForgeCommand: yargs.CommandModule = {
}
}

const testCommand: yargs.CommandModule = {
const testCommand: CommandModule = {
command: 'test <mcVer> <forgeVer>',
describe: 'Validate a distribution.json against the spec.',
builder: (yargs) => {
Expand All @@ -362,7 +364,7 @@ const testCommand: yargs.CommandModule = {

// Registering yargs configuration.
// tslint:disable-next-line:no-unused-expression
yargs
yargs(hideBin(process.argv))
.version(false)
.scriptName('')
.command(initCommand)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { McModInfo } from './mcmodinfo'
import { McModInfo } from './McModInfo.js'

export interface McModInfoList {

Expand Down
6 changes: 3 additions & 3 deletions src/resolver/baseresolver.ts → src/resolver/BaseResolver.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Module } from 'helios-distribution-types'
import { VersionSegmented } from '../util/VersionSegmented'
import { Resolver } from './resolver'
import { MinecraftVersion } from '../util/MinecraftVersion'
import { VersionSegmented } from '../util/VersionSegmented.js'
import { Resolver } from './Resolver.js'
import { MinecraftVersion } from '../util/MinecraftVersion.js'

export abstract class BaseResolver implements Resolver, VersionSegmented {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import StreamZip from 'node-stream-zip'
import { createHash } from 'crypto'
import { Stats } from 'fs-extra'
import { Stats } from 'fs'
import { Artifact } from 'helios-distribution-types'
import { RepoStructure } from '../../structure/repo/Repo.struct'
import { BaseResolver } from '../baseresolver'
import { MinecraftVersion } from '../../util/MinecraftVersion'
import { VersionUtil } from '../../util/versionutil'
import { LoggerUtil } from '../../util/LoggerUtil'
import { RepoStructure } from '../../structure/repo/Repo.struct.js'
import { BaseResolver } from '../BaseResolver.js'
import { MinecraftVersion } from '../../util/MinecraftVersion.js'
import { VersionUtil } from '../../util/VersionUtil.js'
import { LoggerUtil } from '../../util/LoggerUtil.js'

export abstract class ForgeResolver extends BaseResolver {

Expand Down
19 changes: 10 additions & 9 deletions src/resolver/forge/adapter/ForgeGradle2.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { createHash } from 'crypto'
import { copy, lstat, mkdirs, pathExists, readFile, remove } from 'fs-extra'
import { copy, mkdirs, pathExists, remove } from 'fs-extra/esm'
import { lstat, readFile } from 'fs/promises'
import { Module, Type } from 'helios-distribution-types'
import { basename, join } from 'path'
import { VersionManifestFG2 } from '../../../model/forge/VersionManifestFG2'
import { LibRepoStructure } from '../../../structure/repo/LibRepo.struct'
import { MavenUtil } from '../../../util/maven'
import { PackXZExtractWrapper } from '../../../util/java/PackXZExtractWrapper'
import { VersionUtil } from '../../../util/versionutil'
import { ForgeResolver } from '../forge.resolver'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
import { VersionManifestFG2 } from '../../../model/forge/VersionManifestFG2.js'
import { LibRepoStructure } from '../../../structure/repo/LibRepo.struct.js'
import { MavenUtil } from '../../../util/MavenUtil.js'
import { PackXZExtractWrapper } from '../../../util/java/PackXZExtractWrapper.js'
import { VersionUtil } from '../../../util/VersionUtil.js'
import { ForgeResolver } from '../Forge.resolver.js'
import { MinecraftVersion } from '../../../util/MinecraftVersion.js'
import { LoggerUtil } from '../../../util/LoggerUtil.js'

type ArrayElement<A> = A extends readonly (infer T)[] ? T : never

Expand Down
21 changes: 11 additions & 10 deletions src/resolver/forge/adapter/ForgeGradle3.resolver.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ForgeResolver } from '../forge.resolver'
import { MinecraftVersion } from '../../../util/MinecraftVersion'
import { LoggerUtil } from '../../../util/LoggerUtil'
import { VersionUtil } from '../../../util/versionutil'
import { ForgeResolver } from '../Forge.resolver.js'
import { MinecraftVersion } from '../../../util/MinecraftVersion.js'
import { LoggerUtil } from '../../../util/LoggerUtil.js'
import { VersionUtil } from '../../../util/VersionUtil.js'
import { Module, Type } from 'helios-distribution-types'
import { LibRepoStructure } from '../../../structure/repo/LibRepo.struct'
import { pathExists, remove, mkdirs, copy, writeFile, readFile, lstat, writeJson, exists } from 'fs-extra'
import { LibRepoStructure } from '../../../structure/repo/LibRepo.struct.js'
import { pathExists, remove, mkdirs, copy, writeJson } from 'fs-extra/esm'
import { lstat, readFile, writeFile } from 'fs/promises'
import { join, basename, dirname } from 'path'
import { spawn } from 'child_process'
import { JavaUtil } from '../../../util/java/javautil'
import { VersionManifestFG3 } from '../../../model/forge/VersionManifestFG3'
import { MavenUtil } from '../../../util/maven'
import { JavaUtil } from '../../../util/java/JavaUtil.js'
import { VersionManifestFG3 } from '../../../model/forge/VersionManifestFG3.js'
import { MavenUtil } from '../../../util/MavenUtil.js'
import { createHash } from 'crypto'

interface GeneratedFile {
Expand Down Expand Up @@ -339,7 +340,7 @@ export class ForgeGradle3Adapter extends ForgeResolver {
private async verifyInstallerRan(installerOutputDir: string): Promise<void> {
const versionManifestPath = this.getVersionManifestPath(installerOutputDir)

if(!await exists(versionManifestPath)) {
if(!await pathExists(versionManifestPath)) {
await remove(installerOutputDir)
throw new Error(`Forge was either not installed or installed to the wrong location. When the forge installer opens, you MUST set the installation directory to ${installerOutputDir}`)
}
Expand Down
6 changes: 3 additions & 3 deletions src/structure/BaseFileStructure.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mkdirs } from 'fs-extra'
import { mkdirs } from 'fs-extra/esm'
import { join, resolve } from 'path'
import { FileStructure } from './FileStructure'
import { FileStructure } from './FileStructure.js'
import { Logger } from 'winston'
import { LoggerUtil } from '../util/LoggerUtil'
import { LoggerUtil } from '../util/LoggerUtil.js'

export abstract class BaseFileStructure implements FileStructure {

Expand Down
9 changes: 5 additions & 4 deletions src/structure/repo/BaseMavenRepo.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import got from 'got'
import { createWriteStream, mkdirs, pathExists } from 'fs-extra'
import { mkdirs, pathExists } from 'fs-extra/esm'
import { createWriteStream } from 'fs'
import { dirname, join, resolve } from 'path'
import { URL } from 'url'
import { MavenUtil } from '../../util/maven'
import { BaseFileStructure } from '../BaseFileStructure'
import { LoggerUtil } from '../../util/LoggerUtil'
import { MavenUtil } from '../../util/MavenUtil.js'
import { BaseFileStructure } from '../BaseFileStructure.js'
import { LoggerUtil } from '../../util/LoggerUtil.js'

export abstract class BaseMavenRepo extends BaseFileStructure {

Expand Down
2 changes: 1 addition & 1 deletion src/structure/repo/LibRepo.struct.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BaseMavenRepo } from './BaseMavenRepo'
import { BaseMavenRepo } from './BaseMavenRepo.js'

export class LibRepoStructure extends BaseMavenRepo {

Expand Down
8 changes: 4 additions & 4 deletions src/structure/repo/Repo.struct.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { mkdirs } from 'fs-extra'
import { mkdirs } from 'fs-extra/esm'
import { join } from 'path'
import { BaseFileStructure } from '../BaseFileStructure'
import { LibRepoStructure } from './LibRepo.struct'
import { VersionRepoStructure } from './VersionRepo.struct'
import { BaseFileStructure } from '../BaseFileStructure.js'
import { LibRepoStructure } from './LibRepo.struct.js'
import { VersionRepoStructure } from './VersionRepo.struct.js'

export class RepoStructure extends BaseFileStructure {

Expand Down
4 changes: 2 additions & 2 deletions src/structure/repo/VersionRepo.struct.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { join } from 'path'
import { URL } from 'url'
import { BaseFileStructure } from '../BaseFileStructure'
import { MinecraftVersion } from '../../util/MinecraftVersion'
import { BaseFileStructure } from '../BaseFileStructure.js'
import { MinecraftVersion } from '../../util/MinecraftVersion.js'

export class VersionRepoStructure extends BaseFileStructure {

Expand Down
4 changes: 2 additions & 2 deletions src/structure/spec_model/BaseModel.struct.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BaseFileStructure } from '../BaseFileStructure'
import { SpecModelStructure } from './SpecModelStructure'
import { BaseFileStructure } from '../BaseFileStructure.js'
import { SpecModelStructure } from './SpecModelStructure.js'

export abstract class BaseModelStructure<T> extends BaseFileStructure implements SpecModelStructure<T[]> {

Expand Down
Loading

0 comments on commit b55b7af

Please sign in to comment.