-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add consistent use of path.join and refactor path names
- Loading branch information
Showing
8 changed files
with
105 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import oclifPrettierConfig from "@oclif/prettier-config"; | ||
import oclifPrettierConfig from '@oclif/prettier-config'; | ||
|
||
export default { | ||
...oclifPrettierConfig, | ||
semi: true | ||
} | ||
semi: true, | ||
arrowParens: 'avoid', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#!/usr/bin/env -S node --import tsx/esm | ||
#!/usr/bin/env -S npx tsx | ||
|
||
import {execute} from '@oclif/core'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,56 @@ | ||
import {Command, Flags} from '@oclif/core'; | ||
import path from 'node:path'; | ||
import * as YAML from 'yaml'; | ||
|
||
import {getLatestManifest, getLatestVersion} from '../../manifest.js'; | ||
import {Paths, packagePaths} from '../../paths.js'; | ||
import {PackageRepoIndexItem} from '../../types/glasskube/index.js'; | ||
import {PackageIndex} from '../../types/types.js'; | ||
import {getFoldersIn, write} from '../../utils/io.js'; | ||
import {buildPath} from '../../utils/path.js'; | ||
|
||
export default class Index extends Command { | ||
static override readonly aliases = ['update:index']; | ||
|
||
static override readonly description = 'updates packages index'; | ||
|
||
static override readonly description = 'updates the packages index'; | ||
static override readonly examples = ['<%= config.bin %> <%= command.id %>']; | ||
|
||
static override readonly flags = { | ||
// flag with no value (-c, --create-version) | ||
'dry-run': Flags.boolean({description: 'do not make any changes'}), | ||
// flag to determine the base folder | ||
source: Flags.string({char: 's', description: 'packages context'}), | ||
source: Flags.string({char: 's', default: '.', description: 'packages context'}), | ||
}; | ||
|
||
public async run(): Promise<void> { | ||
private paths!: Paths; | ||
|
||
protected override async init(): Promise<void> { | ||
const {flags} = await this.parse(Index); | ||
this.paths = packagePaths(path.join(flags.source, 'packages')); | ||
} | ||
|
||
const {source} = flags; | ||
const packageFolders = await getFoldersIn(buildPath('packages', source)); | ||
public override async run(): Promise<void> { | ||
const {flags} = await this.parse(Index); | ||
const packageFolders = await getFoldersIn(this.paths.dirName()); | ||
|
||
const index = { | ||
packages: await Promise.all(packageFolders.map((it) => this.createPackageIndexItem(it, source))), | ||
} as PackageIndex; | ||
const index: PackageIndex = { | ||
packages: await Promise.all(packageFolders.map(it => this.createPackageIndexItem(it))), | ||
}; | ||
|
||
if (!flags['dry-run']) { | ||
this.log('will rewrite index'); | ||
await write(buildPath('index.yaml', source), YAML.stringify(index)); | ||
const indexPath = this.paths.indexYaml(); | ||
this.log('will rewrite index at', indexPath); | ||
await write(indexPath, YAML.stringify(index)); | ||
this.log('index rewritten'); | ||
} | ||
} | ||
|
||
private async createPackageIndexItem(packageFolder: string, source?: string) { | ||
const latestVersion = await getLatestVersion(packageFolder, source); | ||
const packageManifest = await getLatestManifest(packageFolder, source); | ||
private async createPackageIndexItem(packageFolder: string): Promise<PackageRepoIndexItem> { | ||
const packagePaths = this.paths.package(packageFolder); | ||
const latestVersion = await getLatestVersion(packagePaths); | ||
const packageManifest = await getLatestManifest(packagePaths); | ||
return { | ||
name: packageFolder, | ||
// eslint-disable-next-line perfectionist/sort-objects | ||
iconUrl: packageManifest.iconUrl, | ||
latestVersion: latestVersion.raw, | ||
name: packageFolder, | ||
shortDescription: packageManifest.shortDescription, | ||
} as PackageRepoIndexItem; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,21 @@ | ||
import {SemVer} from 'semver'; | ||
|
||
import {PackagePaths} from './paths.js'; | ||
import {PackageVersions} from './types/types.js'; | ||
import {parseYaml, read} from './utils/io.js'; | ||
|
||
export async function getPackageVersions(packageName: string, source?: string) { | ||
const versionsContent = await read(`${source}packages/${packageName}/versions.yaml`); | ||
export async function getPackageVersions(pkg: PackagePaths) { | ||
const versionsContent = await read(pkg.versionsYaml()); | ||
return parseYaml<PackageVersions>(versionsContent); | ||
} | ||
|
||
export async function getBuildNumbers(version: SemVer, versions: PackageVersions) { | ||
return versions.versions | ||
.filter((it) => version.compare(it.version) === 0) | ||
.map((it) => Number(new SemVer(it.version).build ?? 1)); | ||
.filter(it => version.compare(it.version) === 0) | ||
.map(it => Number(new SemVer(it.version).build ?? 1)); | ||
} | ||
|
||
export async function getNextBuildNumber(appVersion: SemVer, packageName: string, source?: string) { | ||
const packageVersions = await getPackageVersions(packageName, source); | ||
export async function getNextBuildNumber(appVersion: SemVer, pkg: PackagePaths) { | ||
const packageVersions = await getPackageVersions(pkg); | ||
return Math.max(0, ...(await getBuildNumbers(appVersion, packageVersions))) + 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import path from 'node:path'; | ||
|
||
type StringSupplier = () => string; | ||
type DirName = {readonly dirName: StringSupplier}; | ||
type IndexYaml = {readonly indexYaml: StringSupplier}; | ||
type VersionsYaml = {readonly versionsYaml: StringSupplier}; | ||
type ManifestYaml = {readonly packageYaml: StringSupplier}; | ||
export type PackageVersionPaths = DirName & ManifestYaml; | ||
type WithPackageVersion = {readonly version: (version: string) => PackageVersionPaths}; | ||
export type PackagePaths = DirName & VersionsYaml & ManifestYaml & WithPackageVersion; | ||
type WithPackage = {readonly package: (name: string) => PackagePaths}; | ||
export type Paths = DirName & IndexYaml & WithPackage; | ||
|
||
export function packagePaths(base: string): Paths { | ||
return { | ||
dirName: () => base, | ||
indexYaml: () => path.join(base, 'index.yaml'), | ||
package: (name: string) => ({ | ||
dirName: () => path.join(base, name), | ||
packageYaml: () => path.join(base, name, 'package.yaml'), | ||
version: (version: string) => ({ | ||
dirName: () => path.join(base, name, version), | ||
packageYaml: () => path.join(base, name, version, 'package.yaml'), | ||
}), | ||
versionsYaml: () => path.join(base, name, 'versions.yaml'), | ||
}), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters