@dittowords/cli 5.0.0-beta.3 → 5.0.0-beta.4
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 +66 -2
- package/bin/ditto.js +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,75 @@
|
|
|
1
|
-
# Ditto CLI
|
|
1
|
+
# Ditto CLI v5
|
|
2
2
|
|
|
3
|
-
The Ditto CLI enables developers to access the Ditto API directly from the command line.
|
|
3
|
+
The Ditto CLI enables developers to access the Ditto API directly from the command line. The v5 version of the CLI defaults to use the new Ditto Beta by default, but still fully supports legacy configurations and projects by passing in a `--legacy` flag to all invocations.
|
|
4
4
|
|
|
5
5
|
[](https://badge.fury.io/js/@dittowords%2Fcli)
|
|
6
6
|
|
|
7
7
|
## Documentation
|
|
8
8
|
|
|
9
|
+
The official documentation can be found [here](https://dittov3.notion.site/Beta-Developer-Integrations-1d8cc8865c7a800eb13dc54d10c3d231).
|
|
10
|
+
|
|
11
|
+
## Support
|
|
12
|
+
|
|
13
|
+
- [Bug Reports](https://github.com/dittowords/cli/issues/)
|
|
14
|
+
- [Support Chat](https://www.dittowords.com)
|
|
15
|
+
- [What is Ditto?](https://www.dittowords.com/docs/what-is-ditto)
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install --save-dev @dittowords/cli@beta
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
It's recommended to install the CLI as a development dependency to ensure your whole team is on the same version.
|
|
24
|
+
|
|
25
|
+
## Authentication
|
|
26
|
+
|
|
27
|
+
The first time you run the CLI, you’ll be asked to provide an API key. You can generate an API key from your [developer integrations settings](https://app.dittowords.com/account/devtools).
|
|
28
|
+
|
|
29
|
+
See the [Authentication](http://developer.dittowords.com/api-reference/authentication) page for more information on API keys.
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
By default, the CLI operates against a `ditto/` folder relative to the current working directory.
|
|
34
|
+
|
|
35
|
+
The first time you run the CLI, a `ditto/` folder will be created if it doesn't already exist. The folder will also be populated with a default `config.yml` file, which is used to control the CLI's behavior.
|
|
36
|
+
|
|
37
|
+
The default file looks like this:
|
|
38
|
+
|
|
39
|
+
```yml
|
|
40
|
+
projects: [],
|
|
41
|
+
variants: [],
|
|
42
|
+
outputs:
|
|
43
|
+
- format: json,
|
|
44
|
+
framework: i18next
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
For more information on configuring the CLI, see [this documentation section](https://dittov3.notion.site/Beta-Developer-Integrations-1d8cc8865c7a800eb13dc54d10c3d231#1d8cc8865c7a80e68ebbeb083404d8ed).
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx @dittowords/cli
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Run the CLI to pull string data from Ditto and write it to disk.
|
|
56
|
+
|
|
57
|
+
String files are written to the `ditto` folder in a format that corresponds to your configuration. After integrating these files into development, you can execute the CLI at any time to fetch the latest strings from Ditto and update them in your application.
|
|
58
|
+
|
|
59
|
+
For more information on how files written to disk, see [this documentation section](https://dittov3.notion.site/Beta-Developer-Integrations-1d8cc8865c7a800eb13dc54d10c3d231#1d8cc8865c7a80c7bd4fe6f5f254f4d4).
|
|
60
|
+
|
|
61
|
+
See our demo projects for examples of how to integrate the Ditto CLI in different environments:
|
|
62
|
+
|
|
63
|
+
- [React web app](https://github.com/dittowords/ditto-react-demo)
|
|
64
|
+
- [iOS mobile app](https://github.com/dittowords/ditto-react-demo)
|
|
65
|
+
- [Android mobile app](https://github.com/dittowords/ditto-react-demo)
|
|
66
|
+
|
|
67
|
+
# Legacy Setup
|
|
68
|
+
|
|
69
|
+
v5 of the Ditto CLI points at the new Ditto beta experience by default. To run the CLI compatible with legacy Ditto, append the `--legacy` flag, and the CLI will work as it did in the `4.x` version. All existing legecy commands are depricated, but fully functional at this time.
|
|
70
|
+
|
|
71
|
+
## Documentation
|
|
72
|
+
|
|
9
73
|
The official documentation can be found [here](http://developer.dittowords.com/cli-reference/authentication).
|
|
10
74
|
|
|
11
75
|
## Support
|
package/bin/ditto.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="
|
|
4
|
-
var Dr=Object.create;var re=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var _r=Object.getPrototypeOf,Mr=Object.prototype.hasOwnProperty;var Ue=t=>{throw TypeError(t)};var r=(t,e)=>re(t,"name",{value:e,configurable:!0});var Rr=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Nr(e))!Mr.call(t,s)&&s!==o&&re(t,s,{get:()=>e[s],enumerable:!(n=Ar(e,s))||n.enumerable});return t};var l=(t,e,o)=>(o=t!=null?Dr(_r(t)):{},Rr(e||!t||!t.__esModule?re(o,"default",{value:t,enumerable:!0}):o,t));var qe=(t,e,o)=>e.has(t)||Ue("Cannot "+o);var E=(t,e,o)=>(qe(t,e,"read from private field"),o?o.call(t):e.get(t)),L=(t,e,o)=>e.has(t)?Ue("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,o),N=(t,e,o,n)=>(qe(t,e,"write to private field"),n?n.call(t,o):e.set(t,o),o);var Sr=l(require("@sentry/node"));var rt="5.0.0-beta.
|
|
3
|
+
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="8103f612-e8c4-5558-8c03-518699445a98")}catch(e){}}();
|
|
4
|
+
var Dr=Object.create;var re=Object.defineProperty;var Ar=Object.getOwnPropertyDescriptor;var Nr=Object.getOwnPropertyNames;var _r=Object.getPrototypeOf,Mr=Object.prototype.hasOwnProperty;var Ue=t=>{throw TypeError(t)};var r=(t,e)=>re(t,"name",{value:e,configurable:!0});var Rr=(t,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Nr(e))!Mr.call(t,s)&&s!==o&&re(t,s,{get:()=>e[s],enumerable:!(n=Ar(e,s))||n.enumerable});return t};var l=(t,e,o)=>(o=t!=null?Dr(_r(t)):{},Rr(e||!t||!t.__esModule?re(o,"default",{value:t,enumerable:!0}):o,t));var qe=(t,e,o)=>e.has(t)||Ue("Cannot "+o);var E=(t,e,o)=>(qe(t,e,"read from private field"),o?o.call(t):e.get(t)),L=(t,e,o)=>e.has(t)?Ue("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,o),N=(t,e,o,n)=>(qe(t,e,"write to private field"),n?n.call(t,o):e.set(t,o),o);var Sr=l(require("@sentry/node"));var rt="5.0.0-beta.4";var U=require("commander");var mo=l(require("boxen")),Vt=l(require("chalk"));var po=l(require("ora"));var eo=l(require("axios"));var J=l(require("fs")),Xe=l(require("path")),Ze=l(require("url")),st=l(require("js-yaml")),Ke=l(require("@sentry/node"));var We=require("os"),nt=l(require("path")),u=new class{get API_HOST(){return process.env.DITTO_API_HOST||"https://api.dittowords.com"}get CONFIG_FILE(){return process.env.DITTO_CONFIG_FILE||nt.default.join((0,We.homedir)(),".config","ditto")}get PROJECT_CONFIG_FILE(){return nt.default.normalize(nt.default.join("ditto","config.yml"))}get TEXT_DIR(){return process.env.DITTO_TEXT_DIR||"ditto"}get TEXT_FILE(){return nt.default.normalize(nt.default.join(this.TEXT_DIR,"text.json"))}};function ze(t){if(typeof t!="object")return{};let e={};for(let o in t){let n=o,s=t[n];e[n]=typeof s=="object"||Array.isArray(s)?JSON.stringify(s):s}return e}r(ze,"createSentryContext");var Lr={sources:{components:!0},variants:!0,format:"flat"},Qe=st.default.dump(Lr);function St(t,e){let o=Xe.default.dirname(t);J.default.existsSync(o)||J.default.mkdirSync(o),J.default.existsSync(t)||J.default.writeFileSync(t,e||"","utf-8")}r(St,"createFileIfMissing");function Jr(t){return typeof t=="object"}r(Jr,"jsonIsConfigYAML");function Yr(t){return!!t&&typeof t=="object"&&Object.values(t).every(e=>e.every&&e.every(o=>typeof o=="object"&&Object.keys(o).includes("token")))}r(Yr,"jsonIsGlobalYAML");function ne(t=u.PROJECT_CONFIG_FILE,e={}){St(t,Qe);let o=J.default.readFileSync(t,"utf8"),n=st.default.load(o);return Jr(n)?n:e}r(ne,"readProjectConfigData");function wt(t=u.CONFIG_FILE,e={}){St(t);let o=J.default.readFileSync(t,"utf8"),n=st.default.load(o);return Yr(n)?n:e}r(wt,"readGlobalConfigData");function Vr(t,e){St(t,Qe);let o=ne(t),n={...o,...e,sources:{...o.sources,...e.sources}},s=st.default.dump(n);J.default.writeFileSync(t,s,"utf8")}r(Vr,"writeProjectConfigData");function se(t,e){St(t);let o=wt(t),n=st.default.dump({...o,...e});J.default.writeFileSync(t,n,"utf8")}r(se,"writeGlobalConfigData");function Lt(t){return t.includes("://")?Ze.default.parse(t).hostname||"":t}r(Lt,"justTheHost");function Br(t,e){let o=wt(t),n=Lt(e);o[n]=[],o[n][0]={token:""},se(t,o)}r(Br,"deleteToken");function Gr(t,e,o){let n=wt(t),s=Lt(e);n[s]=[],n[s][0]={token:o},se(t,n)}r(Gr,"saveToken");function to(){return process.env.DITTO_API_KEY}r(to,"getTokenFromEnv");function Ur(t,e){let o=to();if(o)return o;let s=wt(t)[Lt(e)];if(!s)return;let{length:i}=s;return s[i-1].token}r(Ur,"getToken");var He=/-(\d+$)/;function qr(t,e){let o=e;if(t.has(o))for(;t.has(o);){let[n,s]=o.match(He)||[];s&&!isNaN(parseInt(s))?o=`${o.replace(He,"")}-${parseInt(s)+1}`:o=`${o}-1`}return o}r(qr,"dedupeProjectName");function Wr(t){let{sources:e,variants:o,format:n,status:s,richText:i,iosLocales:a,projects:c,components:m,disableJsDriver:y}=ne(t),f=e?.projects||[],d=new Set,S=[],x=!1;(f||[]).forEach(P=>{if(P.id&&P.name){if(P.id==="ditto_component_library"){x=!0;return}P.fileName=qr(d,P.name),d.add(P.fileName),S.push(P)}});let I=!!e?.components,_=typeof e?.components=="object"?e.components.root:void 0,F=typeof e?.components=="object"?e.components.folders:void 0,C={hasSourceData:!!S.length||I,validProjects:S,shouldFetchComponentLibrary:I,variants:o||!1,format:n,status:s,richText:i,hasTopLevelProjectsField:!!c,hasTopLevelComponentsField:!!m,hasComponentLibraryInProjects:x,componentRoot:_,componentFolders:F,localeByVariantApiId:a?a.reduce((P,et)=>({...P,...et}),{}):void 0,disableJsDriver:y};return Ke.setContext("config",ze(C)),C}r(Wr,"parseSourceInformation");var w={createFileIfMissing:St,readProjectConfigData:ne,readGlobalConfigData:wt,writeGlobalConfigData:se,writeProjectConfigData:Vr,justTheHost:Lt,saveToken:Gr,deleteToken:Br,getToken:Ur,getTokenFromEnv:to,parseSourceInformation:Wr};function j(t){return eo.default.create({baseURL:u.API_HOST,headers:{Authorization:`token ${t||w.getToken(u.CONFIG_FILE,u.API_HOST)}`,"x-ditto-cli":!0}})}r(j,"createApiClient");var B=l(require("chalk"));var zr=r(t=>B.default.magenta(t),"errorText"),Hr=r(t=>B.default.yellow(t),"warnText"),Xr=r(t=>B.default.blueBright(t),"info"),Zr=r(t=>B.default.green(t),"success"),Kr=r(t=>B.default.blueBright.underline(t),"url"),Qr=r(t=>B.default.grey(t),"subtle"),tn=r(t=>B.default.white(t),"write"),en=r(()=>console.log(`
|
|
5
5
|
`),"nl"),p={errorText:zr,warnText:Hr,info:Xr,success:Zr,url:Kr,subtle:Qr,write:tn,nl:en};var ro=l(require("fs")),no=l(require("@sentry/node")),so=l(require("chalk")),io=require("enquirer");var oo=l(require("@sentry/node"));async function b(t,e=2){t&&console.log(`
|
|
6
6
|
${t}
|
|
7
7
|
`),await oo.flush(),process.exit(e)}r(b,"quit");var ao=require("axios");var ie=r((t,e=u.API_HOST)=>{if(w.getTokenFromEnv())return!1;let o=t||u.CONFIG_FILE;if(!ro.default.existsSync(o))return!0;let n=w.readGlobalConfigData(o);return!n[w.justTheHost(e)]||n[w.justTheHost(e)][0].token===""},"needsToken");async function on(t){let e=j(t),o="/token-check",n;try{n=await e.get(o)}catch(s){if(!(s instanceof ao.AxiosError))return{success:!1,output:[p.warnText("Sorry! We're having trouble reaching the Ditto API.")]};if(s.code==="ENOTFOUND")return{success:!1,output:[p.errorText(`Can't connect to API: ${p.url(u.API_HOST)}`)]};if(s.response?.status===401||s.response?.status===404)return{success:!1,output:[p.errorText("This API key isn't valid. Please try another.")]}}return typeof n=="string"?{success:!1,output:[n]}:n?.status===200?{success:!0}:{success:!1,output:[p.errorText("This API key isn't valid. Please try another.")]}}r(on,"verifyTokenUsingTokenCheck");async function rn(t){let e=await on(t);return e.success?!0:e.output.join(`
|
|
@@ -117,4 +117,4 @@ Error ID: ${T.info(a)}`;return await dt(T.errorText(i)+c,s)}},"executeCommand"),
|
|
|
117
117
|
Ditto CLI is running in legacy mode. This mode is deprecated and will be removed in a future release.
|
|
118
118
|
`)),qo()):Tr()},"main");_s();
|
|
119
119
|
|
|
120
|
-
//# debugId=
|
|
120
|
+
//# debugId=8103f612-e8c4-5558-8c03-518699445a98
|