@dittowords/cli 2.1.2 → 2.4.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.
package/README.md CHANGED
@@ -16,7 +16,7 @@ npm install --global @dittowords/cli
16
16
 
17
17
  The installed binary is named `ditto-cli`. You can execute it directly in `node_modules/.bin/ditto-cli` or using [npx](https://www.npmjs.com/package/npx) (with or without installation) like `npx @dittowords/cli`.
18
18
 
19
- The first time you run the CLI, you'll be asked to provide an API key (found at [https://beta.dittowords.com/account/user](https://beta.dittowords.com/account/user) under **API Keys**):
19
+ The first time you run the CLI, you'll be asked to provide an API key (found at [https://app.dittowords.com/account/user](https://app.dittowords.com/account/user) under **API Keys**):
20
20
 
21
21
  ```
22
22
  $ npx @dittowords/cli
@@ -41,8 +41,8 @@ Once you've successfully authenticated, you'll be asked to configure the CLI wit
41
41
  Looks like there are no Ditto projects selected for your current directory.
42
42
 
43
43
  ? Choose the project you'd like to sync text from:
44
- - Ditto Component Library https://beta.dittowords.com/components/all
45
- - NUX Onboarding Flow https://beta.dittowords.com/doc/609e9981c313f8018d0c346a
44
+ - Ditto Component Library https://app.dittowords.com/components/all
45
+ - NUX Onboarding Flow https://app.dittowords.com/doc/609e9981c313f8018d0c346a
46
46
  ...
47
47
  ```
48
48
 
@@ -50,6 +50,17 @@ After selecting a project, a configuration file will automatically be created at
50
50
 
51
51
  Once you've successfully authenticated and a config file has been created, you’re ready to start fetching copy! You can set up the CLI in multiple directories by running `ditto-cli` and choosing an initial project to sync from.
52
52
 
53
+ ## API Keys
54
+
55
+ The CLI will not prompt for an API key if a value is provided in the environment variable `DITTO_API_KEY`.
56
+
57
+ If the `DITTO_API_KEY` environment variable is not set, then the CLI will attempt to parse a token from a file at the
58
+ path `~/.config/ditto`. If this file does not exist or does not contain a valid API key, then the CLI will prompt
59
+ for one.
60
+
61
+ We don't recommend editing the file manually; if you need to remove a saved API key and put another one in its place,
62
+ it's better to fully delete the file and then re-run the CLI so that a new key is prompted for.
63
+
53
64
  ## Commands
54
65
 
55
66
  ### `pull`
@@ -92,9 +103,9 @@ If you run the CLI in a directory that does not contain a `ditto/` folder, the f
92
103
 
93
104
  ##### `projects`
94
105
 
95
- A list of project names and ids to pull text from. R
106
+ A list of project names and ids to pull text from.
96
107
 
97
- equired if `components: true` is not specified.
108
+ Required if `components: true` is not specified.
98
109
 
99
110
  **Note**: the `name` property is used for display purposes when referencing a project in the CLI, but does not have to be an
100
111
  exact match with the project name in Ditto.
package/lib/config.js CHANGED
@@ -57,7 +57,16 @@ function saveToken(file, host, token) {
57
57
  writeData(file, data);
58
58
  }
59
59
 
60
+ function getTokenFromEnv() {
61
+ return process.env.DITTO_API_KEY;
62
+ }
63
+
60
64
  function getToken(file, host) {
65
+ const tokenFromEnv = getTokenFromEnv();
66
+ if (tokenFromEnv) {
67
+ return tokenFromEnv;
68
+ }
69
+
61
70
  const data = readData(file);
62
71
  const hostEntry = data[justTheHost(host)];
63
72
  if (!hostEntry) return undefined;
@@ -154,6 +163,7 @@ module.exports = {
154
163
  saveToken,
155
164
  deleteToken,
156
165
  getToken,
166
+ getTokenFromEnv,
157
167
  save,
158
168
  parseSourceInformation,
159
169
  };
package/lib/consts.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const homedir = require("os").homedir();
2
-
3
2
  const path = require("path");
4
3
 
4
+ const TEXT_DIR = process.env.DITTO_TEXT_DIR || "ditto"
5
+
5
6
  module.exports.API_HOST =
6
7
  process.env.DITTO_API_HOST || "https://api.dittowords.com";
7
8
  module.exports.CONFIG_FILE =
@@ -9,5 +10,5 @@ module.exports.CONFIG_FILE =
9
10
  module.exports.PROJECT_CONFIG_FILE = path.normalize(
10
11
  path.join("ditto", "config.yml")
11
12
  );
12
- module.exports.TEXT_FILE = path.normalize(path.join("ditto", "text.json"));
13
- module.exports.TEXT_DIR = path.normalize("ditto");
13
+ module.exports.TEXT_DIR = TEXT_DIR
14
+ module.exports.TEXT_FILE = path.normalize(path.join(TEXT_DIR, "text.json"));
@@ -78,6 +78,7 @@ async function collectProject(token, initialize) {
78
78
 
79
79
  if (!(projects && projects.length)) {
80
80
  console.log("You're currently syncing all projects in your workspace.");
81
+ console.log(output.warnText("Not seeing a project that you were expecting? Verify that developer mode is enabled on that project. More info: https://www.dittowords.com/docs/ditto-developer-mode"));
81
82
  return null;
82
83
  }
83
84
 
package/lib/init/token.js CHANGED
@@ -10,6 +10,10 @@ const output = require("../output");
10
10
  const config = require("../config");
11
11
 
12
12
  function needsToken(configFile, host = consts.API_HOST) {
13
+ if (config.getTokenFromEnv()) {
14
+ return false;
15
+ }
16
+
13
17
  const file = configFile || consts.CONFIG_FILE;
14
18
  if (!fs.existsSync(file)) return true;
15
19
  const configData = config.readData(file);
@@ -54,7 +58,7 @@ async function checkToken(token) {
54
58
 
55
59
  async function collectToken(message) {
56
60
  const blue = output.info;
57
- const apiUrl = output.url("https://beta.dittowords.com/account/user");
61
+ const apiUrl = output.url("https://app.dittowords.com/account/user");
58
62
  const breadcrumbs = `${blue("User")}`;
59
63
  const tokenDescription =
60
64
  message ||
@@ -9,7 +9,7 @@ function projectsToText(projects) {
9
9
  "- " +
10
10
  output.info(name) +
11
11
  " " +
12
- output.subtle("https://beta.dittowords.com/doc/" + id)),
12
+ output.subtle("https://app.dittowords.com/doc/" + id)),
13
13
  ""
14
14
  ) + "\n"
15
15
  );
@@ -7,7 +7,7 @@ function formatProjectChoice(project) {
7
7
  project.name +
8
8
  " " +
9
9
  output.subtle(
10
- project.url || `https://beta.dittowords.com/doc/${project.id}`
10
+ project.url || `https://app.dittowords.com/doc/${project.id}`
11
11
  )
12
12
  );
13
13
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittowords/cli",
3
- "version": "2.1.2",
3
+ "version": "2.4.0",
4
4
  "description": "Command Line Interface for Ditto (dittowords.com).",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {