@knocklabs/cli 1.0.0 → 1.0.3
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 +283 -76
- package/dist/commands/audience/archive.js +120 -0
- package/dist/commands/audience/get.js +169 -0
- package/dist/commands/audience/list.js +159 -0
- package/dist/commands/audience/new.js +243 -0
- package/dist/commands/audience/open.js +106 -0
- package/dist/commands/audience/pull.js +214 -0
- package/dist/commands/audience/push.js +172 -0
- package/dist/commands/audience/validate.js +147 -0
- package/dist/commands/branch/create.js +40 -3
- package/dist/commands/branch/list.js +14 -9
- package/dist/commands/branch/switch.js +7 -2
- package/dist/commands/guide/push.js +2 -1
- package/dist/commands/layout/push.js +2 -1
- package/dist/commands/message-type/push.js +2 -1
- package/dist/commands/partial/push.js +2 -1
- package/dist/commands/pull.js +19 -12
- package/dist/commands/push.js +24 -13
- package/dist/commands/translation/push.js +2 -1
- package/dist/commands/workflow/push.js +2 -1
- package/dist/lib/api-v1.js +12 -6
- package/dist/lib/helpers/flag.js +6 -0
- package/dist/lib/helpers/git.js +22 -3
- package/dist/lib/helpers/project-config.js +1 -0
- package/dist/lib/marshal/audience/generator.js +38 -0
- package/dist/lib/marshal/audience/helpers.js +142 -0
- package/dist/lib/marshal/audience/index.js +23 -0
- package/dist/lib/marshal/audience/processor.isomorphic.js +25 -0
- package/dist/lib/marshal/audience/reader.js +149 -0
- package/dist/lib/marshal/audience/types.js +15 -0
- package/dist/lib/marshal/audience/writer.js +177 -0
- package/dist/lib/marshal/index.isomorphic.js +18 -14
- package/dist/lib/marshal/translation/helpers.js +2 -1
- package/dist/lib/marshal/translation/reader.js +1 -1
- package/dist/lib/resources.js +3 -0
- package/dist/lib/run-context/loader.js +9 -20
- package/dist/lib/urls.js +4 -0
- package/oclif.manifest.json +879 -188
- package/package.json +10 -10
|
@@ -0,0 +1,142 @@
|
|
|
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 audienceJsonPath () {
|
|
13
|
+
return audienceJsonPath;
|
|
14
|
+
},
|
|
15
|
+
get ensureValidCommandTarget () {
|
|
16
|
+
return ensureValidCommandTarget;
|
|
17
|
+
},
|
|
18
|
+
get isAudienceDir () {
|
|
19
|
+
return isAudienceDir;
|
|
20
|
+
},
|
|
21
|
+
get lsAudienceJson () {
|
|
22
|
+
return lsAudienceJson;
|
|
23
|
+
},
|
|
24
|
+
get validateAudienceKey () {
|
|
25
|
+
return validateAudienceKey;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
29
|
+
const _core = require("@oclif/core");
|
|
30
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
31
|
+
const _projectconfig = require("../../helpers/project-config");
|
|
32
|
+
const _string = require("../../helpers/string");
|
|
33
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
34
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
35
|
+
if (typeof WeakMap !== "function") return null;
|
|
36
|
+
var cacheBabelInterop = new WeakMap();
|
|
37
|
+
var cacheNodeInterop = new WeakMap();
|
|
38
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
39
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
40
|
+
})(nodeInterop);
|
|
41
|
+
}
|
|
42
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
43
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
44
|
+
return obj;
|
|
45
|
+
}
|
|
46
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
47
|
+
return {
|
|
48
|
+
default: obj
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
52
|
+
if (cache && cache.has(obj)) {
|
|
53
|
+
return cache.get(obj);
|
|
54
|
+
}
|
|
55
|
+
var newObj = {
|
|
56
|
+
__proto__: null
|
|
57
|
+
};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) {
|
|
63
|
+
Object.defineProperty(newObj, key, desc);
|
|
64
|
+
} else {
|
|
65
|
+
newObj[key] = obj[key];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
newObj.default = obj;
|
|
70
|
+
if (cache) {
|
|
71
|
+
cache.set(obj, newObj);
|
|
72
|
+
}
|
|
73
|
+
return newObj;
|
|
74
|
+
}
|
|
75
|
+
const audienceJsonPath = (audienceDirCtx)=>_nodepath.resolve(audienceDirCtx.abspath, _processorisomorphic.AUDIENCE_JSON);
|
|
76
|
+
const lsAudienceJson = async (dirPath)=>{
|
|
77
|
+
const audienceJsonPath = _nodepath.resolve(dirPath, _processorisomorphic.AUDIENCE_JSON);
|
|
78
|
+
const exists = await _fsextra.pathExists(audienceJsonPath);
|
|
79
|
+
return exists ? audienceJsonPath : undefined;
|
|
80
|
+
};
|
|
81
|
+
const isAudienceDir = async (dirPath)=>Boolean(await lsAudienceJson(dirPath));
|
|
82
|
+
const validateAudienceKey = (input)=>{
|
|
83
|
+
if (!(0, _string.checkSlugifiedFormat)(input, {
|
|
84
|
+
onlyLowerCase: true
|
|
85
|
+
})) {
|
|
86
|
+
return "must include only lowercase alphanumeric, dash, or underscore characters";
|
|
87
|
+
}
|
|
88
|
+
return undefined;
|
|
89
|
+
};
|
|
90
|
+
const ensureValidCommandTarget = async (props, runContext, projectConfig)=>{
|
|
91
|
+
const { args, flags } = props;
|
|
92
|
+
const { commandId, resourceDir: resourceDirCtx, cwd: runCwd } = runContext;
|
|
93
|
+
// If the target resource is a different type than the current resource dir
|
|
94
|
+
// type, error out.
|
|
95
|
+
if (resourceDirCtx && resourceDirCtx.type !== "audience") {
|
|
96
|
+
return _core.ux.error(`Cannot run ${commandId} inside a ${resourceDirCtx.type} directory`);
|
|
97
|
+
}
|
|
98
|
+
// Cannot accept both audience key arg and --all flag.
|
|
99
|
+
if (flags.all && args.audienceKey) {
|
|
100
|
+
return _core.ux.error(`audienceKey arg \`${args.audienceKey}\` cannot also be provided when using --all`);
|
|
101
|
+
}
|
|
102
|
+
// Default to knock project config first if present, otherwise cwd.
|
|
103
|
+
const audiencesIndexDirCtx = await (0, _projectconfig.resolveResourceDir)(projectConfig, "audience", runCwd);
|
|
104
|
+
// --all flag is given, which means no audience key arg.
|
|
105
|
+
if (flags.all) {
|
|
106
|
+
// If --all flag used inside an audience directory, then require an audiences
|
|
107
|
+
// dir path.
|
|
108
|
+
if (resourceDirCtx && !flags["audiences-dir"]) {
|
|
109
|
+
return _core.ux.error("Missing required flag audiences-dir");
|
|
110
|
+
}
|
|
111
|
+
return {
|
|
112
|
+
type: "audiencesIndexDir",
|
|
113
|
+
context: flags["audiences-dir"] || audiencesIndexDirCtx
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
// Audience key arg is given, which means no --all flag.
|
|
117
|
+
if (args.audienceKey) {
|
|
118
|
+
if (resourceDirCtx && resourceDirCtx.key !== args.audienceKey) {
|
|
119
|
+
return _core.ux.error(`Cannot run ${commandId} \`${args.audienceKey}\` inside another audience directory:\n${resourceDirCtx.key}`);
|
|
120
|
+
}
|
|
121
|
+
const targetDirPath = resourceDirCtx ? resourceDirCtx.abspath : _nodepath.resolve(audiencesIndexDirCtx.abspath, args.audienceKey);
|
|
122
|
+
const audienceDirCtx = {
|
|
123
|
+
type: "audience",
|
|
124
|
+
key: args.audienceKey,
|
|
125
|
+
abspath: targetDirPath,
|
|
126
|
+
exists: await isAudienceDir(targetDirPath)
|
|
127
|
+
};
|
|
128
|
+
return {
|
|
129
|
+
type: "audienceDir",
|
|
130
|
+
context: audienceDirCtx
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
// From this point on, we have neither an audience key arg nor --all flag.
|
|
134
|
+
// If running inside an audience directory, then use that audience directory.
|
|
135
|
+
if (resourceDirCtx) {
|
|
136
|
+
return {
|
|
137
|
+
type: "audienceDir",
|
|
138
|
+
context: resourceDirCtx
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
return _core.ux.error("Missing 1 required arg:\naudienceKey");
|
|
142
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
_export_star(require("./generator"), exports);
|
|
6
|
+
_export_star(require("./helpers"), exports);
|
|
7
|
+
_export_star(require("./processor.isomorphic"), exports);
|
|
8
|
+
_export_star(require("./reader"), exports);
|
|
9
|
+
_export_star(require("./types"), exports);
|
|
10
|
+
_export_star(require("./writer"), exports);
|
|
11
|
+
function _export_star(from, to) {
|
|
12
|
+
Object.keys(from).forEach(function(k) {
|
|
13
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
14
|
+
Object.defineProperty(to, k, {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
get: function() {
|
|
17
|
+
return from[k];
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
return from;
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 AUDIENCE_JSON () {
|
|
13
|
+
return AUDIENCE_JSON;
|
|
14
|
+
},
|
|
15
|
+
get buildAudienceDirBundle () {
|
|
16
|
+
return buildAudienceDirBundle;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _helpersisomorphic = require("../shared/helpers.isomorphic");
|
|
20
|
+
const AUDIENCE_JSON = "audience.json";
|
|
21
|
+
const buildAudienceDirBundle = (remoteAudience, _localAudience, $schema)=>{
|
|
22
|
+
return {
|
|
23
|
+
[AUDIENCE_JSON]: (0, _helpersisomorphic.prepareResourceJson)(remoteAudience, $schema)
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
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 readAllForCommandTarget () {
|
|
13
|
+
return readAllForCommandTarget;
|
|
14
|
+
},
|
|
15
|
+
get readAudienceDir () {
|
|
16
|
+
return readAudienceDir;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _nodepath = /*#__PURE__*/ _interop_require_default(require("node:path"));
|
|
20
|
+
const _core = require("@oclif/core");
|
|
21
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
22
|
+
const _error = require("../../helpers/error");
|
|
23
|
+
const _json = require("../../helpers/json");
|
|
24
|
+
const _objectisomorphic = require("../../helpers/object.isomorphic");
|
|
25
|
+
const _helpers = require("./helpers");
|
|
26
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
27
|
+
function _interop_require_default(obj) {
|
|
28
|
+
return obj && obj.__esModule ? obj : {
|
|
29
|
+
default: obj
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
33
|
+
if (typeof WeakMap !== "function") return null;
|
|
34
|
+
var cacheBabelInterop = new WeakMap();
|
|
35
|
+
var cacheNodeInterop = new WeakMap();
|
|
36
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
37
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
38
|
+
})(nodeInterop);
|
|
39
|
+
}
|
|
40
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
41
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
45
|
+
return {
|
|
46
|
+
default: obj
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
50
|
+
if (cache && cache.has(obj)) {
|
|
51
|
+
return cache.get(obj);
|
|
52
|
+
}
|
|
53
|
+
var newObj = {
|
|
54
|
+
__proto__: null
|
|
55
|
+
};
|
|
56
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
57
|
+
for(var key in obj){
|
|
58
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
59
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
60
|
+
if (desc && (desc.get || desc.set)) {
|
|
61
|
+
Object.defineProperty(newObj, key, desc);
|
|
62
|
+
} else {
|
|
63
|
+
newObj[key] = obj[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
newObj.default = obj;
|
|
68
|
+
if (cache) {
|
|
69
|
+
cache.set(obj, newObj);
|
|
70
|
+
}
|
|
71
|
+
return newObj;
|
|
72
|
+
}
|
|
73
|
+
/*
|
|
74
|
+
* For the given list of audience directory contexts, read each audience dir and
|
|
75
|
+
* return audience directory data.
|
|
76
|
+
*/ const readAudienceDirs = async (audienceDirCtxs)=>{
|
|
77
|
+
const audiences = [];
|
|
78
|
+
const errors = [];
|
|
79
|
+
for (const audienceDirCtx of audienceDirCtxs){
|
|
80
|
+
// eslint-disable-next-line no-await-in-loop
|
|
81
|
+
const [audience, readErrors] = await readAudienceDir(audienceDirCtx);
|
|
82
|
+
if (readErrors.length > 0) {
|
|
83
|
+
const audienceJsonPath = _nodepath.default.resolve(audienceDirCtx.abspath, _processorisomorphic.AUDIENCE_JSON);
|
|
84
|
+
const e = new _error.SourceError((0, _error.formatErrors)(readErrors), audienceJsonPath);
|
|
85
|
+
errors.push(e);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
audiences.push({
|
|
89
|
+
...audienceDirCtx,
|
|
90
|
+
content: audience
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
return [
|
|
94
|
+
audiences,
|
|
95
|
+
errors
|
|
96
|
+
];
|
|
97
|
+
};
|
|
98
|
+
const readAudienceDir = async (audienceDirCtx)=>{
|
|
99
|
+
const { abspath } = audienceDirCtx;
|
|
100
|
+
const dirExists = await _fsextra.pathExists(abspath);
|
|
101
|
+
if (!dirExists) throw new Error(`${abspath} does not exist`);
|
|
102
|
+
const audienceJsonPath = await (0, _helpers.lsAudienceJson)(abspath);
|
|
103
|
+
if (!audienceJsonPath) throw new Error(`${abspath} is not an audience directory`);
|
|
104
|
+
const result = await (0, _json.readJson)(audienceJsonPath);
|
|
105
|
+
if (!result[0]) return result;
|
|
106
|
+
let [audienceJson] = result;
|
|
107
|
+
audienceJson = (0, _objectisomorphic.omitDeep)(audienceJson, [
|
|
108
|
+
"__readonly"
|
|
109
|
+
]);
|
|
110
|
+
return [
|
|
111
|
+
audienceJson,
|
|
112
|
+
[]
|
|
113
|
+
];
|
|
114
|
+
};
|
|
115
|
+
const readAllForCommandTarget = async (target)=>{
|
|
116
|
+
const { type: targetType, context: targetCtx } = target;
|
|
117
|
+
if (!targetCtx.exists) {
|
|
118
|
+
const subject = targetType === "audienceDir" ? "an audience directory at" : "audience directories in";
|
|
119
|
+
return _core.ux.error(`Cannot locate ${subject} \`${targetCtx.abspath}\``);
|
|
120
|
+
}
|
|
121
|
+
switch(targetType){
|
|
122
|
+
case "audienceDir":
|
|
123
|
+
{
|
|
124
|
+
return readAudienceDirs([
|
|
125
|
+
targetCtx
|
|
126
|
+
]);
|
|
127
|
+
}
|
|
128
|
+
case "audiencesIndexDir":
|
|
129
|
+
{
|
|
130
|
+
const dirents = await _fsextra.readdir(targetCtx.abspath, {
|
|
131
|
+
withFileTypes: true
|
|
132
|
+
});
|
|
133
|
+
const promises = dirents.map(async (dirent)=>{
|
|
134
|
+
const abspath = _nodepath.default.resolve(targetCtx.abspath, dirent.name);
|
|
135
|
+
const audienceDirCtx = {
|
|
136
|
+
type: "audience",
|
|
137
|
+
key: dirent.name,
|
|
138
|
+
abspath,
|
|
139
|
+
exists: await (0, _helpers.isAudienceDir)(abspath)
|
|
140
|
+
};
|
|
141
|
+
return audienceDirCtx;
|
|
142
|
+
});
|
|
143
|
+
const audienceDirCtxs = (await Promise.all(promises)).filter((audienceDirCtx)=>audienceDirCtx.exists);
|
|
144
|
+
return readAudienceDirs(audienceDirCtxs);
|
|
145
|
+
}
|
|
146
|
+
default:
|
|
147
|
+
throw new Error(`Invalid audience command target: ${target}`);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "AudienceType", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return AudienceType;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var AudienceType = /*#__PURE__*/ function(AudienceType) {
|
|
12
|
+
AudienceType["Static"] = "static";
|
|
13
|
+
AudienceType["Dynamic"] = "dynamic";
|
|
14
|
+
return AudienceType;
|
|
15
|
+
}({});
|
|
@@ -0,0 +1,177 @@
|
|
|
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 pruneAudiencesIndexDir () {
|
|
13
|
+
return pruneAudiencesIndexDir;
|
|
14
|
+
},
|
|
15
|
+
get writeAudienceDirFromBundle () {
|
|
16
|
+
return writeAudienceDirFromBundle;
|
|
17
|
+
},
|
|
18
|
+
get writeAudienceDirFromData () {
|
|
19
|
+
return writeAudienceDirFromData;
|
|
20
|
+
},
|
|
21
|
+
get writeAudiencesIndexDir () {
|
|
22
|
+
return writeAudiencesIndexDir;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
26
|
+
const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
27
|
+
const _lodash = require("lodash");
|
|
28
|
+
const _const = require("../../helpers/const");
|
|
29
|
+
const _json = require("../../helpers/json");
|
|
30
|
+
const _helpers = require("./helpers");
|
|
31
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
32
|
+
const _reader = require("./reader");
|
|
33
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
34
|
+
if (typeof WeakMap !== "function") return null;
|
|
35
|
+
var cacheBabelInterop = new WeakMap();
|
|
36
|
+
var cacheNodeInterop = new WeakMap();
|
|
37
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
38
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
39
|
+
})(nodeInterop);
|
|
40
|
+
}
|
|
41
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
42
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
43
|
+
return obj;
|
|
44
|
+
}
|
|
45
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
46
|
+
return {
|
|
47
|
+
default: obj
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
51
|
+
if (cache && cache.has(obj)) {
|
|
52
|
+
return cache.get(obj);
|
|
53
|
+
}
|
|
54
|
+
var newObj = {
|
|
55
|
+
__proto__: null
|
|
56
|
+
};
|
|
57
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
58
|
+
for(var key in obj){
|
|
59
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
60
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
61
|
+
if (desc && (desc.get || desc.set)) {
|
|
62
|
+
Object.defineProperty(newObj, key, desc);
|
|
63
|
+
} else {
|
|
64
|
+
newObj[key] = obj[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
newObj.default = obj;
|
|
69
|
+
if (cache) {
|
|
70
|
+
cache.set(obj, newObj);
|
|
71
|
+
}
|
|
72
|
+
return newObj;
|
|
73
|
+
}
|
|
74
|
+
const AUDIENCE_SCHEMA = "https://schemas.knock.app/cli/audience.json";
|
|
75
|
+
const writeAudienceDirFromData = async (audienceDirCtx, remoteAudience, options)=>{
|
|
76
|
+
const { withSchema = false } = options || {};
|
|
77
|
+
// If the audience directory exists on the file system (i.e. previously
|
|
78
|
+
// pulled before), then read the audience file to use as a reference.
|
|
79
|
+
const [localAudience] = audienceDirCtx.exists ? await (0, _reader.readAudienceDir)(audienceDirCtx) : [];
|
|
80
|
+
const bundle = (0, _processorisomorphic.buildAudienceDirBundle)(remoteAudience, localAudience, withSchema ? AUDIENCE_SCHEMA : undefined);
|
|
81
|
+
return writeAudienceDirFromBundle(audienceDirCtx, bundle);
|
|
82
|
+
};
|
|
83
|
+
/*
|
|
84
|
+
* A lower level write function that takes a constructed audience dir bundle
|
|
85
|
+
* and writes it into an audience directory on a local file system.
|
|
86
|
+
*
|
|
87
|
+
* It does not make any assumptions about how the audience directory bundle was
|
|
88
|
+
* built; for example, it can be from parsing the audience data fetched from
|
|
89
|
+
* the Knock API, or built manually for scaffolding purposes.
|
|
90
|
+
*/ const writeAudienceDirFromBundle = async (audienceDirCtx, audienceDirBundle)=>{
|
|
91
|
+
const backupDirPath = _nodepath.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
92
|
+
try {
|
|
93
|
+
if (audienceDirCtx.exists) {
|
|
94
|
+
await _fsextra.copy(audienceDirCtx.abspath, backupDirPath);
|
|
95
|
+
await _fsextra.emptyDir(audienceDirCtx.abspath);
|
|
96
|
+
}
|
|
97
|
+
const promises = Object.entries(audienceDirBundle).map(([relpath, fileContent])=>{
|
|
98
|
+
const filePath = _nodepath.resolve(audienceDirCtx.abspath, relpath);
|
|
99
|
+
return relpath === _processorisomorphic.AUDIENCE_JSON ? _fsextra.outputJson(filePath, fileContent, {
|
|
100
|
+
spaces: _json.DOUBLE_SPACES
|
|
101
|
+
}) : _fsextra.outputFile(filePath, fileContent !== null && fileContent !== void 0 ? fileContent : "");
|
|
102
|
+
});
|
|
103
|
+
await Promise.all(promises);
|
|
104
|
+
} catch (error) {
|
|
105
|
+
// In case of any error, wipe the target directory that is likely in a bad
|
|
106
|
+
// state then restore the backup if one existed before.
|
|
107
|
+
if (audienceDirCtx.exists) {
|
|
108
|
+
await _fsextra.emptyDir(audienceDirCtx.abspath);
|
|
109
|
+
await _fsextra.copy(backupDirPath, audienceDirCtx.abspath);
|
|
110
|
+
} else {
|
|
111
|
+
await _fsextra.remove(audienceDirCtx.abspath);
|
|
112
|
+
}
|
|
113
|
+
throw error;
|
|
114
|
+
} finally{
|
|
115
|
+
// Always clean up the backup directory in the temp sandbox.
|
|
116
|
+
await _fsextra.remove(backupDirPath);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
/*
|
|
120
|
+
* Prunes the index directory by removing any files, or directories that aren't
|
|
121
|
+
* audience dirs found in fetched audiences. We want to preserve any audience
|
|
122
|
+
* dirs that are going to be updated with remote audiences, so extracted links
|
|
123
|
+
* can be respected.
|
|
124
|
+
*/ const pruneAudiencesIndexDir = async (indexDirCtx, remoteAudiences)=>{
|
|
125
|
+
const audiencesByKey = Object.fromEntries(remoteAudiences.map((a)=>[
|
|
126
|
+
a.key.toLowerCase(),
|
|
127
|
+
a
|
|
128
|
+
]));
|
|
129
|
+
const dirents = await _fsextra.readdir(indexDirCtx.abspath, {
|
|
130
|
+
withFileTypes: true
|
|
131
|
+
});
|
|
132
|
+
const promises = dirents.map(async (dirent)=>{
|
|
133
|
+
const direntPath = _nodepath.resolve(indexDirCtx.abspath, dirent.name);
|
|
134
|
+
const direntKey = dirent.name.toLowerCase();
|
|
135
|
+
if (await (0, _helpers.isAudienceDir)(direntPath) && audiencesByKey[direntKey]) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
await _fsextra.remove(direntPath);
|
|
139
|
+
});
|
|
140
|
+
await Promise.all(promises);
|
|
141
|
+
};
|
|
142
|
+
const writeAudiencesIndexDir = async (indexDirCtx, remoteAudiences, options)=>{
|
|
143
|
+
const backupDirPath = _nodepath.resolve(_const.sandboxDir, (0, _lodash.uniqueId)("backup"));
|
|
144
|
+
try {
|
|
145
|
+
// If the index directory already exists, back it up in the temp sandbox
|
|
146
|
+
// before wiping it clean.
|
|
147
|
+
if (indexDirCtx.exists) {
|
|
148
|
+
await _fsextra.copy(indexDirCtx.abspath, backupDirPath);
|
|
149
|
+
await pruneAudiencesIndexDir(indexDirCtx, remoteAudiences);
|
|
150
|
+
}
|
|
151
|
+
// Write given remote audiences into the given audiences directory path.
|
|
152
|
+
const writeAudienceDirPromises = remoteAudiences.map(async (audience)=>{
|
|
153
|
+
const audienceDirPath = _nodepath.resolve(indexDirCtx.abspath, audience.key);
|
|
154
|
+
const audienceDirCtx = {
|
|
155
|
+
type: "audience",
|
|
156
|
+
key: audience.key,
|
|
157
|
+
abspath: audienceDirPath,
|
|
158
|
+
exists: indexDirCtx.exists ? await (0, _helpers.isAudienceDir)(audienceDirPath) : false
|
|
159
|
+
};
|
|
160
|
+
return writeAudienceDirFromData(audienceDirCtx, audience, options);
|
|
161
|
+
});
|
|
162
|
+
await Promise.all(writeAudienceDirPromises);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
// In case of any error, wipe the index directory that is likely in a bad
|
|
165
|
+
// state then restore the backup if one existed before.
|
|
166
|
+
if (indexDirCtx.exists) {
|
|
167
|
+
await _fsextra.emptyDir(indexDirCtx.abspath);
|
|
168
|
+
await _fsextra.copy(backupDirPath, indexDirCtx.abspath);
|
|
169
|
+
} else {
|
|
170
|
+
await _fsextra.remove(indexDirCtx.abspath);
|
|
171
|
+
}
|
|
172
|
+
throw error;
|
|
173
|
+
} finally{
|
|
174
|
+
// Always clean up the backup directory in the temp sandbox.
|
|
175
|
+
await _fsextra.remove(backupDirPath);
|
|
176
|
+
}
|
|
177
|
+
};
|
|
@@ -11,32 +11,36 @@ function _export(target, all) {
|
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
13
|
_export(exports, {
|
|
14
|
+
get buildAudienceDirBundle () {
|
|
15
|
+
return _processorisomorphic.buildAudienceDirBundle;
|
|
16
|
+
},
|
|
14
17
|
get buildEmailLayoutDirBundle () {
|
|
15
|
-
return
|
|
18
|
+
return _processorisomorphic1.buildEmailLayoutDirBundle;
|
|
16
19
|
},
|
|
17
20
|
get buildGuideDirBundle () {
|
|
18
|
-
return
|
|
21
|
+
return _processorisomorphic2.buildGuideDirBundle;
|
|
19
22
|
},
|
|
20
23
|
get buildMessageTypeDirBundle () {
|
|
21
|
-
return
|
|
24
|
+
return _processorisomorphic3.buildMessageTypeDirBundle;
|
|
22
25
|
},
|
|
23
26
|
get buildPartialDirBundle () {
|
|
24
|
-
return
|
|
27
|
+
return _processorisomorphic4.buildPartialDirBundle;
|
|
25
28
|
},
|
|
26
29
|
get buildReusableStepDirBundle () {
|
|
27
|
-
return
|
|
30
|
+
return _processorisomorphic5.buildReusableStepDirBundle;
|
|
28
31
|
},
|
|
29
32
|
get buildTranslationDirBundle () {
|
|
30
|
-
return
|
|
33
|
+
return _processorisomorphic6.buildTranslationDirBundle;
|
|
31
34
|
},
|
|
32
35
|
get buildWorkflowDirBundle () {
|
|
33
|
-
return
|
|
36
|
+
return _processorisomorphic7.buildWorkflowDirBundle;
|
|
34
37
|
}
|
|
35
38
|
});
|
|
36
|
-
const _processorisomorphic = require("./
|
|
37
|
-
const _processorisomorphic1 = require("./
|
|
38
|
-
const _processorisomorphic2 = require("./
|
|
39
|
-
const _processorisomorphic3 = require("./
|
|
40
|
-
const _processorisomorphic4 = require("./
|
|
41
|
-
const _processorisomorphic5 = require("./
|
|
42
|
-
const _processorisomorphic6 = require("./
|
|
39
|
+
const _processorisomorphic = require("./audience/processor.isomorphic");
|
|
40
|
+
const _processorisomorphic1 = require("./email-layout/processor.isomorphic");
|
|
41
|
+
const _processorisomorphic2 = require("./guide/processor.isomorphic");
|
|
42
|
+
const _processorisomorphic3 = require("./message-type/processor.isomorphic");
|
|
43
|
+
const _processorisomorphic4 = require("./partial/processor.isomorphic");
|
|
44
|
+
const _processorisomorphic5 = require("./reusable-step/processor.isomorphic");
|
|
45
|
+
const _processorisomorphic6 = require("./translation/processor.isomorphic");
|
|
46
|
+
const _processorisomorphic7 = require("./workflow/processor.isomorphic");
|
|
@@ -103,7 +103,8 @@ const formatLanguage = (translation)=>{
|
|
|
103
103
|
const isValidLocale = (localeCode)=>Boolean(_localecodes.default.getByTag(localeCode));
|
|
104
104
|
const isTranslationDir = (dirPath)=>{
|
|
105
105
|
const locale = _nodepath.basename(dirPath);
|
|
106
|
-
|
|
106
|
+
const parentDirName = _nodepath.basename(_nodepath.dirname(dirPath));
|
|
107
|
+
return parentDirName === "translations" && isValidLocale(locale);
|
|
107
108
|
};
|
|
108
109
|
const buildTranslationFileCtx = async (dirPath, translationIdentifier, options)=>{
|
|
109
110
|
const ref = (0, _processorisomorphic.formatRef)(translationIdentifier.localeCode, translationIdentifier.namespace);
|
|
@@ -170,7 +170,7 @@ const readAllForCommandTarget = async (target)=>{
|
|
|
170
170
|
const dirents = await _fsextra.readdir(targetCtx.abspath, {
|
|
171
171
|
withFileTypes: true
|
|
172
172
|
});
|
|
173
|
-
const translationDirPaths = dirents.filter((dirent)=>dirent.isDirectory() && (0, _helpers.
|
|
173
|
+
const translationDirPaths = dirents.filter((dirent)=>dirent.isDirectory() && (0, _helpers.isValidLocale)(dirent.name)).map((dirent)=>_nodepath.resolve(targetCtx.abspath, dirent.name));
|
|
174
174
|
const translationFilePaths = (await Promise.all(translationDirPaths.map(async (abspath)=>(0, _helpers.lsTranslationDir)(abspath)))).flat();
|
|
175
175
|
return readTranslationFiles(translationFilePaths);
|
|
176
176
|
}
|
package/dist/lib/resources.js
CHANGED
|
@@ -17,6 +17,8 @@ _export(exports, {
|
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
19
|
const ALL_RESOURCE_TYPES = [
|
|
20
|
+
// Audiences can be referenced by workflows, so push them early
|
|
21
|
+
"audience",
|
|
20
22
|
// Partials first, as email layouts and workflows may reference them
|
|
21
23
|
"partial",
|
|
22
24
|
// Email layouts next, as workflows with email channel steps may reference them
|
|
@@ -28,6 +30,7 @@ const ALL_RESOURCE_TYPES = [
|
|
|
28
30
|
"translation"
|
|
29
31
|
];
|
|
30
32
|
const RESOURCE_SUBDIRS = {
|
|
33
|
+
audience: "audiences",
|
|
31
34
|
email_layout: "layouts",
|
|
32
35
|
partial: "partials",
|
|
33
36
|
translation: "translations",
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "load", {
|
|
|
13
13
|
}
|
|
14
14
|
});
|
|
15
15
|
const _nodepath = /*#__PURE__*/ _interop_require_wildcard(require("node:path"));
|
|
16
|
+
const _audience = /*#__PURE__*/ _interop_require_wildcard(require("../marshal/audience"));
|
|
16
17
|
const _emaillayout = /*#__PURE__*/ _interop_require_wildcard(require("../marshal/email-layout"));
|
|
17
18
|
const _guide = /*#__PURE__*/ _interop_require_wildcard(require("../marshal/guide"));
|
|
18
19
|
const _messagetype = /*#__PURE__*/ _interop_require_wildcard(require("../marshal/message-type"));
|
|
@@ -71,31 +72,19 @@ const buildResourceDirContext = (type, currDir)=>{
|
|
|
71
72
|
const evaluateRecursively = async (ctx, currDir)=>{
|
|
72
73
|
// Check if we are inside a resource directory and if so update the context.
|
|
73
74
|
if (!ctx.resourceDir) {
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
if (await _audience.isAudienceDir(currDir)) {
|
|
76
|
+
ctx.resourceDir = buildResourceDirContext("audience", currDir);
|
|
77
|
+
} else if (await _workflow.isWorkflowDir(currDir)) {
|
|
76
78
|
ctx.resourceDir = buildResourceDirContext("workflow", currDir);
|
|
77
|
-
}
|
|
78
|
-
const isGuideDir = await _guide.isGuideDir(currDir);
|
|
79
|
-
if (isGuideDir) {
|
|
79
|
+
} else if (await _guide.isGuideDir(currDir)) {
|
|
80
80
|
ctx.resourceDir = buildResourceDirContext("guide", currDir);
|
|
81
|
-
}
|
|
82
|
-
const isEmailLayoutDir = await _emaillayout.isEmailLayoutDir(currDir);
|
|
83
|
-
if (isEmailLayoutDir) {
|
|
81
|
+
} else if (await _emaillayout.isEmailLayoutDir(currDir)) {
|
|
84
82
|
ctx.resourceDir = buildResourceDirContext("email_layout", currDir);
|
|
85
|
-
}
|
|
86
|
-
const isPartialDir = await _partial.isPartialDir(currDir);
|
|
87
|
-
if (isPartialDir) {
|
|
83
|
+
} else if (await _partial.isPartialDir(currDir)) {
|
|
88
84
|
ctx.resourceDir = buildResourceDirContext("partial", currDir);
|
|
89
|
-
}
|
|
90
|
-
const isMessageTypeDir = await _messagetype.isMessageTypeDir(currDir);
|
|
91
|
-
if (isMessageTypeDir) {
|
|
85
|
+
} else if (await _messagetype.isMessageTypeDir(currDir)) {
|
|
92
86
|
ctx.resourceDir = buildResourceDirContext("message_type", currDir);
|
|
93
|
-
}
|
|
94
|
-
// NOTE: Must keep this check as last in the order of directory-type checks
|
|
95
|
-
// since the `isTranslationDir` only checks that the directory name is a
|
|
96
|
-
// valid locale name.
|
|
97
|
-
const isTranslationDir = _translation.isTranslationDir(currDir);
|
|
98
|
-
if (isTranslationDir) {
|
|
87
|
+
} else if (_translation.isTranslationDir(currDir)) {
|
|
99
88
|
ctx.resourceDir = buildResourceDirContext("translation", currDir);
|
|
100
89
|
}
|
|
101
90
|
}
|