@radiantearth/stac-migrate 1.1.0 → 1.3.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 (4) hide show
  1. package/README.md +25 -10
  2. package/bin/cli.js +70 -0
  3. package/migrate.js +926 -816
  4. package/package.json +8 -3
package/README.md CHANGED
@@ -2,10 +2,12 @@
2
2
 
3
3
  A library to update STAC files to the latest version (**1.0.0** at the moment of writing). Supports updating **STAC versions 0.6.0 and later**.
4
4
 
5
- Version of this library: **1.1.0**
5
+ Version of this library: **1.3.0**
6
6
 
7
7
  ## Usage
8
8
 
9
+ ### JavaScript / Node
10
+
9
11
  Add to your project with `npm install @radiantearth/stac-migrate --save`
10
12
 
11
13
  Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
@@ -19,25 +21,38 @@ Import the library: `const Migrate = require('@radiantearth/stac-migrate');`
19
21
 
20
22
  **Note:** All changes will be applied in-place! If you don't want the input object to change, make a deep clone before. If you don't have a library which supports this (e.g. [lodash](https://lodash.com/docs/4.17.15#cloneDeep)) you can simply use `var clone = JSON.parse(JSON.stringify(object));`.
21
23
 
24
+ ### CLI
25
+
26
+ You can also use the CLI to migrate a single file.
27
+ The commands follow the different methods above and has the same "restrictions" as above.
28
+
29
+ * Migrate (auto-detection, override): `npx stac-migrate <source_path>`
30
+ * Migrate (auto-detection, save to a different file with 4 spaces indentation): `npx stac-migrate <source_path> --dest <dest_path> --indent 4`
31
+ * Migrate a STAC Collection: `npx stac-migrate <source_path> <dest_path> --collection`
32
+ * Migrate a STAC Catalog: `npx stac-migrate <source_path> <dest_path> --catalog`
33
+ * Migrate a STAC Item: `npx stac-migrate <source_path> <dest_path> --item --collection_path <collection_path>`
34
+
22
35
  ## Supported Extensions
23
36
 
24
- * Checksum (use `Migrate.enableMultihash(require('multihashes'))` to enable conversion from pre-0.9 checksums - disabled by default to keep the bundle size low)
25
- * Collection Assets 1.0.0
26
- * Commons
27
- * Data Cube 1.0.0
28
- * Datetime Range
37
+ * Checksum (legacy, use `Migrate.enableMultihash(require('multihashes'))` to enable conversion from pre-0.9 checksums - disabled by default to keep the bundle size low)
38
+ * Classification 1.1.0
39
+ * Collection Assets (legacy)
40
+ * Commons (legacy)
41
+ * Data Cube 2.1.0
42
+ * Datetime Range (legacy)
29
43
  * Electro-Optical 1.0.0
30
44
  * File 1.0.0
31
45
  * (Item) Asset Definition 1.0.0
32
- * Label 1.0.0
46
+ * Label 1.0.1
33
47
  * Point Cloud 1.0.0
34
- * Procesing 1.0.0
48
+ * Procesing 1.1.0
35
49
  * Projection 1.0.0
36
- * Raster 1.0.0
50
+ * Raster 1.1.0
37
51
  * SAR 1.0.0
38
52
  * Satellite 1.0.0
39
- * Scientific 1.0.0
53
+ * Scientific Citation 1.0.0
40
54
  * Single Item
55
+ * Table 1.2.0
41
56
  * Timestamps 1.0.0
42
57
  * Versioning Indicators 1.0.0
43
58
  * View Geometry 1.0.0
package/bin/cli.js ADDED
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env node
2
+ const fs = require('fs');
3
+ const yargs = require('yargs/yargs')
4
+ const { hideBin } = require('yargs/helpers')
5
+ const Migrate = require('../migrate');
6
+ const package = require("../package.json");
7
+
8
+ const args = yargs(hideBin(process.argv))
9
+ .option('_', {
10
+ type: 'string',
11
+ describe: 'File to load the STAC data from'
12
+ })
13
+ .option('dest', {
14
+ type: 'string',
15
+ description: 'File to save the result to',
16
+ alias: 'd'
17
+ })
18
+ .option('collection', {
19
+ type: 'boolean',
20
+ description: 'Enforce the collection migration',
21
+ conflicts: ['catalog', 'item'],
22
+
23
+ })
24
+ .option('catalog', {
25
+ type: 'boolean',
26
+ description: 'Enforce the catalog migration',
27
+ conflicts: ['collection', 'item',]
28
+ })
29
+ .option('item', {
30
+ type: 'boolean',
31
+ description: 'Enforce the item migration',
32
+ conflicts: ['catalog', 'collection']
33
+ })
34
+ .option('collection_path', {
35
+ type: 'string',
36
+ description: 'Pass the path to a collection to the item, only possible if --item has been specified.',
37
+ conflicts: ['catalog', 'collection']
38
+ })
39
+ .option('indent', {
40
+ type: 'number',
41
+ description: 'Number of spaces to use for JSON indentation',
42
+ default: 2
43
+ })
44
+ .help()
45
+ .parse()
46
+
47
+ run(args);
48
+
49
+ function run(args) {
50
+ console.log("STAC Migrate v" + package.version);
51
+ let fn = ['collection', 'catalog', 'item'].find(type => Boolean(args[type])) || 'stac';
52
+ if (args._.length !== 1) {
53
+ throw new Error("Please provide exatctly one source file.");
54
+ }
55
+ let src = args._[0];
56
+ let dest = args.dest || src;
57
+
58
+ let dataStr = fs.readFileSync(src);
59
+ let dataObj = JSON.parse(dataStr);
60
+ let options = [dataObj];
61
+ if (fn === 'item') {
62
+ let collestionStr = fs.readFileSync(args.collection_path);
63
+ let collestionObj = JSON.parse(collestionStr);
64
+ options.push(collestionObj);
65
+ }
66
+ Migrate[fn](...options)
67
+ dataStr = JSON.stringify(dataObj, null, args.indent);
68
+ fs.writeFileSync(dest, dataStr);
69
+ console.log("Migrated successfully: " + dest);
70
+ }