@dittowords/cli 2.8.0 → 3.2.0-alpha
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 +150 -141
- package/bin/add-project.js +5 -7
- package/bin/add-project.js.map +1 -1
- package/bin/config.js +37 -11
- package/bin/config.js.map +1 -1
- package/bin/ditto.js +82 -57
- package/bin/ditto.js.map +1 -1
- package/bin/generate-suggestions.js +71 -0
- package/bin/generate-suggestions.js.map +1 -0
- package/bin/http/fetchComponents.js +13 -0
- package/bin/http/fetchComponents.js.map +1 -0
- package/bin/http/fetchVariants.js +26 -0
- package/bin/http/fetchVariants.js.map +1 -0
- package/bin/init/init.js +17 -6
- package/bin/init/init.js.map +1 -1
- package/bin/init/project.js +38 -45
- package/bin/init/project.js.map +1 -1
- package/bin/init/token.js +22 -20
- package/bin/init/token.js.map +1 -1
- package/bin/pull.js +136 -193
- package/bin/pull.js.map +1 -1
- package/bin/remove-project.js +2 -7
- package/bin/remove-project.js.map +1 -1
- package/bin/replace.js +107 -0
- package/bin/replace.js.map +1 -0
- package/bin/utils/cleanFileName.js +11 -0
- package/bin/utils/cleanFileName.js.map +1 -0
- package/bin/utils/generateJsDriver.js +56 -0
- package/bin/utils/generateJsDriver.js.map +1 -0
- package/bin/utils/getSelectedProjects.js +3 -18
- package/bin/utils/getSelectedProjects.js.map +1 -1
- package/bin/utils/projectsToText.js +10 -1
- package/bin/utils/projectsToText.js.map +1 -1
- package/bin/utils/promptForProject.js +2 -3
- package/bin/utils/promptForProject.js.map +1 -1
- package/bin/utils/quit.js +10 -0
- package/bin/utils/quit.js.map +1 -0
- package/lib/add-project.ts +6 -9
- package/lib/config.ts +56 -19
- package/lib/ditto.ts +111 -60
- package/lib/generate-suggestions.test.ts +65 -0
- package/lib/generate-suggestions.ts +107 -0
- package/lib/http/fetchComponents.ts +14 -0
- package/lib/http/fetchVariants.ts +30 -0
- package/lib/init/init.ts +38 -6
- package/lib/init/project.test.ts +3 -3
- package/lib/init/project.ts +47 -58
- package/lib/init/token.ts +17 -16
- package/lib/pull.ts +199 -279
- package/lib/remove-project.ts +2 -8
- package/lib/replace.test.ts +101 -0
- package/lib/replace.ts +106 -0
- package/lib/types.ts +22 -3
- package/lib/utils/cleanFileName.ts +6 -0
- package/lib/utils/generateJsDriver.ts +68 -0
- package/lib/utils/getSelectedProjects.ts +5 -24
- package/lib/utils/projectsToText.ts +11 -1
- package/lib/utils/promptForProject.ts +2 -3
- package/lib/utils/quit.ts +5 -0
- package/package.json +9 -2
- package/tsconfig.json +2 -1
package/README.md
CHANGED
|
@@ -35,20 +35,20 @@ Thanks for authenticating.
|
|
|
35
35
|
We'll save the key to: /Users/{username}/.config/ditto
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Once you've successfully authenticated, you'll be asked to
|
|
38
|
+
Once you've successfully authenticated, you'll be asked to choose a source (a project or your component library) to pull data from:
|
|
39
39
|
|
|
40
40
|
```
|
|
41
|
-
Looks like there are no Ditto
|
|
41
|
+
Looks like there are no Ditto sources selected for your current directory: /Users/ditto
|
|
42
42
|
|
|
43
|
-
? Choose the
|
|
44
|
-
- Ditto Component Library https://app.dittowords.com/components
|
|
43
|
+
? Choose the source you'd like to sync text from:
|
|
44
|
+
- Ditto Component Library https://app.dittowords.com/components
|
|
45
45
|
- NUX Onboarding Flow https://app.dittowords.com/doc/609e9981c313f8018d0c346a
|
|
46
46
|
...
|
|
47
47
|
```
|
|
48
48
|
|
|
49
|
-
After selecting a
|
|
49
|
+
After selecting a source, 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 [config.yml documentation](#files) further down in this README for a full reference of how the CLI can be configured.
|
|
50
50
|
|
|
51
|
-
Once you've successfully authenticated and a config file has been created, you’re ready to start fetching copy!
|
|
51
|
+
Once you've successfully authenticated and a config file has been created, you’re ready to start fetching copy! If you need to use the CLI with multiple configurations, simply run `ditto-cli` in multiple directories.
|
|
52
52
|
|
|
53
53
|
## API Keys
|
|
54
54
|
|
|
@@ -56,205 +56,214 @@ The CLI will not prompt for an API key if a value is provided in the environment
|
|
|
56
56
|
|
|
57
57
|
If the `DITTO_API_KEY` environment variable is not set, the CLI will attempt to parse a token from [your authentication file](#authentication). If this file does not exist or does not contain a valid API key, the CLI will prompt for one.
|
|
58
58
|
|
|
59
|
-
We don't recommend editing the file
|
|
60
|
-
it's better to fully delete the file and then re-run the CLI so that a new key is prompted for.
|
|
59
|
+
We don't recommend editing the authentication file by hand; if you need to remove a saved API key or swap one key with another, it's better to fully delete the file and then re-run the CLI.
|
|
61
60
|
|
|
62
61
|
## Commands
|
|
63
62
|
|
|
64
|
-
###
|
|
63
|
+
### Pull
|
|
65
64
|
|
|
66
|
-
**Usage:** `ditto-cli pull`
|
|
65
|
+
**Usage:** `ditto-cli` (no commands), `ditto-cli pull`
|
|
67
66
|
|
|
68
|
-
**Action:** Pulls
|
|
67
|
+
**Action:** Pulls data from Ditto according to configured sources.
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
Files in your local `ditto/` folder will be generated (`.json`, `.xml`, or `.strings` format according to the `format` property specified in `config.yml`.
|
|
71
70
|
|
|
72
|
-
|
|
71
|
+
If no format is specified, the `flat` format will be used by default. Each time text is pulled from Ditto, the existing text files in the `ditto/` directory are removed before new files are created in their place.
|
|
73
72
|
|
|
74
|
-
|
|
73
|
+
For more details on files generated by this command, see [JSON Files](#json-files).
|
|
74
|
+
|
|
75
|
+
### Add project
|
|
75
76
|
|
|
76
77
|
**Usage:** `ditto-cli project add`
|
|
77
78
|
|
|
78
|
-
**Action:**
|
|
79
|
+
**Action:** Lists projects in your workspace that have developer mode enabled and permits selecting one to add to `config.yml` via an interactive prompt.
|
|
79
80
|
|
|
80
|
-
###
|
|
81
|
+
### Remove project
|
|
81
82
|
|
|
82
83
|
**Usage:** `ditto-cli project remove`
|
|
83
84
|
|
|
84
|
-
**Action:**
|
|
85
|
-
|
|
86
|
-
## Options
|
|
87
|
-
|
|
88
|
-
`-m, --meta <data...>` Optional metadata to send arbitrary data to the backend. Ex: `-m githubActionRequest:true trigger:manual`. Currently, this option should only be utilized when the CLI is ran within a GitHub action (see [Ditto GitHub Action](https://github.com/dittowords/ditto-github-action)) via `githubActionRequest:true`.
|
|
89
|
-
|
|
90
|
-
## Files
|
|
85
|
+
**Action:** Lists projects in `config.yml` and permits selecting one to remove from `config.yml` via an interactive prompt.
|
|
91
86
|
|
|
92
|
-
|
|
87
|
+
## Configuration
|
|
93
88
|
|
|
94
|
-
|
|
89
|
+
The `config.yml` file 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, whether or not the component library should be included, in what format the text should be stored, and more.
|
|
95
90
|
|
|
96
|
-
|
|
91
|
+
This file is edited by the `project add` / `project remove` commands, but most options are currently only supported through manual edits.
|
|
97
92
|
|
|
98
|
-
|
|
93
|
+
This is the default configuration file that is generated the first time that the CLI is run in a given directory:
|
|
99
94
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
```yml
|
|
96
|
+
sources:
|
|
97
|
+
components:
|
|
98
|
+
enabled: true
|
|
99
|
+
format: flat
|
|
100
|
+
variants: true
|
|
101
|
+
```
|
|
103
102
|
|
|
104
|
-
|
|
103
|
+
### Supported Properties
|
|
105
104
|
|
|
106
|
-
|
|
105
|
+
#### Sources
|
|
107
106
|
|
|
108
|
-
|
|
107
|
+
A list of places the CLI should pull text data from. For the CLI to function, at least one source type (`projects` or `components`) is required.
|
|
109
108
|
|
|
110
|
-
|
|
109
|
+
#### `sources.projects`
|
|
111
110
|
|
|
112
|
-
|
|
113
|
-
exact match with the project name in Ditto.
|
|
111
|
+
A list of projects to pull text from.
|
|
114
112
|
|
|
115
|
-
|
|
113
|
+
```yml
|
|
114
|
+
sources:
|
|
116
115
|
projects:
|
|
117
|
-
-
|
|
118
|
-
|
|
119
|
-
-
|
|
120
|
-
|
|
121
|
-
|
|
116
|
+
- id: 61b8d26105f8f400e97fdd14
|
|
117
|
+
name: Landing Page Copy
|
|
118
|
+
- id: 606cb89ac55041013d552f8b
|
|
119
|
+
name: User Settings
|
|
120
|
+
```
|
|
122
121
|
|
|
123
|
-
|
|
122
|
+
The `name` property is used for display purposes when referencing a project in the CLI, but does not have to be an exact match with the project name in Ditto.
|
|
123
|
+
|
|
124
|
+
#### `sources.components`
|
|
125
|
+
|
|
126
|
+
An object to configure pulling component data from your component library.
|
|
127
|
+
|
|
128
|
+
```yml
|
|
129
|
+
sources:
|
|
130
|
+
components:
|
|
131
|
+
# type: boolean
|
|
132
|
+
# required: true
|
|
133
|
+
#
|
|
134
|
+
# if set to true, enables pulling data from the component
|
|
135
|
+
# library. if set to false, CLI behaves as if `sources.components`
|
|
136
|
+
# is not defined
|
|
137
|
+
enabled: true
|
|
138
|
+
|
|
139
|
+
# type: { id: string; name: string; }
|
|
140
|
+
# required: false
|
|
141
|
+
#
|
|
142
|
+
# if defined, restricts the CLI to only pulling data for components that are in the specified folders.
|
|
143
|
+
folders:
|
|
144
|
+
- id: 61b8d26105f8f400e97fdd14
|
|
145
|
+
name: Onboarding
|
|
146
|
+
```
|
|
124
147
|
|
|
125
|
-
|
|
148
|
+
#### Variants
|
|
126
149
|
|
|
127
|
-
|
|
150
|
+
Enables including variant information when pulling text data for configured sources.
|
|
128
151
|
|
|
129
|
-
|
|
130
|
-
components: true
|
|
131
|
-
```
|
|
152
|
+
Defaults to `false` if not specified.
|
|
132
153
|
|
|
133
|
-
|
|
154
|
+
```yml
|
|
155
|
+
variants: true
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
##### Format
|
|
134
159
|
|
|
135
|
-
|
|
160
|
+
The format that text data should be generated in. Accepted values:
|
|
136
161
|
|
|
137
|
-
|
|
162
|
+
- `structured`
|
|
163
|
+
- `flat`
|
|
164
|
+
- `android`
|
|
165
|
+
- `ios-strings`
|
|
138
166
|
|
|
139
|
-
|
|
140
|
-
variants: true
|
|
141
|
-
```
|
|
167
|
+
Defaults to `flat` if not specified.
|
|
142
168
|
|
|
143
|
-
|
|
169
|
+
```yml
|
|
170
|
+
format: flat
|
|
171
|
+
```
|
|
144
172
|
|
|
145
|
-
|
|
173
|
+
#### Status
|
|
146
174
|
|
|
147
|
-
|
|
175
|
+
If defined, data pulled will be restricted to text items or components that have the specified status. Accepted values:
|
|
148
176
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
177
|
+
- `NONE`
|
|
178
|
+
- `WIP`
|
|
179
|
+
- `REVIEW`
|
|
180
|
+
- `FINAL`
|
|
152
181
|
|
|
153
|
-
|
|
182
|
+
```yml
|
|
183
|
+
status: FINAL
|
|
184
|
+
```
|
|
154
185
|
|
|
155
|
-
|
|
186
|
+
Defaults to no status restriction if not specified.
|
|
156
187
|
|
|
157
|
-
|
|
188
|
+
More information about statuses can be found [here](https://www.dittowords.com/docs/tips-for-collaborating).
|
|
158
189
|
|
|
159
|
-
|
|
160
|
-
status: FINAL
|
|
161
|
-
```
|
|
190
|
+
#### Rich Text
|
|
162
191
|
|
|
163
|
-
|
|
192
|
+
If defined in conjunction with the `structured` format, output data will include an HTML string (rich text) for each text item or component that is sourced. You can read more about Ditto's rich text feature [here](https://www.dittowords.com/docs/rich-text).
|
|
164
193
|
|
|
165
|
-
|
|
194
|
+
```yml
|
|
195
|
+
richText: true
|
|
196
|
+
```
|
|
166
197
|
|
|
167
|
-
|
|
198
|
+
### Full Configuration Example
|
|
168
199
|
|
|
169
|
-
|
|
200
|
+
```yml
|
|
201
|
+
sources:
|
|
202
|
+
components:
|
|
203
|
+
enabled: true
|
|
204
|
+
folders:
|
|
205
|
+
- id: 61b8d26105f8f400e97fdd14
|
|
206
|
+
name: Onboarding
|
|
170
207
|
projects:
|
|
171
208
|
- name: Landing Page Copy
|
|
172
209
|
id: 61b8d26105f8f400e97fdd14
|
|
173
210
|
- name: User Settings
|
|
174
211
|
id: 606cb89ac55041013d552f8b
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
- #### JSON Files
|
|
182
|
-
|
|
183
|
-
For `structured` and `flat` formats the copy pulled from your Ditto projects is saved to JSON files in the `ditto/` folder.
|
|
184
|
-
|
|
185
|
-
The number of files present and the convention with which they're named will vary according to the options specified in `config.yml`:
|
|
186
|
-
|
|
187
|
-
- If the `variants` and `format` options are unset, all data will be stored in a single file: `text.json`
|
|
188
|
-
- If the `variants` option is `true` and the `format` option is unset, files will be written on a per-variant basis; `base.json` will contain all base (non-variant) text and all other files will follow the pattern `[variant-api-id].json`.
|
|
189
|
-
- If the `variants` option is unset and the `format` open is `flat` or `structured`, files will be written on a per-project basis following the pattern `[project-id].json`.
|
|
190
|
-
- If the `variants` option is `true` and the `format` option is `flat` or `structured`, files will be written on a per-project per-variant basis following the pattern `[project-id__variant-api-id].json`. These files will NOT contain the top-level `projects` and `project_xyz` keys.
|
|
191
|
-
|
|
192
|
-
- #### Mobile files (XML and .strings)
|
|
193
|
-
|
|
194
|
-
When `format` is set to `android`, the resulting files will be in XML format. More information about the contents of the XML files can be found [here](https://developer.dittowords.com/api-reference#android).
|
|
195
|
-
|
|
196
|
-
When `format` is set to `ios-strings`, the resulting files will be in .strings format. More information about the contents of the .strings files can be found [here](https://developer.dittowords.com/api-reference#ios-strings).
|
|
197
|
-
|
|
198
|
-
- #### `index.js`
|
|
199
|
-
|
|
200
|
-
An automatically generated driver file that simplifies the process of passing text data to Ditto JavaScript SDKs. This file has a standardized format that is always the same independent of the CLI configuration used to generate it.
|
|
212
|
+
variants: true
|
|
213
|
+
format: flat
|
|
214
|
+
status: FINAL
|
|
215
|
+
richText: false
|
|
216
|
+
```
|
|
201
217
|
|
|
202
|
-
|
|
218
|
+
## CLI Files
|
|
203
219
|
|
|
204
|
-
|
|
205
|
-
interface DriverFile {
|
|
206
|
-
[projectId: string]: {
|
|
207
|
-
// non-variant text is represented via an apiId of 'base'
|
|
208
|
-
[variantApiId: string]: {
|
|
209
|
-
[id: string]: Frame | { text: string } | string;
|
|
210
|
-
};
|
|
211
|
-
};
|
|
212
|
-
}
|
|
220
|
+
### `ditto/` Directory
|
|
213
221
|
|
|
214
|
-
|
|
215
|
-
blocks: {
|
|
216
|
-
[blockId: string]: {
|
|
217
|
-
[textApiId: string]: StructuredText;
|
|
218
|
-
};
|
|
219
|
-
};
|
|
220
|
-
otherText: {
|
|
221
|
-
[textId: string]: StructuredText;
|
|
222
|
-
};
|
|
223
|
-
}
|
|
222
|
+
This directory houses the configuration file (`ditto/config.yml`) used by the CLI and is also the default write destination for any files the CLI generates. See [Output Directory](#output-directory) for details on how to customize the location that files are written to.
|
|
224
223
|
|
|
225
|
-
|
|
226
|
-
text: string;
|
|
227
|
-
}
|
|
228
|
-
```
|
|
224
|
+
If you run the CLI in a directory that does not contain a `ditto/` folder, the folder and a default `config.yml` file will be automatically created.
|
|
229
225
|
|
|
230
|
-
|
|
231
|
-
module.exports = {
|
|
232
|
-
ditto_component_library: {
|
|
233
|
-
base: require("./ditto_component_library__base.json"),
|
|
234
|
-
spanish: require("./ditto_component_library__spanish.json"),
|
|
235
|
-
},
|
|
236
|
-
project_1234: {
|
|
237
|
-
base: require("./example-project__base.json"),
|
|
238
|
-
spanish: require("./example-project__spanish.json"),
|
|
239
|
-
},
|
|
240
|
-
};
|
|
241
|
-
```
|
|
226
|
+
#### Output Files
|
|
242
227
|
|
|
243
|
-
|
|
228
|
+
The CLI outputs data from Ditto by writing files to disk in your `ditto/` directory. The format and extension of such files will correspond to the `format` property of your configuration.
|
|
244
229
|
|
|
245
|
-
|
|
246
|
-
|
|
230
|
+
| **Format** | **File Extension** | **Common Usage** |
|
|
231
|
+
| :---------: | :----------------: | :-----------------: |
|
|
232
|
+
| flat | JSON | Web apps |
|
|
233
|
+
| structured | JSON | Web apps |
|
|
234
|
+
| android | XML | Native Android apps |
|
|
235
|
+
| ios-strings | STRINGS | Native iOS apps |
|
|
247
236
|
|
|
248
|
-
|
|
249
|
-
```
|
|
237
|
+
All files created will adhere to the following template:
|
|
250
238
|
|
|
251
|
-
|
|
239
|
+
```
|
|
240
|
+
{source_name}__{variant_name}.{extension}
|
|
241
|
+
```
|
|
252
242
|
|
|
253
|
-
|
|
243
|
+
- `source_name`: the name of a project or `ditto_component_library` for files containing component data
|
|
244
|
+
- `variant_name`: the ID of a variant or `base` for files generated for non-variant text
|
|
245
|
+
- `extension`: the file extension that corresponds to your configured format
|
|
246
|
+
|
|
247
|
+
To help with keeping cross-platform behavior consistent, file names will be fully lowercase, have whitespace replaced with hyphens, and have non-word characters (with the exception of `-` and `_`) removed.
|
|
248
|
+
|
|
249
|
+
If the configured format results in JSON files being generated, an `index.js` "driver file" is also created to simplify the process of integrating Ditto into web apps:
|
|
250
|
+
|
|
251
|
+
```js
|
|
252
|
+
module.exports = {
|
|
253
|
+
ditto_component_library: {
|
|
254
|
+
base: require("./ditto_component_library__base.json"),
|
|
255
|
+
spanish: require("./ditto_component_library__spanish.json"),
|
|
256
|
+
},
|
|
257
|
+
project_xxx: {
|
|
258
|
+
base: require("./example-project__base.json"),
|
|
259
|
+
spanish: require("./example-project__spanish.json"),
|
|
260
|
+
},
|
|
261
|
+
};
|
|
262
|
+
```
|
|
254
263
|
|
|
255
|
-
|
|
264
|
+
The driver file is currently generated as a CommonJS module, but it's possible that ESM will be supported in the future.
|
|
256
265
|
|
|
257
|
-
|
|
266
|
+
## Authentication
|
|
258
267
|
|
|
259
268
|
By default, your API key is saved to `$HOME/.config/ditto`; the default path can be overwritten by specifying a custom one via the environment variable `DITTO_CONFIG_FILE`.
|
|
260
269
|
|
package/bin/add-project.js
CHANGED
|
@@ -7,11 +7,7 @@ const project_1 = require("./init/project");
|
|
|
7
7
|
const projectsToText_1 = __importDefault(require("./utils/projectsToText"));
|
|
8
8
|
const getSelectedProjects_1 = require("./utils/getSelectedProjects");
|
|
9
9
|
const output_1 = __importDefault(require("./output"));
|
|
10
|
-
|
|
11
|
-
console.log("Project selection was not updated.");
|
|
12
|
-
process.exitCode = exitCode;
|
|
13
|
-
process.exit();
|
|
14
|
-
}
|
|
10
|
+
const quit_1 = require("./utils/quit");
|
|
15
11
|
const addProject = async () => {
|
|
16
12
|
const projects = (0, getSelectedProjects_1.getSelectedProjects)();
|
|
17
13
|
const usingComponents = (0, getSelectedProjects_1.getIsUsingComponents)();
|
|
@@ -27,11 +23,13 @@ const addProject = async () => {
|
|
|
27
23
|
else if (projects.length) {
|
|
28
24
|
console.log(`\nYou're currently set up to sync text from the following projects: ${(0, projectsToText_1.default)(projects)}`);
|
|
29
25
|
}
|
|
30
|
-
await (0, project_1.
|
|
26
|
+
await (0, project_1.collectAndSaveSource)({
|
|
27
|
+
components: false,
|
|
28
|
+
});
|
|
31
29
|
}
|
|
32
30
|
catch (error) {
|
|
33
31
|
console.log(`\nSorry, there was an error adding a project to your workspace: `, error);
|
|
34
|
-
quit();
|
|
32
|
+
(0, quit_1.quit)("Project selection was not updated.");
|
|
35
33
|
}
|
|
36
34
|
};
|
|
37
35
|
exports.default = addProject;
|
package/bin/add-project.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"add-project.js","sourceRoot":"","sources":["../lib/add-project.ts"],"names":[],"mappings":";;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"add-project.js","sourceRoot":"","sources":["../lib/add-project.ts"],"names":[],"mappings":";;;;;AAAA,4CAAsD;AACtD,4EAAoD;AACpD,qEAGqC;AACrC,sDAA8B;AAC9B,uCAAoC;AAEpC,MAAM,UAAU,GAAG,KAAK,IAAI,EAAE;IAC5B,MAAM,QAAQ,GAAG,IAAA,yCAAmB,GAAE,CAAC;IACvC,MAAM,eAAe,GAAG,IAAA,0CAAoB,GAAE,CAAC;IAE/C,IAAI;QACF,IAAI,eAAe,EAAE;YACnB,IAAI,QAAQ,CAAC,MAAM,EAAE;gBACnB,OAAO,CAAC,GAAG,CACT,4CAA4C,gBAAM,CAAC,IAAI,CACrD,mBAAmB,CACpB,qCAAqC,IAAA,wBAAc,EAAC,QAAQ,CAAC,EAAE,CACjE,CAAC;aACH;iBAAM;gBACL,OAAO,CAAC,GAAG,CACT,iDAAiD,gBAAM,CAAC,IAAI,CAC1D,mBAAmB,CACpB,EAAE,CACJ,CAAC;aACH;SACF;aAAM,IAAI,QAAQ,CAAC,MAAM,EAAE;YAC1B,OAAO,CAAC,GAAG,CACT,uEAAuE,IAAA,wBAAc,EACnF,QAAQ,CACT,EAAE,CACJ,CAAC;SACH;QACD,MAAM,IAAA,8BAAoB,EAAC;YACzB,UAAU,EAAE,KAAK;SAClB,CAAC,CAAC;KACJ;IAAC,OAAO,KAAK,EAAE;QACd,OAAO,CAAC,GAAG,CACT,kEAAkE,EAClE,KAAK,CACN,CAAC;QACF,IAAA,WAAI,EAAC,oCAAoC,CAAC,CAAC;KAC5C;AACH,CAAC,CAAC;AAEF,kBAAe,UAAU,CAAC"}
|
package/bin/config.js
CHANGED
|
@@ -3,17 +3,29 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_CONFIG = exports.DEFAULT_CONFIG_JSON = void 0;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const path_1 = __importDefault(require("path"));
|
|
8
9
|
const url_1 = __importDefault(require("url"));
|
|
9
10
|
const js_yaml_1 = __importDefault(require("js-yaml"));
|
|
10
11
|
const consts_1 = __importDefault(require("./consts"));
|
|
11
|
-
|
|
12
|
+
exports.DEFAULT_CONFIG_JSON = {
|
|
13
|
+
sources: {
|
|
14
|
+
components: { enabled: true },
|
|
15
|
+
},
|
|
16
|
+
variants: true,
|
|
17
|
+
format: "flat",
|
|
18
|
+
};
|
|
19
|
+
exports.DEFAULT_CONFIG = js_yaml_1.default.dump(exports.DEFAULT_CONFIG_JSON);
|
|
20
|
+
function createFileIfMissing(filename, defaultContents) {
|
|
12
21
|
const dir = path_1.default.dirname(filename);
|
|
22
|
+
// create the directory if it doesn't already exist
|
|
13
23
|
if (!fs_1.default.existsSync(dir))
|
|
14
24
|
fs_1.default.mkdirSync(dir);
|
|
25
|
+
// create the file if it doesn't already exist
|
|
15
26
|
if (!fs_1.default.existsSync(filename)) {
|
|
16
|
-
|
|
27
|
+
// create the file, writing the `defaultContents` if provided
|
|
28
|
+
fs_1.default.writeFileSync(filename, defaultContents || "", "utf-8");
|
|
17
29
|
}
|
|
18
30
|
}
|
|
19
31
|
function jsonIsConfigYAML(json) {
|
|
@@ -22,7 +34,8 @@ function jsonIsConfigYAML(json) {
|
|
|
22
34
|
function jsonIsGlobalYAML(json) {
|
|
23
35
|
return (!!json &&
|
|
24
36
|
typeof json === "object" &&
|
|
25
|
-
Object.values(json).every((arr) => arr.every
|
|
37
|
+
Object.values(json).every((arr) => arr.every &&
|
|
38
|
+
arr.every((val) => typeof val === "object" && Object.keys(val).includes("token"))));
|
|
26
39
|
}
|
|
27
40
|
/**
|
|
28
41
|
* Read data from a project config file
|
|
@@ -31,7 +44,7 @@ function jsonIsGlobalYAML(json) {
|
|
|
31
44
|
* @returns { ConfigYAML }
|
|
32
45
|
*/
|
|
33
46
|
function readProjectConfigData(file = consts_1.default.PROJECT_CONFIG_FILE, defaultData = {}) {
|
|
34
|
-
createFileIfMissing(file);
|
|
47
|
+
createFileIfMissing(file, exports.DEFAULT_CONFIG);
|
|
35
48
|
const fileContents = fs_1.default.readFileSync(file, "utf8");
|
|
36
49
|
const yamlData = js_yaml_1.default.load(fileContents);
|
|
37
50
|
if (jsonIsConfigYAML(yamlData)) {
|
|
@@ -55,9 +68,17 @@ function readGlobalConfigData(file = consts_1.default.CONFIG_FILE, defaultData =
|
|
|
55
68
|
return defaultData;
|
|
56
69
|
}
|
|
57
70
|
function writeProjectConfigData(file, data) {
|
|
58
|
-
createFileIfMissing(file);
|
|
71
|
+
createFileIfMissing(file, exports.DEFAULT_CONFIG);
|
|
59
72
|
const existingData = readProjectConfigData(file);
|
|
60
|
-
const
|
|
73
|
+
const configData = {
|
|
74
|
+
...existingData,
|
|
75
|
+
...data,
|
|
76
|
+
sources: {
|
|
77
|
+
...existingData.sources,
|
|
78
|
+
...data.sources,
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const yamlStr = js_yaml_1.default.dump(configData);
|
|
61
82
|
fs_1.default.writeFileSync(file, yamlStr, "utf8");
|
|
62
83
|
}
|
|
63
84
|
function writeGlobalConfigData(file, data) {
|
|
@@ -130,25 +151,26 @@ function dedupeProjectName(projectNames, projectName) {
|
|
|
130
151
|
* - an array of valid, deduped projects
|
|
131
152
|
* - the `variants` and `format` config options
|
|
132
153
|
*/
|
|
133
|
-
function parseSourceInformation() {
|
|
134
|
-
const {
|
|
154
|
+
function parseSourceInformation(file) {
|
|
155
|
+
const { sources, variants, format, status, richText, projects: projectsRoot, components: componentsRoot, } = readProjectConfigData(file);
|
|
156
|
+
const projects = sources?.projects || [];
|
|
135
157
|
const projectNames = new Set();
|
|
136
158
|
const validProjects = [];
|
|
137
|
-
let
|
|
159
|
+
let hasComponentLibraryInProjects = false;
|
|
138
160
|
(projects || []).forEach((project) => {
|
|
139
161
|
const isValid = project.id && project.name;
|
|
140
162
|
if (!isValid) {
|
|
141
163
|
return;
|
|
142
164
|
}
|
|
143
165
|
if (project.id === "ditto_component_library") {
|
|
144
|
-
|
|
166
|
+
hasComponentLibraryInProjects = true;
|
|
145
167
|
return;
|
|
146
168
|
}
|
|
147
169
|
project.fileName = dedupeProjectName(projectNames, project.name);
|
|
148
170
|
projectNames.add(project.fileName);
|
|
149
171
|
validProjects.push(project);
|
|
150
172
|
});
|
|
151
|
-
const shouldFetchComponentLibrary =
|
|
173
|
+
const shouldFetchComponentLibrary = Boolean(sources?.components?.enabled);
|
|
152
174
|
const hasSourceData = !!validProjects.length || shouldFetchComponentLibrary;
|
|
153
175
|
return {
|
|
154
176
|
hasSourceData,
|
|
@@ -158,6 +180,10 @@ function parseSourceInformation() {
|
|
|
158
180
|
format,
|
|
159
181
|
status,
|
|
160
182
|
richText,
|
|
183
|
+
hasTopLevelProjectsField: !!projectsRoot,
|
|
184
|
+
hasTopLevelComponentsField: !!componentsRoot,
|
|
185
|
+
hasComponentLibraryInProjects,
|
|
186
|
+
componentFolders: sources?.components?.folders || null,
|
|
161
187
|
};
|
|
162
188
|
}
|
|
163
189
|
exports.default = {
|
package/bin/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../lib/config.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../lib/config.ts"],"names":[],"mappings":";;;;;;AAAA,4CAAoB;AACpB,gDAAwB;AACxB,8CAAsB;AACtB,sDAA2B;AAG3B,sDAA8B;AAGjB,QAAA,mBAAmB,GAAe;IAC7C,OAAO,EAAE;QACP,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;KAC9B;IACD,QAAQ,EAAE,IAAI;IACd,MAAM,EAAE,MAAM;CACf,CAAC;AAEW,QAAA,cAAc,GAAG,iBAAI,CAAC,IAAI,CAAC,2BAAmB,CAAC,CAAC;AAE7D,SAAS,mBAAmB,CAAC,QAAgB,EAAE,eAAqB;IAClE,MAAM,GAAG,GAAG,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEnC,mDAAmD;IACnD,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,GAAG,CAAC;QAAE,YAAE,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IAE3C,8CAA8C;IAC9C,IAAI,CAAC,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE;QAC5B,6DAA6D;QAC7D,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,eAAe,IAAI,EAAE,EAAE,OAAO,CAAC,CAAC;KAC5D;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAAa;IACrC,OAAO,OAAO,IAA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