From 8923fce9a30ea8da7ef7d6151c10b9def8fc319a Mon Sep 17 00:00:00 2001 From: Victor Engmark Date: Mon, 8 Jan 2024 11:13:24 +1300 Subject: [PATCH] refactor: Remove dead code (#804) #### Motivation Cleans up miscellaneous issues found by JetBrains IDEA. #### Modification - Remove unreferenced example code - Remove unused variables, types, classes - Import type rather than relying on UMD global variable - Wait for writes to finish #### Checklist None of these are applicable. This is just a cleanup. - [ ] Tests updated - [ ] Docs updated - [ ] Issue linked in Title --- .../basemaps-mapsheet/create-mapsheet.ts | 6 ++- src/commands/format/pretty.print.ts | 4 +- .../__test__/tileindex.validate.test.ts | 3 +- .../tileindex-validate/tileindex.validate.ts | 4 -- src/direct/README.md | 13 ----- src/direct/copy.ts | 47 ------------------- src/utils/actions.ts | 2 - src/utils/github.ts | 7 --- 8 files changed, 7 insertions(+), 79 deletions(-) delete mode 100644 src/direct/README.md delete mode 100644 src/direct/copy.ts diff --git a/src/commands/basemaps-mapsheet/create-mapsheet.ts b/src/commands/basemaps-mapsheet/create-mapsheet.ts index 77e33769..3c7793e1 100644 --- a/src/commands/basemaps-mapsheet/create-mapsheet.ts +++ b/src/commands/basemaps-mapsheet/create-mapsheet.ts @@ -86,7 +86,7 @@ export const basemapsCreateMapSheet = command({ const mem = ConfigProviderMemory.fromJson(configJson); const rest = fgb.deserialize(buf) as FeatureCollection; - fsa.write('features.json', JSON.stringify(rest)); + const featuresWritePromise = fsa.write('features.json', JSON.stringify(rest)); const aerial = await mem.TileSet.get('ts_aerial'); if (aerial == null) throw new Error('Invalid config file.'); @@ -95,7 +95,9 @@ export const basemapsCreateMapSheet = command({ const outputs = await createMapSheet(aerial, mem, rest, include, exclude); logger.info({ outputPath }, 'MapSheet:WriteOutput'); - fsa.write(outputPath, JSON.stringify(outputs, null, 2)); + const outputWritePromise = fsa.write(outputPath, JSON.stringify(outputs, null, 2)); + + await Promise.all([featuresWritePromise, outputWritePromise]); }, }); diff --git a/src/commands/format/pretty.print.ts b/src/commands/format/pretty.print.ts index 847d772a..77ade3a0 100644 --- a/src/commands/format/pretty.print.ts +++ b/src/commands/format/pretty.print.ts @@ -75,10 +75,8 @@ export async function formatFile(path: string, target = ''): Promise { * @returns the stringify JSON pretty printed */ export async function prettyPrint(jsonStr: string, config: prettier.Options): Promise { - const formatted = await prettier.format(jsonStr, { + return await prettier.format(jsonStr, { ...config, parser: 'json', }); - - return formatted; } diff --git a/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts b/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts index a353ccb8..97c78a3b 100644 --- a/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts +++ b/src/commands/tileindex-validate/__test__/tileindex.validate.test.ts @@ -3,6 +3,7 @@ import { before, beforeEach, describe, it } from 'node:test'; import { fsa } from '@chunkd/fs'; import { FsMemory } from '@chunkd/source-memory'; +import { FeatureCollection } from 'geojson'; import { MapSheet } from '../../../utils/mapsheet.js'; import { @@ -115,7 +116,7 @@ describe('validate', () => { assert.equal(stub.mock.callCount(), 1); assert.deepEqual(stub.mock.calls[0]?.arguments[0], ['s3://test']); - const outputFileList: GeoJSON.FeatureCollection = await fsa.readJson('/tmp/tile-index-validate/output.geojson'); + const outputFileList: FeatureCollection = await fsa.readJson('/tmp/tile-index-validate/output.geojson'); assert.equal(outputFileList.features.length, 1); const firstFeature = outputFileList.features[0]; assert.equal(firstFeature?.properties?.['tileName'], 'AS21_1000_0101'); diff --git a/src/commands/tileindex-validate/tileindex.validate.ts b/src/commands/tileindex-validate/tileindex.validate.ts index 5c69809c..dc51f649 100644 --- a/src/commands/tileindex-validate/tileindex.validate.ts +++ b/src/commands/tileindex-validate/tileindex.validate.ts @@ -57,10 +57,6 @@ export const TiffLoader = { }, }; -export interface FileList { - tileName: string; - uris: string[]; -} /** * Validate list of tiffs match a LINZ Mapsheet tile index * diff --git a/src/direct/README.md b/src/direct/README.md deleted file mode 100644 index 9492992c..00000000 --- a/src/direct/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# Directly run commands - -These scripts are utility scripts for moving data around inside of LINZ's aws organization - - -[./copy.ts](./copy.ts) - Directly copy files from a source to target location. - - -These commands can be run directly with `esno` - -``` -npx esno src/direct/copy.ts -``` \ No newline at end of file diff --git a/src/direct/copy.ts b/src/direct/copy.ts deleted file mode 100644 index 56c28a4c..00000000 --- a/src/direct/copy.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { fsa } from '@chunkd/fs'; -import { basename } from 'path'; - -import { registerCli } from '../commands/common.js'; -import { s3Fs } from '../fs.register.js'; -import { logger } from '../log.js'; -import { ConcurrentQueue } from '../utils/concurrent.queue.js'; - -const SourceLocation = 's3://linz-topographic-upload/blacha/SNC9990'; -const TargetLocation = 's3://linz-basemaps-source/target-location'; - -s3Fs.credentials.register({ - prefix: SourceLocation, - roleArn: `arn:aws:iam::019359803926:role/internal-user-read`, - flags: 'r', -}); -s3Fs.credentials.register({ - prefix: TargetLocation, - roleArn: `arn:aws:iam::019359803926:role/internal-user-read`, - flags: 'rw', -}); - -const q = new ConcurrentQueue(25); - -async function main(): Promise { - await registerCli({ name: 'direct' }, { verbose: true }); - - for await (const source of fsa.details(SourceLocation)) { - if (source.size === 0) continue; - const sourceFileName = basename(source.path); - const target = fsa.join(TargetLocation, sourceFileName); - - q.push(async () => { - const exists = await fsa.exists(target); - if (exists) { - logger.warn({ source: source.path, target }, 'File:Skipped'); - return; - } - - await fsa.write(target, fsa.stream(source.path)); - logger.info({ source: source.path, target }, 'File:Copied'); - }); - } - await q.join(); -} - -main(); diff --git a/src/utils/actions.ts b/src/utils/actions.ts index 6f0c716d..1a7ea429 100644 --- a/src/utils/actions.ts +++ b/src/utils/actions.ts @@ -1,5 +1,3 @@ -export type Actions = ActionCopy; - export interface ActionCopy { action: 'copy'; parameters: { diff --git a/src/utils/github.ts b/src/utils/github.ts index 9081ceaf..c074c4d0 100644 --- a/src/utils/github.ts +++ b/src/utils/github.ts @@ -4,12 +4,6 @@ import { Api } from '@octokit/plugin-rest-endpoint-methods/dist-types/types.js'; import { logger } from '../log.js'; -export interface Job { - imagery: string; - tileMatrix: string; - content: string; -} - export interface Blob { path: string; mode: '100644'; @@ -34,7 +28,6 @@ export class GithubApi { } isOk = (s: number): boolean => s >= 200 && s <= 299; - isNotFound = (s: number): boolean => s === 404; toRef = (branch: string): string => `heads/${branch}`; /**