@knocklabs/cli 0.1.22 → 0.1.23
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 +102 -43
- package/dist/commands/commit/list.js +21 -1
- package/dist/commands/guide/activate.js +121 -0
- package/dist/commands/guide/generate-types.js +148 -0
- package/dist/commands/guide/get.js +139 -0
- package/dist/commands/guide/list.js +112 -0
- package/dist/commands/guide/pull.js +209 -0
- package/dist/commands/guide/push.js +171 -0
- package/dist/commands/guide/validate.js +148 -0
- package/dist/commands/workflow/generate-types.js +6 -5
- package/dist/lib/api-v1.js +61 -0
- package/dist/lib/helpers/const.js +4 -4
- package/dist/lib/helpers/date.js +3 -3
- package/dist/lib/helpers/error.js +8 -8
- package/dist/lib/helpers/flag.js +7 -7
- package/dist/lib/helpers/json.js +5 -5
- package/dist/lib/helpers/object.isomorphic.js +8 -8
- package/dist/lib/helpers/page.js +9 -9
- package/dist/lib/helpers/request.js +4 -4
- package/dist/lib/helpers/string.js +3 -3
- package/dist/lib/helpers/typegen.js +59 -0
- package/dist/lib/helpers/ux.js +3 -3
- package/dist/lib/marshal/email-layout/helpers.js +5 -5
- package/dist/lib/marshal/email-layout/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/email-layout/reader.js +5 -5
- package/dist/lib/marshal/email-layout/writer.js +4 -4
- package/dist/lib/marshal/guide/helpers.js +283 -0
- package/dist/lib/marshal/guide/index.js +3 -0
- package/dist/lib/marshal/guide/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/guide/reader.js +193 -0
- package/dist/lib/marshal/guide/writer.js +175 -0
- package/dist/lib/marshal/index.isomorphic.js +7 -7
- package/dist/lib/marshal/message-type/helpers.js +5 -5
- package/dist/lib/marshal/message-type/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/message-type/reader.js +5 -5
- package/dist/lib/marshal/message-type/writer.js +4 -4
- package/dist/lib/marshal/partial/helpers.js +5 -5
- package/dist/lib/marshal/partial/processor.isomorphic.js +3 -3
- package/dist/lib/marshal/partial/reader.js +5 -5
- package/dist/lib/marshal/partial/writer.js +4 -4
- package/dist/lib/marshal/shared/const.isomorphic.js +3 -3
- package/dist/lib/marshal/shared/helpers.isomorphic.js +9 -2
- package/dist/lib/marshal/shared/helpers.js +4 -4
- package/dist/lib/marshal/translation/helpers.js +10 -10
- package/dist/lib/marshal/translation/processor.isomorphic.js +6 -6
- package/dist/lib/marshal/translation/writer.js +3 -3
- package/dist/lib/marshal/workflow/generator.js +4 -4
- package/dist/lib/marshal/workflow/helpers.js +53 -10
- package/dist/lib/marshal/workflow/processor.isomorphic.js +5 -5
- package/dist/lib/marshal/workflow/reader.js +5 -5
- package/dist/lib/marshal/workflow/writer.js +5 -5
- package/dist/lib/resources.js +3 -3
- package/oclif.manifest.json +615 -54
- package/package.json +8 -8
- package/dist/lib/type-generator.js +0 -100
|
@@ -7,14 +7,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
function _export(target, all) {
|
|
8
8
|
for(var name in all)Object.defineProperty(target, name, {
|
|
9
9
|
enumerable: true,
|
|
10
|
-
get: all
|
|
10
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
_export(exports, {
|
|
14
|
-
checkSlugifiedFormat
|
|
14
|
+
get checkSlugifiedFormat () {
|
|
15
15
|
return checkSlugifiedFormat;
|
|
16
16
|
},
|
|
17
|
-
indentString
|
|
17
|
+
get indentString () {
|
|
18
18
|
return indentString;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
@@ -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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get getLanguageFromExtension () {
|
|
13
|
+
return getLanguageFromExtension;
|
|
14
|
+
},
|
|
15
|
+
get supportedExtensions () {
|
|
16
|
+
return supportedExtensions;
|
|
17
|
+
},
|
|
18
|
+
get transformSchema () {
|
|
19
|
+
return transformSchema;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const supportedExtensions = [
|
|
23
|
+
".ts",
|
|
24
|
+
".py",
|
|
25
|
+
".go",
|
|
26
|
+
".rb"
|
|
27
|
+
];
|
|
28
|
+
function getLanguageFromExtension(extension) {
|
|
29
|
+
switch(extension){
|
|
30
|
+
case "ts":
|
|
31
|
+
case ".ts":
|
|
32
|
+
return "typescript";
|
|
33
|
+
case "py":
|
|
34
|
+
case ".py":
|
|
35
|
+
return "python";
|
|
36
|
+
case "go":
|
|
37
|
+
case ".go":
|
|
38
|
+
return "go";
|
|
39
|
+
case "rb":
|
|
40
|
+
case ".rb":
|
|
41
|
+
return "ruby";
|
|
42
|
+
default:
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function transformSchema(schema) {
|
|
47
|
+
if (schema.type === "object" && !schema.additionalProperties) {
|
|
48
|
+
schema.additionalProperties = false;
|
|
49
|
+
}
|
|
50
|
+
var _schema_properties;
|
|
51
|
+
for (const key of Object.keys((_schema_properties = schema.properties) !== null && _schema_properties !== void 0 ? _schema_properties : {})){
|
|
52
|
+
const property = schema.properties[key];
|
|
53
|
+
if (property.type === "object") {
|
|
54
|
+
const transformedProperty = transformSchema(property);
|
|
55
|
+
schema.properties[key] = transformedProperty;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
return schema;
|
|
59
|
+
}
|
package/dist/lib/helpers/ux.js
CHANGED
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
promptToConfirm
|
|
12
|
+
get promptToConfirm () {
|
|
13
13
|
return promptToConfirm;
|
|
14
14
|
},
|
|
15
|
-
spinner
|
|
15
|
+
get spinner () {
|
|
16
16
|
return spinner;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -5,20 +5,20 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
emailLayoutJsonPath
|
|
12
|
+
get emailLayoutJsonPath () {
|
|
13
13
|
return emailLayoutJsonPath;
|
|
14
14
|
},
|
|
15
|
-
ensureValidCommandTarget
|
|
15
|
+
get ensureValidCommandTarget () {
|
|
16
16
|
return ensureValidCommandTarget;
|
|
17
17
|
},
|
|
18
|
-
isEmailLayoutDir
|
|
18
|
+
get isEmailLayoutDir () {
|
|
19
19
|
return isEmailLayoutDir;
|
|
20
20
|
},
|
|
21
|
-
lsEmailLayoutJson
|
|
21
|
+
get lsEmailLayoutJson () {
|
|
22
22
|
return lsEmailLayoutJson;
|
|
23
23
|
}
|
|
24
24
|
});
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
LAYOUT_JSON
|
|
12
|
+
get LAYOUT_JSON () {
|
|
13
13
|
return LAYOUT_JSON;
|
|
14
14
|
},
|
|
15
|
-
buildEmailLayoutDirBundle
|
|
15
|
+
get buildEmailLayoutDirBundle () {
|
|
16
16
|
return buildEmailLayoutDirBundle;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
readAllForCommandTarget
|
|
12
|
+
get readAllForCommandTarget () {
|
|
13
13
|
return readAllForCommandTarget;
|
|
14
14
|
},
|
|
15
|
-
readEmailLayoutDir
|
|
15
|
+
get readEmailLayoutDir () {
|
|
16
16
|
return readEmailLayoutDir;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
@@ -135,7 +135,7 @@ const readAllForCommandTarget = async (target, opts = {})=>{
|
|
|
135
135
|
};
|
|
136
136
|
const readEmailLayoutDir = async (layoutDirCtx, opts = {})=>{
|
|
137
137
|
const { abspath } = layoutDirCtx;
|
|
138
|
-
const { withExtractedFiles = false
|
|
138
|
+
const { withExtractedFiles = false } = opts;
|
|
139
139
|
const dirExists = await _fsextra.pathExists(abspath);
|
|
140
140
|
if (!dirExists) throw new Error(`${abspath} does not exist`);
|
|
141
141
|
const layoutJsonPath = await (0, _helpers1.lsEmailLayoutJson)(abspath);
|
|
@@ -143,7 +143,7 @@ const readEmailLayoutDir = async (layoutDirCtx, opts = {})=>{
|
|
|
143
143
|
const result = await (0, _json.readJson)(layoutJsonPath);
|
|
144
144
|
if (!result[0]) return result;
|
|
145
145
|
let [layoutJson] = result;
|
|
146
|
-
layoutJson =
|
|
146
|
+
layoutJson = (0, _objectisomorphic.omitDeep)(layoutJson, [
|
|
147
147
|
"__readonly"
|
|
148
148
|
]);
|
|
149
149
|
return withExtractedFiles ? joinExtractedFiles(layoutDirCtx, layoutJson) : [
|
|
@@ -5,17 +5,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
function _export(target, all) {
|
|
6
6
|
for(var name in all)Object.defineProperty(target, name, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: all
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
pruneLayoutsIndexDir
|
|
12
|
+
get pruneLayoutsIndexDir () {
|
|
13
13
|
return pruneLayoutsIndexDir;
|
|
14
14
|
},
|
|
15
|
-
writeEmailLayoutDirFromData
|
|
15
|
+
get writeEmailLayoutDirFromData () {
|
|
16
16
|
return writeEmailLayoutDirFromData;
|
|
17
17
|
},
|
|
18
|
-
writeEmailLayoutIndexDir
|
|
18
|
+
get writeEmailLayoutIndexDir () {
|
|
19
19
|
return writeEmailLayoutIndexDir;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
@@ -0,0 +1,283 @@
|
|
|
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: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get ensureValidCommandTarget () {
|
|
13
|
+
return ensureValidCommandTarget;
|
|
14
|
+
},
|
|
15
|
+
get formatActivationRules () {
|
|
16
|
+
return formatActivationRules;
|
|
17
|
+
},
|
|
18
|
+
get formatStatusWithSchedule () {
|
|
19
|
+
return formatStatusWithSchedule;
|
|
20
|
+
},
|
|
21
|
+
get formatStep () {
|
|
22
|
+
return formatStep;
|
|
23
|
+
},
|
|
24
|
+
get generateIndexTypeTS () {
|
|
25
|
+
return generateIndexTypeTS;
|
|
26
|
+
},
|
|
27
|
+
get generateTypes () {
|
|
28
|
+
return generateTypes;
|
|
29
|
+
},
|
|
30
|
+
get guideJsonPath () {
|
|
31
|
+
return guideJsonPath;
|
|
32
|
+
},
|
|
33
|
+
get isGuideDir () {
|
|
34
|
+
return isGuideDir;
|
|
35
|
+
},
|
|
36
|
+
get lsGuideJson () {
|
|
37
|
+
return lsGuideJson;
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
41
|
+
const _core = require("@oclif/core");
|
|
42
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
43
|
+
const _lodash = require("lodash");
|
|
44
|
+
const _quicktypecore = require("quicktype-core");
|
|
45
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
46
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
47
|
+
if (typeof WeakMap !== "function") return null;
|
|
48
|
+
var cacheBabelInterop = new WeakMap();
|
|
49
|
+
var cacheNodeInterop = new WeakMap();
|
|
50
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
51
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
52
|
+
})(nodeInterop);
|
|
53
|
+
}
|
|
54
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
55
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
56
|
+
return obj;
|
|
57
|
+
}
|
|
58
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
59
|
+
return {
|
|
60
|
+
default: obj
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
64
|
+
if (cache && cache.has(obj)) {
|
|
65
|
+
return cache.get(obj);
|
|
66
|
+
}
|
|
67
|
+
var newObj = {
|
|
68
|
+
__proto__: null
|
|
69
|
+
};
|
|
70
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
71
|
+
for(var key in obj){
|
|
72
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
73
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
74
|
+
if (desc && (desc.get || desc.set)) {
|
|
75
|
+
Object.defineProperty(newObj, key, desc);
|
|
76
|
+
} else {
|
|
77
|
+
newObj[key] = obj[key];
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
newObj.default = obj;
|
|
82
|
+
if (cache) {
|
|
83
|
+
cache.set(obj, newObj);
|
|
84
|
+
}
|
|
85
|
+
return newObj;
|
|
86
|
+
}
|
|
87
|
+
const formatStatusWithSchedule = (guide)=>{
|
|
88
|
+
const baseStatus = guide.active ? "Active" : "Inactive";
|
|
89
|
+
if (guide.active_from || guide.active_until) {
|
|
90
|
+
const fromText = guide.active_from ? `from ${guide.active_from}` : "immediately";
|
|
91
|
+
const untilText = guide.active_until ? `until ${guide.active_until}` : "with no end time";
|
|
92
|
+
return `${baseStatus} (${fromText} ${untilText})`;
|
|
93
|
+
}
|
|
94
|
+
return baseStatus;
|
|
95
|
+
};
|
|
96
|
+
const formatStep = (step)=>{
|
|
97
|
+
return `${step.schema_key} (${step.schema_variant_key})`;
|
|
98
|
+
};
|
|
99
|
+
const formatActivationRules = (rules)=>{
|
|
100
|
+
if (!rules || !Array.isArray(rules)) return "-";
|
|
101
|
+
return rules.map(({ directive, pathname })=>`${directive} ${pathname}`).join(", ");
|
|
102
|
+
};
|
|
103
|
+
const guideJsonPath = (guideDirCtx)=>_nodepath.resolve(guideDirCtx.abspath, _processorisomorphic.GUIDE_JSON);
|
|
104
|
+
const lsGuideJson = async (dirPath)=>{
|
|
105
|
+
const guideJsonPath = _nodepath.resolve(dirPath, _processorisomorphic.GUIDE_JSON);
|
|
106
|
+
const exists = await _fsextra.pathExists(guideJsonPath);
|
|
107
|
+
return exists ? guideJsonPath : undefined;
|
|
108
|
+
};
|
|
109
|
+
const isGuideDir = async (dirPath)=>Boolean(await lsGuideJson(dirPath));
|
|
110
|
+
const ensureValidCommandTarget = async (props, runContext)=>{
|
|
111
|
+
const { args, flags } = props;
|
|
112
|
+
const { commandId, resourceDir: resourceDirCtx, cwd: runCwd } = runContext;
|
|
113
|
+
// If the target resource is a different type than the current resource dir
|
|
114
|
+
// type, error out.
|
|
115
|
+
if (resourceDirCtx && resourceDirCtx.type !== "guide") {
|
|
116
|
+
return _core.ux.error(`Cannot run ${commandId} inside a ${resourceDirCtx.type} directory`);
|
|
117
|
+
}
|
|
118
|
+
// Cannot accept both guide key arg and --all flag.
|
|
119
|
+
if (flags.all && args.guideKey) {
|
|
120
|
+
return _core.ux.error(`guideKey arg \`${args.guideKey}\` cannot also be provided when using --all`);
|
|
121
|
+
}
|
|
122
|
+
// --all flag is given, which means no guide key arg.
|
|
123
|
+
if (flags.all) {
|
|
124
|
+
// If --all flag used inside a guide directory, then require a guides
|
|
125
|
+
// dir path.
|
|
126
|
+
if (resourceDirCtx && !flags["guides-dir"]) {
|
|
127
|
+
return _core.ux.error("Missing required flag guides-dir");
|
|
128
|
+
}
|
|
129
|
+
// Targeting all guide dirs in the guides index dir.
|
|
130
|
+
// TODO: Default to the knock project config first if present before cwd.
|
|
131
|
+
const defaultToCwd = {
|
|
132
|
+
abspath: runCwd,
|
|
133
|
+
exists: true
|
|
134
|
+
};
|
|
135
|
+
const indexDirCtx = flags["guides-dir"] || defaultToCwd;
|
|
136
|
+
return {
|
|
137
|
+
type: "guidesIndexDir",
|
|
138
|
+
context: indexDirCtx
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Guide key arg is given, which means no --all flag.
|
|
142
|
+
if (args.guideKey) {
|
|
143
|
+
if (resourceDirCtx && resourceDirCtx.key !== args.guideKey) {
|
|
144
|
+
return _core.ux.error(`Cannot run ${commandId} \`${args.guideKey}\` inside another guide directory:\n${resourceDirCtx.key}`);
|
|
145
|
+
}
|
|
146
|
+
const targetDirPath = resourceDirCtx ? resourceDirCtx.abspath : _nodepath.resolve(runCwd, args.guideKey);
|
|
147
|
+
const guideDirCtx = {
|
|
148
|
+
type: "guide",
|
|
149
|
+
key: args.guideKey,
|
|
150
|
+
abspath: targetDirPath,
|
|
151
|
+
exists: await isGuideDir(targetDirPath)
|
|
152
|
+
};
|
|
153
|
+
return {
|
|
154
|
+
type: "guideDir",
|
|
155
|
+
context: guideDirCtx
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
// From this point on, we have neither a guide key arg nor --all flag.
|
|
159
|
+
// If running inside a guide directory, then use that guide directory.
|
|
160
|
+
if (resourceDirCtx) {
|
|
161
|
+
return {
|
|
162
|
+
type: "guideDir",
|
|
163
|
+
context: resourceDirCtx
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
return _core.ux.error("Missing 1 required arg:\nguideKey");
|
|
167
|
+
};
|
|
168
|
+
/*
|
|
169
|
+
* Takes an array of guides and generate types from its content json schemas.
|
|
170
|
+
*/ const SCHEMA_TITLE_PREFIX = "Guide";
|
|
171
|
+
async function generateTypes(guides, targetLanguage) {
|
|
172
|
+
const schemaInput = new _quicktypecore.JSONSchemaInput(new _quicktypecore.FetchingJSONSchemaStore());
|
|
173
|
+
let processedCount = 0;
|
|
174
|
+
const mapping = {
|
|
175
|
+
key: {},
|
|
176
|
+
type: {}
|
|
177
|
+
};
|
|
178
|
+
for (const guide of guides){
|
|
179
|
+
if (!guide.type) {
|
|
180
|
+
continue;
|
|
181
|
+
}
|
|
182
|
+
// We only support single step guides at the moment.
|
|
183
|
+
const step = (guide.steps || []).find((s)=>s.json_schema);
|
|
184
|
+
if (!step) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
// Format the type name that quicktype can output exactly. It's important
|
|
188
|
+
// that the names we format are used/preserved by quicktype as we create the
|
|
189
|
+
// final mapping referencing these type names.
|
|
190
|
+
// Example: `GuideBannerFourStep1Banner001Default`
|
|
191
|
+
const typeName = [
|
|
192
|
+
SCHEMA_TITLE_PREFIX,
|
|
193
|
+
startCaseNoSpace(guide.key),
|
|
194
|
+
startCaseNoSpace(step.ref),
|
|
195
|
+
startCaseNoSpace(step.schema_key),
|
|
196
|
+
startCaseNoSpace(step.schema_semver),
|
|
197
|
+
startCaseNoSpace(step.schema_variant_key)
|
|
198
|
+
].join("");
|
|
199
|
+
schemaInput.addSource({
|
|
200
|
+
name: typeName,
|
|
201
|
+
schema: JSON.stringify({
|
|
202
|
+
...step.json_schema,
|
|
203
|
+
title: typeName
|
|
204
|
+
})
|
|
205
|
+
});
|
|
206
|
+
mapping.key[guide.key] = typeName;
|
|
207
|
+
mapping.type[guide.type] = [
|
|
208
|
+
...mapping.type[guide.type] || [],
|
|
209
|
+
typeName
|
|
210
|
+
];
|
|
211
|
+
processedCount++;
|
|
212
|
+
}
|
|
213
|
+
if (processedCount === 0) {
|
|
214
|
+
return {
|
|
215
|
+
result: undefined,
|
|
216
|
+
count: 0,
|
|
217
|
+
mapping
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
const inputData = new _quicktypecore.InputData();
|
|
221
|
+
inputData.addInput(schemaInput);
|
|
222
|
+
const result = await (0, _quicktypecore.quicktype)({
|
|
223
|
+
inputData,
|
|
224
|
+
lang: targetLanguage,
|
|
225
|
+
allPropertiesOptional: false,
|
|
226
|
+
alphabetizeProperties: true,
|
|
227
|
+
rendererOptions: {
|
|
228
|
+
"just-types": true,
|
|
229
|
+
"no-extra-properties": true,
|
|
230
|
+
"no-optional-null": true
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
return {
|
|
234
|
+
result,
|
|
235
|
+
count: processedCount,
|
|
236
|
+
mapping
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
const startCaseNoSpace = (key)=>(0, _lodash.startCase)(key).replace(/\s/g, "");
|
|
240
|
+
/*
|
|
241
|
+
* For typescript, this writes a root type that maps out all guide types by
|
|
242
|
+
* guide type and key.
|
|
243
|
+
*
|
|
244
|
+
* For example:
|
|
245
|
+
* type GuideContentByType = {
|
|
246
|
+
* "banner-one": GuideBannerOneStep1Banner001Default;
|
|
247
|
+
* "banner-two": GuideBannerTwoStep1Banner001Default;
|
|
248
|
+
* "card-one": GuideCardOneStep1Card001Default;
|
|
249
|
+
* "card-two": GuideCardTwoStep1Card001SingleAction;
|
|
250
|
+
* "changelog-card": GuideChangelogCardStep1ChangelogCard001SingleAction;
|
|
251
|
+
* "modal-one": GuideModalOneStep1Modal001MultiAction;
|
|
252
|
+
* };
|
|
253
|
+
*
|
|
254
|
+
* type GuideContentByKey = {
|
|
255
|
+
* "banner": GuideBannerOneStep1Banner001Default | GuideBannerTwoStep1Banner001Default;
|
|
256
|
+
* "card": GuideCardOneStep1Card001Default | GuideCardTwoStep1Card001SingleAction;
|
|
257
|
+
* "changelog-card": GuideChangelogCardStep1ChangelogCard001SingleAction;
|
|
258
|
+
* "modal": GuideModalOneStep1Modal001MultiAction;
|
|
259
|
+
* };
|
|
260
|
+
*
|
|
261
|
+
* export type GuideContentIndex = {
|
|
262
|
+
* key: GuideContentByType;
|
|
263
|
+
* type: GuideContentByKey;
|
|
264
|
+
* };
|
|
265
|
+
*/ const TS_INDEX_TYPE_PREFIX = "GuideContent";
|
|
266
|
+
const generateIndexTypeTS = (mapping)=>{
|
|
267
|
+
const lines = [];
|
|
268
|
+
// Define the type for sub index by guide key.
|
|
269
|
+
const byKey = `${TS_INDEX_TYPE_PREFIX}ByKey`;
|
|
270
|
+
lines.push(`\ntype ${byKey} = {`);
|
|
271
|
+
for (const [key, val] of Object.entries(mapping.key)){
|
|
272
|
+
lines.push(` "${key}": ${val};`);
|
|
273
|
+
}
|
|
274
|
+
lines.push("};");
|
|
275
|
+
// Define the type for sub index by guide type.
|
|
276
|
+
const byType = `${TS_INDEX_TYPE_PREFIX}ByType`;
|
|
277
|
+
lines.push(`\ntype ${byType} = {`);
|
|
278
|
+
for (const [key, val] of Object.entries(mapping.type)){
|
|
279
|
+
lines.push(` "${key}": ${(val || []).join(" | ")};`);
|
|
280
|
+
}
|
|
281
|
+
lines.push("};", `\nexport type ${TS_INDEX_TYPE_PREFIX}Index = {`, ` key: ${byKey};`, ` type: ${byType};`, "};");
|
|
282
|
+
return lines;
|
|
283
|
+
};
|
|
@@ -2,8 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
_export_star(require("./helpers"), exports);
|
|
5
6
|
_export_star(require("./processor.isomorphic"), exports);
|
|
7
|
+
_export_star(require("./reader"), exports);
|
|
6
8
|
_export_star(require("./types"), exports);
|
|
9
|
+
_export_star(require("./writer"), exports);
|
|
7
10
|
function _export_star(from, to) {
|
|
8
11
|
Object.keys(from).forEach(function(k) {
|
|
9
12
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -12,14 +12,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
12
12
|
function _export(target, all) {
|
|
13
13
|
for(var name in all)Object.defineProperty(target, name, {
|
|
14
14
|
enumerable: true,
|
|
15
|
-
get: all
|
|
15
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
_export(exports, {
|
|
19
|
-
GUIDE_JSON
|
|
19
|
+
get GUIDE_JSON () {
|
|
20
20
|
return GUIDE_JSON;
|
|
21
21
|
},
|
|
22
|
-
buildGuideDirBundle
|
|
22
|
+
get buildGuideDirBundle () {
|
|
23
23
|
return buildGuideDirBundle;
|
|
24
24
|
}
|
|
25
25
|
});
|