Skip to content

Commit 757246b

Browse files
authored
Expose only one ota command for CLI (#978)
2 parents e930a40 + 2c2e224 commit 757246b

File tree

17 files changed

+6019
-11494
lines changed

17 files changed

+6019
-11494
lines changed

.github/workflows/test.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ jobs:
3131
with:
3232
node-version: 16
3333
- run: npm ci
34-
- run: npm test
34+
- name: Run tests (Linux)
35+
if: ${{ runner.os == 'Linux' }}
36+
run: npm test
37+
- name: Run tests (Windows or macOS)
38+
if: ${{ runner.os == 'Windows' || runner.os == 'macOS' }}
39+
run: npm test -- --timeout 5000
3540

3641
validate_declarations:
3742
strategy:

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ All notable changes to this project will be documented in this file.
55
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html) and the format is based on [Common Changelog](https://common-changelog.org).\
66
Unlike Common Changelog, the `unreleased` section of [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) is preserved with the addition of a tag to specify which type of release should be published and to foster discussions about it inside pull requests. This tag should be one of the names mandated by SemVer, within brackets: `[patch]`, `[minor]` or `[major]`. For example: `## Unreleased [minor]`.
77

8-
## Unreleased
8+
## Unreleased [minor]
9+
10+
### Changed
11+
- **Breaking:** Unify all CLI commands as subcommands of one single `ota` command and rename some options; the new CLI can be discovered in the documentation and by running `ota help` ([#978](https://github.com/ambanum/OpenTermsArchive/pull/978))
912

1013
## 0.18.2 - 2022-12-12
1114
### Fixed

README.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -150,17 +150,17 @@ This quick example aimed at letting you try the engine quickly. Most likely, you
150150

151151
### CLI
152152

153-
Once the engine module is installed as a dependency within another module, the following commands are available.
153+
Once the engine module is installed as a dependency within another module, the `ota` command with the following subcommands is available.
154154

155155
In these commands:
156156

157157
- **`<service_id>`** is the case sensitive name of the service declaration file without the extension. For example, for `Twitter.json`, the service ID is `Twitter`.
158158
- **`<terms_type>`** is the property name used under the `documents` property in the declaration to declare a terms. For example, in the getting started declaration, the terms type declared is `Privacy Policy`.
159159

160-
#### `ota-track`
160+
#### `ota track`
161161

162162
```sh
163-
npx ota-track
163+
npx ota track
164164
```
165165

166166
[Track](#tracking-documents) the current terms of services according to provided declarations.
@@ -172,31 +172,31 @@ The declarations, snapshots and versions paths are defined in the [configuration
172172
##### Recap of available options
173173

174174
```sh
175-
npx ota-track --help
175+
npx ota track --help
176176
```
177177

178178
##### Track terms of specific services
179179

180180
```sh
181-
npx ota-track --services "<service_id>" ["<service_id>"...]
181+
npx ota track --services "<service_id>" ["<service_id>"...]
182182
```
183183

184184
##### Track specific terms of specific services
185185

186186
```sh
187-
npx ota-track --services "<service_id>" ["<service_id>"...] --documentTypes "<terms_type>" ["<terms_type>"...]
187+
npx ota track --services "<service_id>" ["<service_id>"...] --termsTypes "<terms_type>" ["<terms_type>"...]
188188
```
189189

190190
##### Track documents four times a day
191191

192192
```sh
193-
npx ota-track --schedule
193+
npx ota track --schedule
194194
```
195195

196-
#### `ota-validate-declarations`
196+
#### `ota validate`
197197

198198
```sh
199-
npx ota-validate-declarations [--services <service_id>...]
199+
npx ota validate [--services <service_id>...] [--termsTypes <terms_type>...]
200200
```
201201

202202
Check that all declarations allow recording a snapshot and a version properly.
@@ -206,7 +206,7 @@ If one or several `<service_id>` are provided, check only those services.
206206
##### Validate schema only
207207

208208
```sh
209-
npx ota-validate-declarations --schema-only [--services <service_id>...]
209+
npx ota validate --schema-only [--services <service_id>...] [--termsTypes <terms_type>...]
210210
```
211211

212212
Check that all declarations are readable by the engine.
@@ -215,10 +215,10 @@ Allows for a much faster check of declarations, but does not check that the docu
215215

216216
If one or several `<service_id>` are provided, check only those services.
217217

218-
#### `ota-lint-declarations`
218+
#### `ota lint`
219219

220220
```sh
221-
npx ota-lint-declarations [--services <service_id>...]
221+
npx ota lint [--services <service_id>...]
222222
```
223223

224224
Normalise the format of declarations.

bin/.env.js

-10
This file was deleted.

bin/env.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import path from 'path';
2+
import { fileURLToPath } from 'url';
3+
4+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
5+
6+
process.env.SUPPRESS_NO_CONFIG_WARNING = 'y'; // Caller don't get "no config files" warnings if it does define configuration files
7+
8+
const OTA_CONFIG_DIR = path.resolve(`${__dirname}./../config/`);
9+
const PROCESS_CONFIG_DIR = path.resolve(`${process.cwd()}/config/`);
10+
11+
process.env.NODE_CONFIG_DIR = OTA_CONFIG_DIR + path.delimiter + PROCESS_CONFIG_DIR; // Ensure OTA config is loaded and loaded before caller config
+4-11
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
#! /usr/bin/env node
2-
// makes it easy to lint all files relative to one service ID, which would have been
3-
// more difficult to achieve using an eslint based command directly defined in the package.json.
4-
// It also ensures that the same version of eslint is used in the OpenTermsArchive core and declarations repositories.
5-
import './.env.js'; // Workaround to ensure `SUPPRESS_NO_CONFIG_WARNING` is set before config is imported
2+
import './env.js';
63

7-
import fs from 'fs';
84
import path from 'path';
95
import { fileURLToPath, pathToFileURL } from 'url';
106

117
import { program } from 'commander';
128

139
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1410

15-
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
16-
1711
program
18-
.name('ota-lint-declarations')
12+
.name('ota lint')
1913
.description('Check format and stylistic errors in declarations and auto fix them')
20-
.version(version)
21-
.option('-s, --services [serviceId...]', 'service IDs of services to handle')
14+
.option('-s, --services [serviceId...]', 'service IDs of services to lint')
2215
.option('-m, --modified', 'to only lint modified services already commited to git');
2316

24-
const lintDeclarations = (await import(pathToFileURL(path.resolve(__dirname, '../scripts/declarations/lint/index.js')))).default;
17+
const lintDeclarations = (await import(pathToFileURL(path.resolve(__dirname, '../scripts/declarations/lint/index.js')))).default; // load asynchronously to ensure env.js is loaded before
2518

2619
lintDeclarations(program.parse().opts());

bin/ota-track.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#! /usr/bin/env node
2+
import './env.js';
3+
4+
import path from 'path';
5+
import { fileURLToPath, pathToFileURL } from 'url';
6+
7+
import { program } from 'commander';
8+
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
11+
const track = (await import(pathToFileURL(path.resolve(__dirname, '../src/index.js')))).default; // load asynchronously to ensure env.js is loaded before
12+
13+
program
14+
.name('ota track')
15+
.description('Retrieve declared documents, record snapshots, extract versions and publish the resulting records')
16+
.option('-s, --services [serviceId...]', 'service IDs of services to track')
17+
.option('-t, --termsType [termsType...]', 'terms types to track')
18+
.option('-r, --refilter-only', 'refilter existing snapshots with latest declarations and engine, without recording new snapshots')
19+
.option('--schedule', 'schedule automatic document tracking');
20+
21+
track(program.parse(process.argv).opts());

bin/validate-declarations.js bin/ota-validate.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#! /usr/bin/env node
2-
import './.env.js'; // Workaround to ensure `SUPPRESS_NO_CONFIG_WARNING` is set before config is imported
2+
import './env.js';
33

4-
import fs from 'fs';
54
import path from 'path';
65
import { fileURLToPath } from 'url';
76

87
import { program } from 'commander';
98
import Mocha from 'mocha';
109

11-
const { version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
12-
1310
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1411

1512
const VALIDATE_PATH = path.resolve(__dirname, '../scripts/declarations/validate/index.mocha.js');
@@ -21,13 +18,12 @@ process.on('unhandledRejection', reason => {
2118
});
2219

2320
program
24-
.name('ota-validate-declarations')
21+
.name('ota validate')
2522
.description('Run a series of tests to check the validity of document declarations')
26-
.version(version)
27-
.option('-s, --services [serviceId...]', 'service IDs of services to handle')
28-
.option('-d, --documentTypes [documentType...]', 'document types to handle')
29-
.option('-m, --modified', 'to only lint modified services already commited to git')
30-
.option('-so, --schema-only', 'only refilter exisiting snapshots with last declarations and engine\'s updates');
23+
.option('-s, --services [serviceId...]', 'service IDs of services to validate')
24+
.option('-t, --termsTypes [termsType...]', 'terms types to validate')
25+
.option('-m, --modified', 'target only services modified in the current git branch')
26+
.option('-o, --schema-only', 'much faster check of declarations, but does not check that the documents are actually accessible');
3127

3228
const mocha = new Mocha({
3329
delay: true, // as the validation script performs an asynchronous load before running the tests, the execution of the tests are delayed until run() is called

bin/ota.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#! /usr/bin/env node
2+
import './env.js';
3+
4+
import fs from 'fs';
5+
6+
import { program } from 'commander';
7+
8+
const { description, version } = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)).toString());
9+
10+
program
11+
.description(description)
12+
.version(version)
13+
.command('track', 'Track the current terms of services according to provided declarations')
14+
.command('validate', 'Run a series of tests to check the validity of document declarations')
15+
.command('lint', 'Check format and stylistic errors in declarations and auto fix them')
16+
.parse(process.argv);

bin/track.js

-25
This file was deleted.

config/production.json

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
{
2-
"services": {
3-
"declarationsPath": "../declarations/declarations"
4-
},
52
"recorder": {
63
"versions": {
74
"storage": {

0 commit comments

Comments
 (0)