@knocklabs/cli 0.1.13 → 0.1.15
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 +506 -6
- package/dist/{src/commands → commands}/translation/get.js +15 -3
- package/dist/{src/commands → commands}/translation/pull.js +18 -4
- package/dist/{src/commands → commands}/translation/push.js +2 -1
- package/dist/{src/commands → commands}/translation/validate.js +2 -1
- package/dist/{src/lib → lib}/api-v1.js +3 -1
- package/dist/{src/lib → lib}/marshal/translation/helpers.js +33 -8
- package/dist/lib/marshal/translation/processor.isomorphic.js +59 -0
- package/dist/{src/lib → lib}/marshal/translation/reader.js +56 -5
- package/dist/{src/lib → lib}/marshal/translation/writer.js +21 -6
- package/dist/lib/run-context/types.js +4 -0
- package/oclif.manifest.json +1784 -2
- package/package.json +6 -6
- package/dist/src/lib/marshal/translation/processor.isomorphic.js +0 -39
- package/dist/src/lib/marshal/translation/types.js +0 -5
- /package/dist/{src/commands → commands}/commit/get.js +0 -0
- /package/dist/{src/commands → commands}/commit/index.js +0 -0
- /package/dist/{src/commands → commands}/commit/list.js +0 -0
- /package/dist/{src/commands → commands}/commit/promote.js +0 -0
- /package/dist/{src/commands → commands}/knock.js +0 -0
- /package/dist/{src/commands → commands}/layout/get.js +0 -0
- /package/dist/{src/commands → commands}/layout/list.js +0 -0
- /package/dist/{src/commands → commands}/layout/pull.js +0 -0
- /package/dist/{src/commands → commands}/layout/push.js +0 -0
- /package/dist/{src/commands → commands}/layout/validate.js +0 -0
- /package/dist/{src/commands → commands}/ping.js +0 -0
- /package/dist/{src/commands → commands}/translation/list.js +0 -0
- /package/dist/{src/commands → commands}/whoami.js +0 -0
- /package/dist/{src/commands → commands}/workflow/activate.js +0 -0
- /package/dist/{src/commands → commands}/workflow/get.js +0 -0
- /package/dist/{src/commands → commands}/workflow/list.js +0 -0
- /package/dist/{src/commands → commands}/workflow/new.js +0 -0
- /package/dist/{src/commands → commands}/workflow/pull.js +0 -0
- /package/dist/{src/commands → commands}/workflow/push.js +0 -0
- /package/dist/{src/commands → commands}/workflow/run.js +0 -0
- /package/dist/{src/commands → commands}/workflow/validate.js +0 -0
- /package/dist/{src/index.js → index.js} +0 -0
- /package/dist/{src/isomorphic.js → isomorphic.js} +0 -0
- /package/dist/{src/lib → lib}/base-command.js +0 -0
- /package/dist/{src/lib → lib}/helpers/const.js +0 -0
- /package/dist/{src/lib → lib}/helpers/date.js +0 -0
- /package/dist/{src/lib → lib}/helpers/error.js +0 -0
- /package/dist/{src/lib → lib}/helpers/flag.js +0 -0
- /package/dist/{src/lib → lib}/helpers/fs.js +0 -0
- /package/dist/{src/lib → lib}/helpers/json.js +0 -0
- /package/dist/{src/lib → lib}/helpers/liquid.js +0 -0
- /package/dist/{src/lib → lib}/helpers/object.isomorphic.js +0 -0
- /package/dist/{src/lib → lib}/helpers/page.js +0 -0
- /package/dist/{src/lib → lib}/helpers/request.js +0 -0
- /package/dist/{src/lib → lib}/helpers/string.js +0 -0
- /package/dist/{src/lib → lib}/helpers/ux.js +0 -0
- /package/dist/{src/lib → lib}/marshal/commit/helpers.js +0 -0
- /package/dist/{src/lib → lib}/marshal/commit/index.js +0 -0
- /package/dist/{src/lib → lib}/marshal/commit/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/conditions/helpers.js +0 -0
- /package/dist/{src/lib → lib}/marshal/conditions/index.js +0 -0
- /package/dist/{src/lib → lib}/marshal/conditions/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/helpers.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/index.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/processor.isomorphic.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/reader.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/email-layout/writer.js +0 -0
- /package/dist/{src/lib → lib}/marshal/index.isomorphic.js +0 -0
- /package/dist/{src/lib → lib}/marshal/shared/const.isomorphic.js +0 -0
- /package/dist/{src/lib → lib}/marshal/shared/helpers.js +0 -0
- /package/dist/{src/lib → lib}/marshal/shared/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/translation/index.js +0 -0
- /package/dist/{src/lib/run-context → lib/marshal/translation}/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/generator.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/helpers.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/index.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/processor.isomorphic.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/reader.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/types.js +0 -0
- /package/dist/{src/lib → lib}/marshal/workflow/writer.js +0 -0
- /package/dist/{src/lib → lib}/run-context/helpers.js +0 -0
- /package/dist/{src/lib → lib}/run-context/index.js +0 -0
- /package/dist/{src/lib → lib}/run-context/loader.js +0 -0
- /package/dist/{src/lib → lib}/user-config.js +0 -0
|
@@ -104,15 +104,15 @@ const isTranslationDir = (dirPath)=>{
|
|
|
104
104
|
const locale = _nodepath.basename(dirPath);
|
|
105
105
|
return isValidLocale(locale);
|
|
106
106
|
};
|
|
107
|
-
const buildTranslationFileCtx = async (dirPath,
|
|
108
|
-
const ref = (0, _processorisomorphic.formatRef)(localeCode, namespace);
|
|
109
|
-
const filename = (0, _processorisomorphic.formatFileName)(ref);
|
|
107
|
+
const buildTranslationFileCtx = async (dirPath, translationIdentifier, options)=>{
|
|
108
|
+
const ref = (0, _processorisomorphic.formatRef)(translationIdentifier.localeCode, translationIdentifier.namespace);
|
|
109
|
+
const filename = (0, _processorisomorphic.formatFileName)(ref, options);
|
|
110
110
|
const abspath = _nodepath.resolve(dirPath, filename);
|
|
111
111
|
const exists = await _fsextra.pathExists(abspath);
|
|
112
112
|
return {
|
|
113
113
|
ref,
|
|
114
|
-
localeCode,
|
|
115
|
-
namespace,
|
|
114
|
+
localeCode: translationIdentifier.localeCode,
|
|
115
|
+
namespace: translationIdentifier.namespace,
|
|
116
116
|
abspath,
|
|
117
117
|
exists
|
|
118
118
|
};
|
|
@@ -182,10 +182,34 @@ const ensureValidCommandTarget = async (props, runContext)=>{
|
|
|
182
182
|
// Got translationRef arg but no --all flag, which means target only a single
|
|
183
183
|
// translation file.
|
|
184
184
|
if (!flags.all) {
|
|
185
|
-
|
|
185
|
+
// If specified, check the given format; otherwise check for all supported formats
|
|
186
|
+
const formats = flags.format ? [
|
|
187
|
+
flags.format
|
|
188
|
+
] : _processorisomorphic.SUPPORTED_TRANSLATION_FORMATS;
|
|
189
|
+
const translationFileCtxs = await Promise.all(formats.map(async (format)=>buildTranslationFileCtx(targetDirPath, {
|
|
190
|
+
localeCode,
|
|
191
|
+
namespace
|
|
192
|
+
}, {
|
|
193
|
+
format
|
|
194
|
+
})));
|
|
195
|
+
if (flags.format) {
|
|
196
|
+
return {
|
|
197
|
+
type: "translationFile",
|
|
198
|
+
context: translationFileCtxs[0]
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
// If no format is specified, look for the first existing file and return that context
|
|
202
|
+
const existingFileCtx = translationFileCtxs.find((ctx)=>ctx.exists);
|
|
203
|
+
if (existingFileCtx) {
|
|
204
|
+
return {
|
|
205
|
+
type: "translationFile",
|
|
206
|
+
context: existingFileCtx
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
// If no file exists, fall back to the file context with the default format (json)
|
|
186
210
|
return {
|
|
187
211
|
type: "translationFile",
|
|
188
|
-
context:
|
|
212
|
+
context: translationFileCtxs[0]
|
|
189
213
|
};
|
|
190
214
|
}
|
|
191
215
|
// From this point on, we have both translationRef and --all flag used
|
|
@@ -212,7 +236,8 @@ const lsTranslationDir = async (pathToDir)=>{
|
|
|
212
236
|
return dirents.filter((dirent)=>{
|
|
213
237
|
if (dirent.isDirectory()) return false;
|
|
214
238
|
const filename = dirent.name.toLowerCase();
|
|
215
|
-
|
|
239
|
+
const isValidExtension = _processorisomorphic.SUPPORTED_TRANSLATION_FORMATS.some((extension)=>filename.endsWith(`${localeCode}.${extension}`));
|
|
240
|
+
if (!isValidExtension) return false;
|
|
216
241
|
const { name: translationRef } = _nodepath.parse(filename);
|
|
217
242
|
const parsedRef = parseTranslationRef(translationRef);
|
|
218
243
|
if (!parsedRef) return false;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
DEFAULT_TRANSLATION_FORMAT: function() {
|
|
13
|
+
return DEFAULT_TRANSLATION_FORMAT;
|
|
14
|
+
},
|
|
15
|
+
SUPPORTED_TRANSLATION_FORMATS: function() {
|
|
16
|
+
return SUPPORTED_TRANSLATION_FORMATS;
|
|
17
|
+
},
|
|
18
|
+
buildTranslationDirBundle: function() {
|
|
19
|
+
return buildTranslationDirBundle;
|
|
20
|
+
},
|
|
21
|
+
formatFileName: function() {
|
|
22
|
+
return formatFileName;
|
|
23
|
+
},
|
|
24
|
+
formatRef: function() {
|
|
25
|
+
return formatRef;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const SUPPORTED_TRANSLATION_FORMATS = [
|
|
29
|
+
"json",
|
|
30
|
+
"po"
|
|
31
|
+
];
|
|
32
|
+
const DEFAULT_TRANSLATION_FORMAT = "json";
|
|
33
|
+
const formatRef = (localeCode, namespace)=>namespace ? `${namespace}.${localeCode}` : localeCode;
|
|
34
|
+
const formatFileName = (input, options)=>{
|
|
35
|
+
var _options_format;
|
|
36
|
+
const extension = (_options_format = options === null || options === void 0 ? void 0 : options.format) !== null && _options_format !== void 0 ? _options_format : DEFAULT_TRANSLATION_FORMAT;
|
|
37
|
+
const ref = typeof input === "string" ? input : formatRef(input.locale_code, input.namespace);
|
|
38
|
+
return `${ref}.${extension}`;
|
|
39
|
+
};
|
|
40
|
+
const buildTranslationDirBundle = (input, options)=>{
|
|
41
|
+
var _options_format;
|
|
42
|
+
const format = (_options_format = options === null || options === void 0 ? void 0 : options.format) !== null && _options_format !== void 0 ? _options_format : DEFAULT_TRANSLATION_FORMAT;
|
|
43
|
+
if (Array.isArray(input)) {
|
|
44
|
+
const translations = input;
|
|
45
|
+
return Object.fromEntries(translations.map((translation)=>[
|
|
46
|
+
formatFileName(translation, {
|
|
47
|
+
format
|
|
48
|
+
}),
|
|
49
|
+
JSON.parse(translation.content)
|
|
50
|
+
]));
|
|
51
|
+
}
|
|
52
|
+
const translation = input;
|
|
53
|
+
const content = format === "json" ? JSON.parse(translation.content) : translation.content;
|
|
54
|
+
return {
|
|
55
|
+
[formatFileName(translation, {
|
|
56
|
+
format
|
|
57
|
+
})]: content
|
|
58
|
+
};
|
|
59
|
+
};
|
|
@@ -14,6 +14,7 @@ const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
|
14
14
|
const _error = require("../../helpers/error");
|
|
15
15
|
const _json = require("../../helpers/json");
|
|
16
16
|
const _helpers = require("./helpers");
|
|
17
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
17
18
|
function _getRequireWildcardCache(nodeInterop) {
|
|
18
19
|
if (typeof WeakMap !== "function") return null;
|
|
19
20
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -76,10 +77,9 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
76
77
|
// push commands. Consider making this an option in the future.
|
|
77
78
|
if (namespace === _helpers.SYSTEM_NAMESPACE) continue;
|
|
78
79
|
// eslint-disable-next-line no-await-in-loop
|
|
79
|
-
const [content,
|
|
80
|
-
if (
|
|
81
|
-
|
|
82
|
-
errors.push(e);
|
|
80
|
+
const [content, sourceError, format] = await readTranslationFile(abspath);
|
|
81
|
+
if (sourceError) {
|
|
82
|
+
errors.push(sourceError);
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
85
|
translations.push({
|
|
@@ -88,7 +88,8 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
88
88
|
namespace,
|
|
89
89
|
abspath,
|
|
90
90
|
exists: true,
|
|
91
|
-
content
|
|
91
|
+
content,
|
|
92
|
+
format
|
|
92
93
|
});
|
|
93
94
|
}
|
|
94
95
|
return [
|
|
@@ -96,6 +97,56 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
96
97
|
errors
|
|
97
98
|
];
|
|
98
99
|
};
|
|
100
|
+
const readTranslationFile = async (filePath)=>{
|
|
101
|
+
// Get translation format from file extension
|
|
102
|
+
const format = getFormatFromFilePath(filePath);
|
|
103
|
+
switch(format){
|
|
104
|
+
case "json":
|
|
105
|
+
{
|
|
106
|
+
const [jsonContent, readErrors] = await (0, _json.readJson)(filePath);
|
|
107
|
+
if (readErrors.length > 0) {
|
|
108
|
+
const e = new _error.SourceError((0, _error.formatErrors)(readErrors), filePath);
|
|
109
|
+
return [
|
|
110
|
+
undefined,
|
|
111
|
+
e,
|
|
112
|
+
format
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
const content = JSON.stringify(jsonContent);
|
|
116
|
+
return [
|
|
117
|
+
content,
|
|
118
|
+
undefined,
|
|
119
|
+
format
|
|
120
|
+
];
|
|
121
|
+
}
|
|
122
|
+
case "po":
|
|
123
|
+
{
|
|
124
|
+
try {
|
|
125
|
+
const content = await _fsextra.readFile(filePath, "utf8");
|
|
126
|
+
return [
|
|
127
|
+
content,
|
|
128
|
+
undefined,
|
|
129
|
+
format
|
|
130
|
+
];
|
|
131
|
+
} catch (error) {
|
|
132
|
+
const e = new _error.SourceError(error.message, filePath);
|
|
133
|
+
return [
|
|
134
|
+
undefined,
|
|
135
|
+
e,
|
|
136
|
+
format
|
|
137
|
+
];
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
default:
|
|
141
|
+
throw new Error(`unsupported translation file extension: ${filePath}`);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getFormatFromFilePath = (filePath)=>{
|
|
145
|
+
// Path.extname returns the extension with a period (e.g. .json)
|
|
146
|
+
// so we use slice to get just the name
|
|
147
|
+
const extension = _nodepath.extname(filePath).slice(1);
|
|
148
|
+
return _processorisomorphic.SUPPORTED_TRANSLATION_FORMATS.includes(extension) ? extension : undefined;
|
|
149
|
+
};
|
|
99
150
|
const readAllForCommandTarget = async (target)=>{
|
|
100
151
|
const { type: targetType, context: targetCtx } = target;
|
|
101
152
|
if (!targetCtx.exists) {
|
|
@@ -22,6 +22,7 @@ const _lodash = require("lodash");
|
|
|
22
22
|
const _const = require("../../helpers/const");
|
|
23
23
|
const _json = require("../../helpers/json");
|
|
24
24
|
const _helpers = require("./helpers");
|
|
25
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
25
26
|
function _getRequireWildcardCache(nodeInterop) {
|
|
26
27
|
if (typeof WeakMap !== "function") return null;
|
|
27
28
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -63,10 +64,21 @@ function _interop_require_wildcard(obj, nodeInterop) {
|
|
|
63
64
|
}
|
|
64
65
|
return newObj;
|
|
65
66
|
}
|
|
66
|
-
const writeTranslationFile = async (translationFileCtx, translation
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const writeTranslationFile = async (translationFileCtx, translation, options)=>{
|
|
68
|
+
var _options_format;
|
|
69
|
+
const format = (_options_format = options === null || options === void 0 ? void 0 : options.format) !== null && _options_format !== void 0 ? _options_format : _processorisomorphic.DEFAULT_TRANSLATION_FORMAT;
|
|
70
|
+
switch(format){
|
|
71
|
+
case "json":
|
|
72
|
+
return _fsextra.outputJson(translationFileCtx.abspath, JSON.parse(translation.content), {
|
|
73
|
+
spaces: _json.DOUBLE_SPACES
|
|
74
|
+
});
|
|
75
|
+
case "po":
|
|
76
|
+
return _fsextra.outputFile(translationFileCtx.abspath, translation.content);
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`Invalid translation file format: ${options === null || options === void 0 ? void 0 : options.format}`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const writeTranslationFiles = async (targetDirCtx, translations, options)=>{
|
|
70
82
|
const backupDirPath = _nodepath.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
71
83
|
try {
|
|
72
84
|
// If the index directory already exists, back it up in the temp sandbox
|
|
@@ -81,8 +93,11 @@ const writeTranslationFiles = async (targetDirCtx, translations)=>{
|
|
|
81
93
|
// to write translation files in; otherwise for translations index
|
|
82
94
|
// directory, we want to nest translation files under each locale dir.
|
|
83
95
|
const localeDirPath = "key" in targetDirCtx ? targetDirCtx.abspath : _nodepath.resolve(targetDirCtx.abspath, translation.locale_code);
|
|
84
|
-
const translationFileCtx = await (0, _helpers.buildTranslationFileCtx)(localeDirPath,
|
|
85
|
-
|
|
96
|
+
const translationFileCtx = await (0, _helpers.buildTranslationFileCtx)(localeDirPath, {
|
|
97
|
+
localeCode: translation.locale_code,
|
|
98
|
+
namespace: translation.namespace
|
|
99
|
+
}, options);
|
|
100
|
+
return writeTranslationFile(translationFileCtx, translation, options);
|
|
86
101
|
});
|
|
87
102
|
await Promise.all(writeTranslationDirPromises);
|
|
88
103
|
} catch (error) {
|