@knocklabs/cli 1.0.0-rc.1 → 1.0.2
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 +332 -64
- 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 +167 -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/open.js +106 -0
- package/dist/commands/layout/open.js +106 -0
- package/dist/commands/message-type/open.js +106 -0
- package/dist/commands/partial/open.js +106 -0
- package/dist/commands/pull.js +19 -12
- package/dist/commands/push.js +19 -12
- package/dist/commands/workflow/open.js +106 -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/resources.js +3 -0
- package/dist/lib/run-context/loader.js +12 -20
- package/dist/lib/urls.js +20 -0
- package/oclif.manifest.json +1368 -430
- package/package.json +11 -11
package/dist/commands/push.js
CHANGED
|
@@ -16,12 +16,13 @@ const _const = require("../lib/helpers/const");
|
|
|
16
16
|
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../lib/helpers/flag"));
|
|
17
17
|
const _projectconfig = require("../lib/helpers/project-config");
|
|
18
18
|
const _resources = require("../lib/resources");
|
|
19
|
-
const _push = /*#__PURE__*/ _interop_require_default(require("./
|
|
20
|
-
const _push1 = /*#__PURE__*/ _interop_require_default(require("./
|
|
21
|
-
const _push2 = /*#__PURE__*/ _interop_require_default(require("./
|
|
22
|
-
const _push3 = /*#__PURE__*/ _interop_require_default(require("./
|
|
23
|
-
const _push4 = /*#__PURE__*/ _interop_require_default(require("./
|
|
24
|
-
const _push5 = /*#__PURE__*/ _interop_require_default(require("./
|
|
19
|
+
const _push = /*#__PURE__*/ _interop_require_default(require("./audience/push"));
|
|
20
|
+
const _push1 = /*#__PURE__*/ _interop_require_default(require("./guide/push"));
|
|
21
|
+
const _push2 = /*#__PURE__*/ _interop_require_default(require("./layout/push"));
|
|
22
|
+
const _push3 = /*#__PURE__*/ _interop_require_default(require("./message-type/push"));
|
|
23
|
+
const _push4 = /*#__PURE__*/ _interop_require_default(require("./partial/push"));
|
|
24
|
+
const _push5 = /*#__PURE__*/ _interop_require_default(require("./translation/push"));
|
|
25
|
+
const _push6 = /*#__PURE__*/ _interop_require_default(require("./workflow/push"));
|
|
25
26
|
function _define_property(obj, key, value) {
|
|
26
27
|
if (key in obj) {
|
|
27
28
|
Object.defineProperty(obj, key, {
|
|
@@ -155,38 +156,44 @@ const runResourcePushCommand = async (resourceType, targetDirCtx, args)=>{
|
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
158
|
switch(resourceType){
|
|
159
|
+
case "audience":
|
|
160
|
+
return _push.default.run([
|
|
161
|
+
...args,
|
|
162
|
+
"--audiences-dir",
|
|
163
|
+
subdirPath
|
|
164
|
+
]);
|
|
158
165
|
case "email_layout":
|
|
159
|
-
return
|
|
166
|
+
return _push2.default.run([
|
|
160
167
|
...args,
|
|
161
168
|
"--layouts-dir",
|
|
162
169
|
subdirPath
|
|
163
170
|
]);
|
|
164
171
|
case "partial":
|
|
165
|
-
return
|
|
172
|
+
return _push4.default.run([
|
|
166
173
|
...args,
|
|
167
174
|
"--partials-dir",
|
|
168
175
|
subdirPath
|
|
169
176
|
]);
|
|
170
177
|
case "translation":
|
|
171
|
-
return
|
|
178
|
+
return _push5.default.run([
|
|
172
179
|
...args,
|
|
173
180
|
"--translations-dir",
|
|
174
181
|
subdirPath
|
|
175
182
|
]);
|
|
176
183
|
case "workflow":
|
|
177
|
-
return
|
|
184
|
+
return _push6.default.run([
|
|
178
185
|
...args,
|
|
179
186
|
"--workflows-dir",
|
|
180
187
|
subdirPath
|
|
181
188
|
]);
|
|
182
189
|
case "message_type":
|
|
183
|
-
return
|
|
190
|
+
return _push3.default.run([
|
|
184
191
|
...args,
|
|
185
192
|
"--message-types-dir",
|
|
186
193
|
subdirPath
|
|
187
194
|
]);
|
|
188
195
|
case "guide":
|
|
189
|
-
return
|
|
196
|
+
return _push1.default.run([
|
|
190
197
|
...args,
|
|
191
198
|
"--guides-dir",
|
|
192
199
|
subdirPath
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return WorkflowOpen;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _core = require("@oclif/core");
|
|
12
|
+
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _browser = require("../../lib/helpers/browser");
|
|
14
|
+
const _error = require("../../lib/helpers/error");
|
|
15
|
+
const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../../lib/helpers/flag"));
|
|
16
|
+
const _request = require("../../lib/helpers/request");
|
|
17
|
+
const _urls = require("../../lib/urls");
|
|
18
|
+
function _define_property(obj, key, value) {
|
|
19
|
+
if (key in obj) {
|
|
20
|
+
Object.defineProperty(obj, key, {
|
|
21
|
+
value: value,
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true
|
|
25
|
+
});
|
|
26
|
+
} else {
|
|
27
|
+
obj[key] = value;
|
|
28
|
+
}
|
|
29
|
+
return obj;
|
|
30
|
+
}
|
|
31
|
+
function _interop_require_default(obj) {
|
|
32
|
+
return obj && obj.__esModule ? obj : {
|
|
33
|
+
default: obj
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
37
|
+
if (typeof WeakMap !== "function") return null;
|
|
38
|
+
var cacheBabelInterop = new WeakMap();
|
|
39
|
+
var cacheNodeInterop = new WeakMap();
|
|
40
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
41
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
42
|
+
})(nodeInterop);
|
|
43
|
+
}
|
|
44
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
45
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
46
|
+
return obj;
|
|
47
|
+
}
|
|
48
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
49
|
+
return {
|
|
50
|
+
default: obj
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) {
|
|
55
|
+
return cache.get(obj);
|
|
56
|
+
}
|
|
57
|
+
var newObj = {
|
|
58
|
+
__proto__: null
|
|
59
|
+
};
|
|
60
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
61
|
+
for(var key in obj){
|
|
62
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
63
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
64
|
+
if (desc && (desc.get || desc.set)) {
|
|
65
|
+
Object.defineProperty(newObj, key, desc);
|
|
66
|
+
} else {
|
|
67
|
+
newObj[key] = obj[key];
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
newObj.default = obj;
|
|
72
|
+
if (cache) {
|
|
73
|
+
cache.set(obj, newObj);
|
|
74
|
+
}
|
|
75
|
+
return newObj;
|
|
76
|
+
}
|
|
77
|
+
class WorkflowOpen extends _basecommand.default {
|
|
78
|
+
async run() {
|
|
79
|
+
const whoamiResp = await this.apiV1.whoami();
|
|
80
|
+
if (!(0, _request.isSuccessResp)(whoamiResp)) {
|
|
81
|
+
const message = (0, _request.formatErrorRespMessage)(whoamiResp);
|
|
82
|
+
_core.ux.error(new _error.ApiError(message));
|
|
83
|
+
}
|
|
84
|
+
const { account_slug } = whoamiResp.data;
|
|
85
|
+
const { workflowKey } = this.props.args;
|
|
86
|
+
const { environment, branch } = this.props.flags;
|
|
87
|
+
const envOrBranch = branch !== null && branch !== void 0 ? branch : environment;
|
|
88
|
+
const url = (0, _urls.viewWorkflowUrl)(this.sessionContext.dashboardOrigin, account_slug, envOrBranch, workflowKey);
|
|
89
|
+
this.log(`‣ Opening workflow \`${workflowKey}\` in the Knock dashboard...`);
|
|
90
|
+
this.log(` ${url}`);
|
|
91
|
+
await _browser.browser.openUrl(url);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
_define_property(WorkflowOpen, "summary", "Open a workflow in the Knock dashboard.");
|
|
95
|
+
_define_property(WorkflowOpen, "flags", {
|
|
96
|
+
environment: _core.Flags.string({
|
|
97
|
+
default: "development",
|
|
98
|
+
summary: "The environment to use."
|
|
99
|
+
}),
|
|
100
|
+
branch: _flag.branch
|
|
101
|
+
});
|
|
102
|
+
_define_property(WorkflowOpen, "args", {
|
|
103
|
+
workflowKey: _core.Args.string({
|
|
104
|
+
required: true
|
|
105
|
+
})
|
|
106
|
+
});
|
package/dist/lib/helpers/git.js
CHANGED
|
@@ -2,9 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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 getCurrentGitBranch () {
|
|
13
|
+
return getCurrentGitBranch;
|
|
14
|
+
},
|
|
15
|
+
get isFileIgnoredByGit () {
|
|
8
16
|
return isFileIgnoredByGit;
|
|
9
17
|
}
|
|
10
18
|
});
|
|
@@ -23,3 +31,14 @@ const isFileIgnoredByGit = async (currDir, filePath)=>{
|
|
|
23
31
|
return false;
|
|
24
32
|
}
|
|
25
33
|
};
|
|
34
|
+
const getCurrentGitBranch = ()=>{
|
|
35
|
+
try {
|
|
36
|
+
const branch = (0, _nodechild_process.execSync)("git rev-parse --abbrev-ref HEAD", {
|
|
37
|
+
stdio: "pipe",
|
|
38
|
+
encoding: "utf-8"
|
|
39
|
+
}).trim();
|
|
40
|
+
return branch;
|
|
41
|
+
} catch {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
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 generateAudienceDir () {
|
|
13
|
+
return generateAudienceDir;
|
|
14
|
+
},
|
|
15
|
+
get scaffoldAudienceDirBundle () {
|
|
16
|
+
return scaffoldAudienceDirBundle;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _processorisomorphic = require("./processor.isomorphic");
|
|
20
|
+
const _writer = require("./writer");
|
|
21
|
+
/*
|
|
22
|
+
* Scaffolds a new audience directory bundle with default content.
|
|
23
|
+
*/ const scaffoldAudienceDirBundle = (attrs)=>{
|
|
24
|
+
const audienceJson = {
|
|
25
|
+
name: attrs.name,
|
|
26
|
+
type: attrs.type
|
|
27
|
+
};
|
|
28
|
+
if (attrs.description) {
|
|
29
|
+
audienceJson.description = attrs.description;
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
[_processorisomorphic.AUDIENCE_JSON]: audienceJson
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const generateAudienceDir = async (audienceDirCtx, attrs)=>{
|
|
36
|
+
const bundle = scaffoldAudienceDirBundle(attrs);
|
|
37
|
+
return (0, _writer.writeAudienceDirFromBundle)(audienceDirCtx, bundle);
|
|
38
|
+
};
|
|
@@ -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
|
+
}({});
|