@dittowords/cli 2.1.1 → 2.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.
package/README.md CHANGED
@@ -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;
@@ -110,7 +119,7 @@ function dedupeProjectName(projectNames, projectName) {
110
119
  function parseSourceInformation() {
111
120
  const { projects, components, variants, format } = readData();
112
121
 
113
- const projectNames = {};
122
+ const projectNames = new Set();
114
123
  const validProjects = [];
115
124
 
116
125
  let componentLibraryInProjects = false;
@@ -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);
@@ -29,7 +29,7 @@ function getSelectedProjects(configFile = PROJECT_CONFIG_FILE) {
29
29
  return [];
30
30
  }
31
31
 
32
- return contentjson.projects.filter(({ name, id }) => name && id);
32
+ return contentJson.projects.filter(({ name, id }) => name && id);
33
33
  }
34
34
 
35
35
  module.exports = getSelectedProjects;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittowords/cli",
3
- "version": "2.1.1",
3
+ "version": "2.3.0",
4
4
  "description": "Command Line Interface for Ditto (dittowords.com).",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {