@knocklabs/cli 1.0.0 → 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 +252 -69
- 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/pull.js +19 -12
- package/dist/commands/push.js +19 -12
- 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 +4 -0
- package/oclif.manifest.json +737 -94
- package/package.json +10 -10
|
@@ -8,9 +8,13 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return BranchCreate;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
+
const _enquirer = require("enquirer");
|
|
11
12
|
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
12
13
|
const _arg = require("../../lib/helpers/arg");
|
|
14
|
+
const _const = require("../../lib/helpers/const");
|
|
15
|
+
const _git = require("../../lib/helpers/git");
|
|
13
16
|
const _request = require("../../lib/helpers/request");
|
|
17
|
+
const _string = require("../../lib/helpers/string");
|
|
14
18
|
function _define_property(obj, key, value) {
|
|
15
19
|
if (key in obj) {
|
|
16
20
|
Object.defineProperty(obj, key, {
|
|
@@ -32,12 +36,45 @@ function _interop_require_default(obj) {
|
|
|
32
36
|
class BranchCreate extends _basecommand.default {
|
|
33
37
|
async run() {
|
|
34
38
|
const { args, flags } = this.props;
|
|
35
|
-
|
|
39
|
+
// If slug is provided, use it directly
|
|
40
|
+
let slug = args.slug;
|
|
41
|
+
// Otherwise, prompt for it with Git branch as default
|
|
42
|
+
if (!slug) {
|
|
43
|
+
slug = await this.promptForBranchSlug();
|
|
44
|
+
}
|
|
45
|
+
if (!slug) {
|
|
46
|
+
return this.error("Invalid slug provided");
|
|
47
|
+
}
|
|
48
|
+
const resp = await this.request(slug);
|
|
36
49
|
if (flags.json) return resp;
|
|
37
50
|
this.render(resp);
|
|
38
51
|
}
|
|
52
|
+
async promptForBranchSlug() {
|
|
53
|
+
const gitBranch = (0, _git.getCurrentGitBranch)();
|
|
54
|
+
const initial = gitBranch ? (0, _string.slugify)(gitBranch) : undefined;
|
|
55
|
+
try {
|
|
56
|
+
const response = await (0, _enquirer.prompt)({
|
|
57
|
+
type: "input",
|
|
58
|
+
name: "slug",
|
|
59
|
+
message: "Branch slug",
|
|
60
|
+
initial,
|
|
61
|
+
validate: (value)=>{
|
|
62
|
+
const slugified = (0, _string.slugify)(value);
|
|
63
|
+
if (!slugified) {
|
|
64
|
+
return "Invalid slug provided";
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return (0, _string.slugify)(response.slug);
|
|
70
|
+
} catch {
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
39
74
|
async request(slug) {
|
|
40
|
-
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.
|
|
75
|
+
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.branches.create(slug, {
|
|
76
|
+
environment: _const.KnockEnv.Development
|
|
77
|
+
}));
|
|
41
78
|
}
|
|
42
79
|
async render(data) {
|
|
43
80
|
this.log(`‣ Successfully created branch \`${data.slug}\``);
|
|
@@ -48,7 +85,7 @@ _define_property(BranchCreate, "summary", "Creates a new branch off of the devel
|
|
|
48
85
|
_define_property(BranchCreate, "enableJsonFlag", true);
|
|
49
86
|
_define_property(BranchCreate, "args", {
|
|
50
87
|
slug: _arg.CustomArgs.slug({
|
|
51
|
-
required:
|
|
88
|
+
required: false,
|
|
52
89
|
description: "The slug for the new branch"
|
|
53
90
|
})
|
|
54
91
|
});
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
const _core = require("@oclif/core");
|
|
12
12
|
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
13
|
+
const _const = require("../../lib/helpers/const");
|
|
13
14
|
const _date = require("../../lib/helpers/date");
|
|
14
15
|
const _page = require("../../lib/helpers/page");
|
|
15
16
|
const _request = require("../../lib/helpers/request");
|
|
@@ -43,28 +44,32 @@ class BranchList extends _basecommand.default {
|
|
|
43
44
|
...this.props.flags,
|
|
44
45
|
...pageParams
|
|
45
46
|
});
|
|
46
|
-
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.
|
|
47
|
-
|
|
47
|
+
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.branches.list({
|
|
48
|
+
environment: _const.KnockEnv.Development,
|
|
49
|
+
...queryParams
|
|
48
50
|
}));
|
|
49
51
|
}
|
|
50
52
|
async render(data) {
|
|
51
53
|
const { entries } = data;
|
|
52
54
|
this.log(`‣ Showing ${entries.length} branches off of the development environment\n`);
|
|
53
|
-
|
|
55
|
+
const formattedBranches = entries.map((entry)=>({
|
|
56
|
+
slug: entry.slug,
|
|
57
|
+
created_at: (0, _date.formatDate)(entry.created_at),
|
|
58
|
+
updated_at: (0, _date.formatDate)(entry.updated_at),
|
|
59
|
+
last_commit_at: entry.last_commit_at ? (0, _date.formatDate)(entry.last_commit_at) : "Never"
|
|
60
|
+
}));
|
|
61
|
+
_core.ux.table(formattedBranches, {
|
|
54
62
|
slug: {
|
|
55
63
|
header: "Slug"
|
|
56
64
|
},
|
|
57
65
|
created_at: {
|
|
58
|
-
header: "Created at"
|
|
59
|
-
get: (entry)=>(0, _date.formatDate)(entry.created_at)
|
|
66
|
+
header: "Created at"
|
|
60
67
|
},
|
|
61
68
|
updated_at: {
|
|
62
|
-
header: "Updated at"
|
|
63
|
-
get: (entry)=>(0, _date.formatDate)(entry.updated_at)
|
|
69
|
+
header: "Updated at"
|
|
64
70
|
},
|
|
65
71
|
last_commit_at: {
|
|
66
|
-
header: "Last commit at"
|
|
67
|
-
get: (entry)=>entry.last_commit_at ? (0, _date.formatDate)(entry.last_commit_at) : "Never"
|
|
72
|
+
header: "Last commit at"
|
|
68
73
|
}
|
|
69
74
|
});
|
|
70
75
|
return this.prompt(data);
|
|
@@ -15,6 +15,7 @@ const _fsextra = /*#__PURE__*/ _interop_require_wildcard(require("fs-extra"));
|
|
|
15
15
|
const _basecommand = /*#__PURE__*/ _interop_require_default(require("../../lib/base-command"));
|
|
16
16
|
const _arg = require("../../lib/helpers/arg");
|
|
17
17
|
const _branch = require("../../lib/helpers/branch");
|
|
18
|
+
const _const = require("../../lib/helpers/const");
|
|
18
19
|
const _error = require("../../lib/helpers/error");
|
|
19
20
|
const _git = require("../../lib/helpers/git");
|
|
20
21
|
const _request = require("../../lib/helpers/request");
|
|
@@ -132,12 +133,16 @@ class BranchSwitch extends _basecommand.default {
|
|
|
132
133
|
}
|
|
133
134
|
}
|
|
134
135
|
async fetchBranch(slug) {
|
|
135
|
-
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.
|
|
136
|
+
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.branches.retrieve(slug, {
|
|
137
|
+
environment: _const.KnockEnv.Development
|
|
138
|
+
}), {
|
|
136
139
|
action: "‣ Fetching branch"
|
|
137
140
|
});
|
|
138
141
|
}
|
|
139
142
|
async createBranch(slug) {
|
|
140
|
-
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.
|
|
143
|
+
return (0, _request.withSpinnerV2)(()=>this.apiV1.mgmtClient.branches.create(slug, {
|
|
144
|
+
environment: _const.KnockEnv.Development
|
|
145
|
+
}), {
|
|
141
146
|
action: "‣ Creating branch"
|
|
142
147
|
});
|
|
143
148
|
}
|
package/dist/commands/pull.js
CHANGED
|
@@ -15,12 +15,13 @@ const _flag = /*#__PURE__*/ _interop_require_wildcard(require("../lib/helpers/fl
|
|
|
15
15
|
const _projectconfig = require("../lib/helpers/project-config");
|
|
16
16
|
const _ux = require("../lib/helpers/ux");
|
|
17
17
|
const _resources = require("../lib/resources");
|
|
18
|
-
const _pull = /*#__PURE__*/ _interop_require_default(require("./
|
|
19
|
-
const _pull1 = /*#__PURE__*/ _interop_require_default(require("./
|
|
20
|
-
const _pull2 = /*#__PURE__*/ _interop_require_default(require("./
|
|
21
|
-
const _pull3 = /*#__PURE__*/ _interop_require_default(require("./
|
|
22
|
-
const _pull4 = /*#__PURE__*/ _interop_require_default(require("./
|
|
23
|
-
const _pull5 = /*#__PURE__*/ _interop_require_default(require("./
|
|
18
|
+
const _pull = /*#__PURE__*/ _interop_require_default(require("./audience/pull"));
|
|
19
|
+
const _pull1 = /*#__PURE__*/ _interop_require_default(require("./guide/pull"));
|
|
20
|
+
const _pull2 = /*#__PURE__*/ _interop_require_default(require("./layout/pull"));
|
|
21
|
+
const _pull3 = /*#__PURE__*/ _interop_require_default(require("./message-type/pull"));
|
|
22
|
+
const _pull4 = /*#__PURE__*/ _interop_require_default(require("./partial/pull"));
|
|
23
|
+
const _pull5 = /*#__PURE__*/ _interop_require_default(require("./translation/pull"));
|
|
24
|
+
const _pull6 = /*#__PURE__*/ _interop_require_default(require("./workflow/pull"));
|
|
24
25
|
function _define_property(obj, key, value) {
|
|
25
26
|
if (key in obj) {
|
|
26
27
|
Object.defineProperty(obj, key, {
|
|
@@ -140,39 +141,45 @@ _define_property(Pull, "flags", {
|
|
|
140
141
|
const runResourcePullCommand = async (resourceType, targetDirCtx, args)=>{
|
|
141
142
|
const subdirPath = _nodepath.resolve(targetDirCtx.abspath, _resources.RESOURCE_SUBDIRS[resourceType]);
|
|
142
143
|
switch(resourceType){
|
|
144
|
+
case "audience":
|
|
145
|
+
return _pull.default.run([
|
|
146
|
+
...args,
|
|
147
|
+
"--audiences-dir",
|
|
148
|
+
subdirPath
|
|
149
|
+
]);
|
|
143
150
|
case "email_layout":
|
|
144
|
-
return
|
|
151
|
+
return _pull2.default.run([
|
|
145
152
|
...args,
|
|
146
153
|
"--layouts-dir",
|
|
147
154
|
subdirPath
|
|
148
155
|
]);
|
|
149
156
|
case "partial":
|
|
150
|
-
return
|
|
157
|
+
return _pull4.default.run([
|
|
151
158
|
...args,
|
|
152
159
|
"--partials-dir",
|
|
153
160
|
subdirPath
|
|
154
161
|
]);
|
|
155
162
|
// TODO(KNO-9451): Include translation in the knock pull
|
|
156
163
|
case "translation":
|
|
157
|
-
return
|
|
164
|
+
return _pull5.default.run([
|
|
158
165
|
...args,
|
|
159
166
|
"--translations-dir",
|
|
160
167
|
subdirPath
|
|
161
168
|
]);
|
|
162
169
|
case "workflow":
|
|
163
|
-
return
|
|
170
|
+
return _pull6.default.run([
|
|
164
171
|
...args,
|
|
165
172
|
"--workflows-dir",
|
|
166
173
|
subdirPath
|
|
167
174
|
]);
|
|
168
175
|
case "message_type":
|
|
169
|
-
return
|
|
176
|
+
return _pull3.default.run([
|
|
170
177
|
...args,
|
|
171
178
|
"--message-types-dir",
|
|
172
179
|
subdirPath
|
|
173
180
|
]);
|
|
174
181
|
case "guide":
|
|
175
|
-
return
|
|
182
|
+
return _pull1.default.run([
|
|
176
183
|
...args,
|
|
177
184
|
"--guides-dir",
|
|
178
185
|
subdirPath
|
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
|
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
|
+
};
|