@dittowords/cli 2.1.0 → 2.1.1

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,9 +16,39 @@ 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://beta.dittowords.com/account/user](https://beta.dittowords.com/account/user) under **API Keys**):
20
20
 
21
- Once you've successfully authenticated, 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.
21
+ ```
22
+ $ npx @dittowords/cli
23
+
24
+ ┌──────────────────────────────────┐
25
+ │ │
26
+ │ Welcome to the Ditto CLI. │
27
+ │ │
28
+ │ We're glad to have you here. │
29
+ │ │
30
+ └──────────────────────────────────┘
31
+
32
+ What is your API key? > xxx-xxx-xxx
33
+
34
+ Thanks for authenticating.
35
+ We'll save the key to: /Users/{username}/.config/ditto
36
+ ```
37
+
38
+ Once you've successfully authenticated, you'll be asked to configure the CLI with an initial project from your workspace:
39
+
40
+ ```
41
+ Looks like there are no Ditto projects selected for your current directory.
42
+
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
46
+ ...
47
+ ```
48
+
49
+ After selecting a project, a configuration file will automatically be created at the path `./ditto/config.yml`, relative to your current working directory. The CLI will attempt to read from this file every time a command is executed. See the [documentation on config.yml](#files) further down in this README for a full reference of how the CLI can be configured.
50
+
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.
22
52
 
23
53
  ## Commands
24
54
 
@@ -52,7 +82,7 @@ This folder houses the configuration file (`ditto/config.yml`) used by the CLI a
52
82
 
53
83
  If you run the CLI in a directory that does not contain a `ditto/` folder, the folder and a `config.yml` file will be automatically created.
54
84
 
55
- - #### `config.yml`
85
+ - #### config.yml
56
86
 
57
87
  This is the source of truth for a given directory about how the CLI should fetch and store data from Ditto. It includes information about which Ditto projects the CLI should pull text from and in what format the text should be stored.
58
88
 
@@ -60,16 +90,62 @@ If you run the CLI in a directory that does not contain a `ditto/` folder, the f
60
90
 
61
91
  **Supported properties**
62
92
 
63
- - `projects` (required) - a list of project names and ids to pull text from (see example)
64
- - `variants` (optional) - a `true` or `false` value indicating whether or not variant data should be pulled for the specified projects. Defaults to `false` if not specified (will likely default to `true` in future major releases).
65
- - `format` (optional) - the format the specified projects should be stored in. Acceptable values are `structured` or `flat`. If not specified, the default format containing block and frame data will be used.
93
+ ##### `projects`
94
+
95
+ A list of project names and ids to pull text from. R
96
+
97
+ equired if `components: true` is not specified.
98
+
99
+ **Note**: the `name` property is used for display purposes when referencing a project in the CLI, but does not have to be an
100
+ exact match with the project name in Ditto.
101
+
102
+ ```yml
103
+ projects:
104
+ - name: Landing Page Copy
105
+ id: 61b8d26105f8f400e97fdd14
106
+ - name: User Settings
107
+ id: 606cb89ac55041013d552f8b
108
+ ```
109
+
110
+ ##### `components`
111
+
112
+ If included with a value of `true`, data from the component library will be fetched and included in the CLI's output.
66
113
 
67
- **Example**:
114
+ Required if `projects` is not specified with a valid list of projects.
115
+
116
+ ```yml
117
+ components: true
118
+ ```
68
119
 
120
+ ##### `variants`
121
+
122
+ If included with a value of `true`, variant data will be pulled for the specified projects and/or the component library.
123
+
124
+ Defaults to `false`.
125
+
126
+ ```yml
127
+ variants: true
69
128
  ```
129
+
130
+ ##### `format`
131
+
132
+ The format the specified projects should be stored in. Acceptable values are `structured` or `flat`.
133
+
134
+ If not specified, the default format containing block and frame data will be used.
135
+
136
+ ```yml
137
+ format: flat
138
+ ```
139
+
140
+ **Full Example**
141
+
142
+ ```yml
70
143
  projects:
71
- - name: Ditto Component Library
72
- id: ditto_component_library
144
+ - name: Landing Page Copy
145
+ id: 61b8d26105f8f400e97fdd14
146
+ - name: User Settings
147
+ id: 606cb89ac55041013d552f8b
148
+ components: true
73
149
  variants: true
74
150
  format: flat
75
151
  ```
package/lib/config.js CHANGED
@@ -17,7 +17,7 @@ function createFileIfMissing(filename) {
17
17
 
18
18
  /**
19
19
  * Read data from a file
20
- * @param {*} file defaults to `PROJECT_CONFIG_FILE` defined in `constants.js`
20
+ * @param {string} file defaults to `PROJECT_CONFIG_FILE` defined in `constants.js`
21
21
  * @param {*} defaultData defaults to `{}`
22
22
  * @returns
23
23
  */
@@ -83,8 +83,8 @@ const IS_DUPLICATE = /-(\d+$)/;
83
83
  function dedupeProjectName(projectNames, projectName) {
84
84
  let dedupedName = projectName;
85
85
 
86
- if (projectNames[dedupedName]) {
87
- while (projectNames[dedupedName]) {
86
+ if (projectNames.has(dedupedName)) {
87
+ while (projectNames.has(dedupedName)) {
88
88
  const [_, numberStr] = dedupedName.match(IS_DUPLICATE) || [];
89
89
  if (numberStr && !isNaN(parseInt(numberStr))) {
90
90
  dedupedName = `${dedupedName.replace(IS_DUPLICATE, "")}-${
@@ -127,7 +127,7 @@ function parseSourceInformation() {
127
127
  }
128
128
 
129
129
  project.fileName = dedupeProjectName(projectNames, project.name);
130
- projectNames[project.fileName] = true;
130
+ projectNames.add(project.fileName);
131
131
 
132
132
  validProjects.push(project);
133
133
  });
@@ -15,6 +15,14 @@ function quit(exitCode = 2) {
15
15
  }
16
16
 
17
17
  function saveProject(file, name, id) {
18
+ // old functionality included "ditto_component_library" in the `projects`
19
+ // array, but we want to always treat the component library as a separate
20
+ // entity and use the new notation of a top-level `components` key
21
+ if (id === "ditto_component_library") {
22
+ config.writeData(file, { components: true });
23
+ return;
24
+ }
25
+
18
26
  const projects = [...getSelectedProjects(), { name, id }];
19
27
 
20
28
  config.writeData(file, { projects });
@@ -15,7 +15,7 @@ function sourcesToText(projects, componentLibrary) {
15
15
  }
16
16
 
17
17
  if ((projects || []).length) {
18
- message += ` the following projects: ${projectsToText(projects)}\n`;
18
+ message += `the following projects: ${projectsToText(projects)}\n`;
19
19
  }
20
20
 
21
21
  return message;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dittowords/cli",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Command Line Interface for Ditto (dittowords.com).",
5
5
  "main": "bin/index.js",
6
6
  "scripts": {