@basemaps/cli 7.16.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +4 -28
  2. package/build/cli/bin.js +9 -2
  3. package/build/cli/bin.js.map +1 -1
  4. package/build/cli/index.d.ts +245 -4
  5. package/build/cli/index.js +11 -19
  6. package/build/cli/index.js.map +1 -1
  7. package/package.json +6 -27
  8. package/build/cli/__tests__/util.test.d.ts +0 -1
  9. package/build/cli/__tests__/util.test.js +0 -15
  10. package/build/cli/__tests__/util.test.js.map +0 -1
  11. package/build/cli/config/action.bundle.assets.d.ts +0 -14
  12. package/build/cli/config/action.bundle.assets.js +0 -111
  13. package/build/cli/config/action.bundle.assets.js.map +0 -1
  14. package/build/cli/config/action.bundle.d.ts +0 -12
  15. package/build/cli/config/action.bundle.js +0 -76
  16. package/build/cli/config/action.bundle.js.map +0 -1
  17. package/build/cli/config/action.import.d.ts +0 -59
  18. package/build/cli/config/action.import.js +0 -378
  19. package/build/cli/config/action.import.js.map +0 -1
  20. package/build/cli/config/config.diff.d.ts +0 -27
  21. package/build/cli/config/config.diff.js +0 -146
  22. package/build/cli/config/config.diff.js.map +0 -1
  23. package/build/cli/config/config.update.d.ts +0 -24
  24. package/build/cli/config/config.update.js +0 -115
  25. package/build/cli/config/config.update.js.map +0 -1
  26. package/build/cli/folder.d.ts +0 -4
  27. package/build/cli/folder.js +0 -17
  28. package/build/cli/folder.js.map +0 -1
  29. package/build/cli/server/action.serve.d.ts +0 -11
  30. package/build/cli/server/action.serve.js +0 -69
  31. package/build/cli/server/action.serve.js.map +0 -1
  32. package/build/cli/util.d.ts +0 -23
  33. package/build/cli/util.js +0 -136
  34. package/build/cli/util.js.map +0 -1
package/README.md CHANGED
@@ -12,34 +12,10 @@ To install
12
12
  npm i @basemaps/cli
13
13
  ```
14
14
 
15
- ## Usage -- Bundle
15
+ ## Usage -- Config
16
16
 
17
- Bundle config files into config bundle json from a given config path. This is mainly use for [linz/basemaps-config](https://github.com/linz/basemaps-config) CICD process to bundle all the individual config json files into a single JSON bundle.
17
+ Config clis in @basemap/cli-config
18
18
 
19
19
  ```bash
20
- ./bin/bmc.js bundle --config config/ --assets assets/asset.tar --output config.json
21
- ```
22
-
23
- ## Usage -- Import
24
-
25
- Import all configs from a bundled config.json into dynamo db from a given config path. This is mainly use for [linz/basemaps-config](https://github.com/linz/basemaps-config) repository ci/cd process to deploy the config changes into DynamoDB.
26
-
27
- ```bash
28
- ./bin/bmc.js import --config config.json --commit
29
- ```
30
-
31
- ## Usage -- Create Config
32
-
33
- Create a individual config.json from a path of imagery for Basemaps to load as standalone server to view them. This is mainly used for the preview images for the Basemaps imagery import process.
34
-
35
- ```bash
36
- ./bin/bmc.js create-config --path s3://..../images/*.tiff --title image_title --commit
37
- ```
38
-
39
- ## Usage -- Overview
40
-
41
- Create a overview tar file of tiles from the given of imagery. This create low zoom level tiles for the individual imagery and significantly improve the performance of serving individual imagery by pre-rendering and saving the tiles instead of rendering them on the fly.
42
-
43
- ```bash
44
- ./bin/bmc.js create-overview --config s3://..../images/*.tiff --output overview/overviews.tar.co
45
- ```
20
+ ./bin/bmc.js config --help
21
+ ```
package/build/cli/bin.js CHANGED
@@ -1,4 +1,11 @@
1
1
  Error.stackTraceLimit = 100;
2
- import { BasemapsConfigCommandLine } from './index.js';
3
- new BasemapsConfigCommandLine().run();
2
+ import { LogConfig } from '@basemaps/shared';
3
+ import { run } from 'cmd-ts';
4
+ import { Cli } from './index.js';
5
+ run(Cli, process.argv.slice(2)).catch((err) => {
6
+ const logger = LogConfig.get();
7
+ logger.fatal({ err }, 'Command:Failed');
8
+ // Give the logger some time to flush before exiting
9
+ setTimeout(() => process.exit(1), 25);
10
+ });
4
11
  //# sourceMappingURL=bin.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":"AAAA,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC;AAC5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAEvD,IAAI,yBAAyB,EAAE,CAAC,GAAG,EAAE,CAAC"}
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../../src/cli/bin.ts"],"names":[],"mappings":"AAAA,KAAK,CAAC,eAAe,GAAG,GAAG,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAEjC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;IAC5C,MAAM,MAAM,GAAG,SAAS,CAAC,GAAG,EAAE,CAAC;IAC/B,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,EAAE,gBAAgB,CAAC,CAAC;IAExC,oDAAoD;IACpD,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACxC,CAAC,CAAC,CAAC"}
@@ -1,5 +1,246 @@
1
1
  #!/usr/bin/env node
2
- import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
3
- export declare class BasemapsConfigCommandLine extends BaseCommandLine {
4
- constructor();
5
- }
2
+ export declare const Cli: Partial<import("cmd-ts/dist/cjs/argparser.js").Register> & {
3
+ parse(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<{
4
+ command: "config";
5
+ args: {
6
+ command: "bundle-assets";
7
+ args: {
8
+ assets: string;
9
+ output: string;
10
+ verbose: boolean;
11
+ extraVerbose: boolean;
12
+ };
13
+ } | {
14
+ command: "bundle";
15
+ args: {
16
+ config: string;
17
+ output: string;
18
+ assets: string | undefined;
19
+ cache: string | undefined;
20
+ verbose: boolean;
21
+ extraVerbose: boolean;
22
+ };
23
+ } | {
24
+ command: "create-config";
25
+ args: {
26
+ target: URL | undefined;
27
+ concurrency: number;
28
+ host: URL | undefined;
29
+ path: URL;
30
+ verbose: boolean;
31
+ extraVerbose: boolean;
32
+ };
33
+ } | {
34
+ command: "import";
35
+ args: {
36
+ config: string;
37
+ output: string;
38
+ target: string | undefined;
39
+ commit: boolean;
40
+ verbose: boolean;
41
+ extraVerbose: boolean;
42
+ };
43
+ };
44
+ } | {
45
+ command: "cogify";
46
+ args: {
47
+ command: "cover";
48
+ args: {
49
+ target: URL;
50
+ cutline: URL | undefined;
51
+ cutlineBlend: number;
52
+ paths: URL[];
53
+ preset: string;
54
+ tileMatrix: string;
55
+ baseZoomOffset: number | undefined;
56
+ requireStacCollection: boolean;
57
+ background: import("@basemaps/config").Rgba | undefined;
58
+ verbose: boolean;
59
+ extraVerbose: boolean;
60
+ };
61
+ } | {
62
+ command: "create";
63
+ args: {
64
+ path: URL[];
65
+ force: boolean;
66
+ concurrency: number;
67
+ docker: boolean;
68
+ fromFile: URL[] | undefined;
69
+ verbose: boolean;
70
+ extraVerbose: boolean;
71
+ };
72
+ } | {
73
+ command: "validate";
74
+ args: {
75
+ concurrency: number;
76
+ tiffs: URL[];
77
+ verbose: boolean;
78
+ extraVerbose: boolean;
79
+ };
80
+ } | {
81
+ command: "topo";
82
+ args: {
83
+ title: string | undefined;
84
+ target: URL;
85
+ mapSeries: string;
86
+ latestOnly: boolean;
87
+ output: URL | undefined;
88
+ paths: URL[];
89
+ verbose: boolean;
90
+ extraVerbose: boolean;
91
+ };
92
+ };
93
+ }>>;
94
+ } & import("cmd-ts/dist/cjs/helpdoc.js").Named & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Descriptive & import("cmd-ts/dist/cjs/helpdoc.js").Versioned> & import("cmd-ts/dist/cjs/helpdoc.js").PrintHelp & Partial<import("cmd-ts/dist/cjs/helpdoc.js").Versioned> & import("cmd-ts/dist/cjs/argparser.js").Register & import("cmd-ts/dist/cjs/runner.js").Handling<{
95
+ command: "config";
96
+ args: {
97
+ command: "bundle-assets";
98
+ args: {
99
+ assets: string;
100
+ output: string;
101
+ verbose: boolean;
102
+ extraVerbose: boolean;
103
+ };
104
+ } | {
105
+ command: "bundle";
106
+ args: {
107
+ config: string;
108
+ output: string;
109
+ assets: string | undefined;
110
+ cache: string | undefined;
111
+ verbose: boolean;
112
+ extraVerbose: boolean;
113
+ };
114
+ } | {
115
+ command: "create-config";
116
+ args: {
117
+ target: URL | undefined;
118
+ concurrency: number;
119
+ host: URL | undefined;
120
+ path: URL;
121
+ verbose: boolean;
122
+ extraVerbose: boolean;
123
+ };
124
+ } | {
125
+ command: "import";
126
+ args: {
127
+ config: string;
128
+ output: string;
129
+ target: string | undefined;
130
+ commit: boolean;
131
+ verbose: boolean;
132
+ extraVerbose: boolean;
133
+ };
134
+ };
135
+ } | {
136
+ command: "cogify";
137
+ args: {
138
+ command: "cover";
139
+ args: {
140
+ target: URL;
141
+ cutline: URL | undefined;
142
+ cutlineBlend: number;
143
+ paths: URL[];
144
+ preset: string;
145
+ tileMatrix: string;
146
+ baseZoomOffset: number | undefined;
147
+ requireStacCollection: boolean;
148
+ background: import("@basemaps/config").Rgba | undefined;
149
+ verbose: boolean;
150
+ extraVerbose: boolean;
151
+ };
152
+ } | {
153
+ command: "create";
154
+ args: {
155
+ path: URL[];
156
+ force: boolean;
157
+ concurrency: number;
158
+ docker: boolean;
159
+ fromFile: URL[] | undefined;
160
+ verbose: boolean;
161
+ extraVerbose: boolean;
162
+ };
163
+ } | {
164
+ command: "validate";
165
+ args: {
166
+ concurrency: number;
167
+ tiffs: URL[];
168
+ verbose: boolean;
169
+ extraVerbose: boolean;
170
+ };
171
+ } | {
172
+ command: "topo";
173
+ args: {
174
+ title: string | undefined;
175
+ target: URL;
176
+ mapSeries: string;
177
+ latestOnly: boolean;
178
+ output: URL | undefined;
179
+ paths: URL[];
180
+ verbose: boolean;
181
+ extraVerbose: boolean;
182
+ };
183
+ };
184
+ }, {
185
+ command: "config";
186
+ value: {
187
+ command: "bundle-assets";
188
+ value: Promise<void>;
189
+ } | {
190
+ command: "bundle";
191
+ value: Promise<void>;
192
+ } | {
193
+ command: "create-config";
194
+ value: Promise<void>;
195
+ } | {
196
+ command: "import";
197
+ value: Promise<void>;
198
+ };
199
+ } | {
200
+ command: "cogify";
201
+ value: {
202
+ command: "cover";
203
+ value: Promise<void>;
204
+ } | {
205
+ command: "create";
206
+ value: Promise<void>;
207
+ } | {
208
+ command: "validate";
209
+ value: Promise<void>;
210
+ } | {
211
+ command: "topo";
212
+ value: Promise<void>;
213
+ };
214
+ }> & {
215
+ run(context: import("cmd-ts/dist/cjs/argparser.js").ParseContext): Promise<import("cmd-ts/dist/cjs/argparser.js").ParsingResult<{
216
+ command: "config";
217
+ value: {
218
+ command: "bundle-assets";
219
+ value: Promise<void>;
220
+ } | {
221
+ command: "bundle";
222
+ value: Promise<void>;
223
+ } | {
224
+ command: "create-config";
225
+ value: Promise<void>;
226
+ } | {
227
+ command: "import";
228
+ value: Promise<void>;
229
+ };
230
+ } | {
231
+ command: "cogify";
232
+ value: {
233
+ command: "cover";
234
+ value: Promise<void>;
235
+ } | {
236
+ command: "create";
237
+ value: Promise<void>;
238
+ } | {
239
+ command: "validate";
240
+ value: Promise<void>;
241
+ } | {
242
+ command: "topo";
243
+ value: Promise<void>;
244
+ };
245
+ }>>;
246
+ };
@@ -1,21 +1,13 @@
1
1
  #!/usr/bin/env node
2
- import { BaseCommandLine } from '@basemaps/shared/build/cli/base.js';
3
- import { CommandBundleAssets } from './config/action.bundle.assets.js';
4
- import { CommandBundle } from './config/action.bundle.js';
5
- import { CommandImport } from './config/action.import.js';
6
- import { CommandServe } from './server/action.serve.js';
7
- export class BasemapsConfigCommandLine extends BaseCommandLine {
8
- constructor() {
9
- super({
10
- toolFilename: 'bmc',
11
- toolDescription: 'Basemaps config command tools',
12
- });
13
- // Basemaps Config
14
- this.addAction(new CommandBundle());
15
- this.addAction(new CommandBundleAssets());
16
- this.addAction(new CommandImport());
17
- // CICD - Screenshot tests
18
- this.addAction(new CommandServe());
19
- }
20
- }
2
+ import { ConfigCli } from '@basemaps/cli-config';
3
+ import { CogifyCli } from '@basemaps/cli-raster';
4
+ import { subcommands } from 'cmd-ts';
5
+ export const Cli = subcommands({
6
+ name: 'bmc',
7
+ description: 'Basemaps command tools',
8
+ cmds: {
9
+ config: ConfigCli,
10
+ cogify: CogifyCli,
11
+ },
12
+ });
21
13
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAErE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,MAAM,OAAO,yBAA0B,SAAQ,eAAe;IAC5D;QACE,KAAK,CAAC;YACJ,YAAY,EAAE,KAAK;YACnB,eAAe,EAAE,+BAA+B;SACjD,CAAC,CAAC;QAEH,kBAAkB;QAClB,IAAI,CAAC,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QACpC,IAAI,CAAC,SAAS,CAAC,IAAI,mBAAmB,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,SAAS,CAAC,IAAI,aAAa,EAAE,CAAC,CAAC;QAEpC,0BAA0B;QAC1B,IAAI,CAAC,SAAS,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC;IACrC,CAAC;CACF"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AAErC,MAAM,CAAC,MAAM,GAAG,GAAG,WAAW,CAAC;IAC7B,IAAI,EAAE,KAAK;IACX,WAAW,EAAE,wBAAwB;IACrC,IAAI,EAAE;QACJ,MAAM,EAAE,SAAS;QACjB,MAAM,EAAE,SAAS;KAClB;CACF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@basemaps/cli",
3
- "version": "7.16.0",
3
+ "version": "8.0.0",
4
4
  "private": false,
5
5
  "repository": {
6
6
  "type": "git",
@@ -40,31 +40,10 @@
40
40
  "node": ">=16.0.0"
41
41
  },
42
42
  "dependencies": {
43
- "@basemaps/config": "^7.16.0",
44
- "@basemaps/config-loader": "^7.16.0",
45
- "@basemaps/geo": "^7.16.0",
46
- "@basemaps/server": "^7.16.0",
47
- "@basemaps/shared": "^7.16.0",
48
- "@basemaps/tiler": "^7.16.0",
49
- "@basemaps/tiler-sharp": "^7.16.0",
50
- "@chunkd/source-memory": "^11.0.2",
51
- "@cotar/builder": "^6.0.1",
52
- "@cotar/tar": "^6.0.1",
53
- "@linzjs/geojson": "^7.10.0",
54
- "@rushstack/ts-command-line": "^4.3.13",
55
- "ansi-colors": "^4.1.1",
56
- "deep-diff": "^1.0.2",
57
- "node-fetch": "^3.2.3",
58
- "p-limit": "^4.0.0",
59
- "pretty-json-log": "^1.0.0",
60
- "slugify": "^1.6.5",
61
- "zod": "^3.17.3"
62
- },
63
- "devDependencies": {
64
- "@aws-sdk/client-cloudformation": "^3.470.0",
65
- "@aws-sdk/client-cloudfront": "^3.470.0",
66
- "@aws-sdk/client-s3": "^3.470.0",
67
- "@types/deep-diff": "^1.0.1"
43
+ "@basemaps/cli-config": "^8.0.0",
44
+ "@basemaps/cli-raster": "^8.0.0",
45
+ "@basemaps/shared": "^8.0.0",
46
+ "cmd-ts": "^0.13.0"
68
47
  },
69
48
  "publishConfig": {
70
49
  "access": "public"
@@ -72,5 +51,5 @@
72
51
  "files": [
73
52
  "build/"
74
53
  ],
75
- "gitHead": "25fa7659b84a40205ceacda8b2ca5f48e1dc6f7b"
54
+ "gitHead": "852c7c8bcbe06d065de732f23a6ebc2dd6a19cfc"
76
55
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,15 +0,0 @@
1
- import assert from 'node:assert';
2
- import { describe, it } from 'node:test';
3
- import { nameImageryTitle } from '../util.js';
4
- describe('util', () => {
5
- it('nameImageryTitle', () => {
6
- assert.equal(nameImageryTitle('Palmerston-north urban 2016-17 12.125m'), 'palmerston-north_urban_2016-17_12-125m');
7
- assert.equal(nameImageryTitle('Palmerston-north urban 2016-17 12-125'), 'palmerston-north_urban_2016-17_12-125');
8
- assert.equal(nameImageryTitle('Palmerston-north / urban 2016-17 12.125'), 'palmerston-north_urban_2016-17_12-125');
9
- assert.equal(nameImageryTitle('Palmerston.north / urban 2016-17 12.125'), 'palmerston-north_urban_2016-17_12-125');
10
- assert.equal(nameImageryTitle('Manawatū urban 2016-17 12.125m'), 'manawatu_urban_2016-17_12-125m');
11
- assert.equal(nameImageryTitle('ĀāĒēĪīŌōŪū urban 2016-17 12.125m'), 'aaeeiioouu_urban_2016-17_12-125m');
12
- assert.equal(nameImageryTitle('Marlborough / Wellington 0.75m SNC50451 (2004-2005)'), 'marlborough_wellington_0-75m_snc50451_2004-2005');
13
- });
14
- });
15
- //# sourceMappingURL=util.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"util.test.js","sourceRoot":"","sources":["../../../src/cli/__tests__/util.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AAEzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE9C,QAAQ,CAAC,MAAM,EAAE,GAAG,EAAE;IACpB,EAAE,CAAC,kBAAkB,EAAE,GAAG,EAAE;QAC1B,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,wCAAwC,CAAC,EAAE,wCAAwC,CAAC,CAAC;QACnH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,uCAAuC,CAAC,EAAE,uCAAuC,CAAC,CAAC;QACjH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,yCAAyC,CAAC,EAAE,uCAAuC,CAAC,CAAC;QACnH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,yCAAyC,CAAC,EAAE,uCAAuC,CAAC,CAAC;QACnH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,gCAAgC,CAAC,EAAE,gCAAgC,CAAC,CAAC;QACnG,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,kCAAkC,CAAC,EAAE,kCAAkC,CAAC,CAAC;QACvG,MAAM,CAAC,KAAK,CACV,gBAAgB,CAAC,qDAAqD,CAAC,EACvE,iDAAiD,CAClD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,14 +0,0 @@
1
- import { LogType } from '@basemaps/shared';
2
- import { CommandLineAction, CommandLineStringParameter } from '@rushstack/ts-command-line';
3
- import { Readable } from 'stream';
4
- export declare function hashFile(stream: Readable): Promise<string>;
5
- export declare class CommandBundleAssets extends CommandLineAction {
6
- assets: CommandLineStringParameter;
7
- output: CommandLineStringParameter;
8
- constructor();
9
- protected onDefineParameters(): void;
10
- protected onExecute(): Promise<void>;
11
- buildTar(input: URL, output: string, logger: LogType): Promise<string>;
12
- buildTarCo(input: string, output: string, logger: LogType): Promise<string>;
13
- toTarIndex(filename: string, indexFileName: string, logger: LogType): Promise<Buffer>;
14
- }
@@ -1,111 +0,0 @@
1
- import { base58 } from '@basemaps/config';
2
- import { fsa, LogConfig, SourceMemory } from '@basemaps/shared';
3
- import { CotarIndexBuilder, TarReader } from '@cotar/builder';
4
- import { CotarIndex } from '@cotar/core';
5
- import { TarBuilder } from '@cotar/tar';
6
- import { CommandLineAction } from '@rushstack/ts-command-line';
7
- import { createHash } from 'crypto';
8
- import { createReadStream, promises as fs } from 'fs';
9
- const Packing = 25; // Packing factor for the hash map
10
- const MaxSearch = 50; // Max search factor
11
- export async function hashFile(stream) {
12
- return new Promise((resolve, reject) => {
13
- const hash = createHash('sha256');
14
- stream.on('data', (chunk) => hash.update(chunk));
15
- stream.on('end', () => resolve(base58.encode(hash.digest())));
16
- stream.on('error', (err) => reject(err));
17
- });
18
- }
19
- export class CommandBundleAssets extends CommandLineAction {
20
- constructor() {
21
- super({
22
- actionName: 'bundle-assets',
23
- summary: 'Cli tool to create cotar file for the config assets',
24
- documentation: 'Create a cotar file from a directory',
25
- });
26
- Object.defineProperty(this, "assets", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: void 0
31
- });
32
- Object.defineProperty(this, "output", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- }
39
- onDefineParameters() {
40
- this.assets = this.defineStringParameter({
41
- argumentName: 'ASSETS',
42
- parameterLongName: '--assets',
43
- description: 'Paths to the input assets files, must contain assets/sprites/ and assets/fonts.',
44
- });
45
- this.output = this.defineStringParameter({
46
- argumentName: 'OUTPUT',
47
- parameterLongName: '--output',
48
- description: 'Paths of the output co tar file.',
49
- });
50
- }
51
- async onExecute() {
52
- const logger = LogConfig.get();
53
- const assets = this.assets.value;
54
- const output = this.output.value;
55
- if (assets == null || output == null)
56
- throw new Error('Please provide a input and output path');
57
- if (!output.endsWith('.tar.co'))
58
- throw new Error(`Invalid output, needs to be .tar.co :"${output}"`);
59
- logger.info({ input: assets }, 'BundleAssets:Start');
60
- const tarFile = await this.buildTar(fsa.toUrl(assets), output, logger);
61
- const cotarFile = await this.buildTarCo(tarFile, output, logger);
62
- const cotarHash = await hashFile(createReadStream(cotarFile));
63
- await fs.rename(cotarFile, cotarFile.replace('.tar.co', `-${cotarHash}.tar.co`));
64
- logger.info({ output: cotarFile, hash: cotarHash }, 'BundleAssets:Finish');
65
- }
66
- async buildTar(input, output, logger) {
67
- const startTime = Date.now();
68
- const outputTar = output.split('.co')[0];
69
- const tarBuilder = new TarBuilder(outputTar);
70
- const files = await fsa.toArray(fsa.list(input));
71
- // Ensure files are put into the same order
72
- files.sort((a, b) => a.href.localeCompare(b.href));
73
- logger.info({ output: outputTar, files: files.length }, 'Tar:Create');
74
- for (const file of files) {
75
- const filePath = file.href.replace(input.href, '');
76
- if (filePath.startsWith('/'))
77
- filePath.slice(1); // Remove the leading '/'
78
- await tarBuilder.write(decodeURI(filePath), await fsa.read(file));
79
- }
80
- await tarBuilder.close();
81
- logger.info({ output: outputTar, stats: tarBuilder.stats, duration: Date.now() - startTime }, 'Tar:Create:Done');
82
- return outputTar;
83
- }
84
- async buildTarCo(input, output, logger) {
85
- logger.info({ output }, 'Cotar:Create');
86
- const indexFile = input + '.index';
87
- const startTime = Date.now();
88
- const buf = await this.toTarIndex(input, indexFile, logger);
89
- logger.info({ output }, 'Cotar:Create:WriteTar');
90
- await fs.copyFile(input, output);
91
- await fs.appendFile(output, buf);
92
- const duration = Date.now() - startTime;
93
- logger.info({ output, duration }, 'Cotar:Created');
94
- return output;
95
- }
96
- async toTarIndex(filename, indexFileName, logger) {
97
- const fd = await fs.open(filename, 'r');
98
- logger.info({ index: indexFileName }, 'Cotar.Index:Start');
99
- const startTime = Date.now();
100
- const { buffer, count } = await CotarIndexBuilder.create(fd, {
101
- packingFactor: 1 + Packing / 100,
102
- maxSearch: MaxSearch,
103
- });
104
- logger.info({ count, size: buffer.length, duration: Date.now() - startTime }, 'Cotar.Index:Created');
105
- const index = await CotarIndex.create(new SourceMemory('index', buffer));
106
- await TarReader.validate(fd, index);
107
- await fd.close();
108
- return buffer;
109
- }
110
- }
111
- //# sourceMappingURL=action.bundle.assets.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"action.bundle.assets.js","s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,EAAE,GAAG,MAAM,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,aAAa,EAAE,EAAE,mBAAmB,CAAC,CAAC;QAC3D,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,EAAE,EAAE;YAC3D,aAAa,EAAE,CAAC,GAAG,OAAO,GAAG,GAAG;YAChC,SAAS,EAAE,SAAS;SACrB,CAAC,CAAC;QAEH,MAAM,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS,EAAE,EAAE,qBAAqB,CAAC,CAAC;QACrG,MAAM,KAAK,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC;QACzE,MAAM,SAAS,CAAC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,CAAC;QACpC,MAAM,EAAE,CAAC,KAAK,EAAE,CAAC;QACjB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -1,12 +0,0 @@
1
- import { CommandLineAction } from '@rushstack/ts-command-line';
2
- export declare const DefaultConfig = "config/";
3
- export declare const DefaultOutput = "config/config.json";
4
- export declare class CommandBundle extends CommandLineAction {
5
- private config;
6
- private output;
7
- private assets;
8
- private configCache;
9
- constructor();
10
- protected onDefineParameters(): void;
11
- onExecute(): Promise<void>;
12
- }
@@ -1,76 +0,0 @@
1
- import { ConfigJson } from '@basemaps/config-loader';
2
- import { fsa, LogConfig } from '@basemaps/shared';
3
- import { CommandLineAction } from '@rushstack/ts-command-line';
4
- import pLimit from 'p-limit';
5
- export const DefaultConfig = 'config/';
6
- export const DefaultOutput = 'config/config.json';
7
- export class CommandBundle extends CommandLineAction {
8
- constructor() {
9
- super({
10
- actionName: 'bundle',
11
- summary: 'bundle a config json from config files',
12
- documentation: 'Given a path of config files and bundle them into one config json',
13
- });
14
- Object.defineProperty(this, "config", {
15
- enumerable: true,
16
- configurable: true,
17
- writable: true,
18
- value: void 0
19
- });
20
- Object.defineProperty(this, "output", {
21
- enumerable: true,
22
- configurable: true,
23
- writable: true,
24
- value: void 0
25
- });
26
- Object.defineProperty(this, "assets", {
27
- enumerable: true,
28
- configurable: true,
29
- writable: true,
30
- value: void 0
31
- });
32
- Object.defineProperty(this, "configCache", {
33
- enumerable: true,
34
- configurable: true,
35
- writable: true,
36
- value: void 0
37
- });
38
- }
39
- onDefineParameters() {
40
- this.config = this.defineStringParameter({
41
- argumentName: 'CONFIG',
42
- parameterLongName: '--config',
43
- description: 'Path of config files',
44
- });
45
- this.output = this.defineStringParameter({
46
- argumentName: 'OUTPUT',
47
- parameterLongName: '--output',
48
- description: 'Output of the bundle file',
49
- });
50
- this.assets = this.defineStringParameter({
51
- argumentName: 'ASSETS',
52
- parameterLongName: '--assets',
53
- description: 'Add assets location into the config bundle file',
54
- });
55
- this.configCache = this.defineStringParameter({
56
- argumentName: 'CACHE',
57
- parameterLongName: '--cache',
58
- description: 'Location of the config cache to reduce number of requests needed to source file',
59
- });
60
- }
61
- async onExecute() {
62
- const logger = LogConfig.get();
63
- const configUrl = fsa.toUrl(this.config.value ?? DefaultConfig);
64
- const outputUrl = fsa.toUrl(this.output.value ?? DefaultOutput);
65
- const cacheLocation = this.configCache.value ? fsa.toUrl(this.configCache.value) : undefined;
66
- const q = pLimit(25);
67
- const mem = await ConfigJson.fromUrl(configUrl, q, logger, cacheLocation);
68
- if (this.assets.value)
69
- mem.assets = this.assets.value;
70
- const configJson = mem.toJson();
71
- await fsa.write(outputUrl, JSON.stringify(configJson));
72
- logger.info({ path: outputUrl }, 'ConfigBundled');
73
- return;
74
- }
75
- }
76
- //# sourceMappingURL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