contensis-cli 1.0.11 → 1.0.12-beta.0
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/dist/mappers/DevInit-to-CIWorkflow.js +44 -25
- package/dist/mappers/DevInit-to-CIWorkflow.js.map +2 -2
- package/dist/services/ContensisAuthService.js +4 -0
- package/dist/services/ContensisAuthService.js.map +2 -2
- package/dist/services/ContensisCliService.js +4 -3
- package/dist/services/ContensisCliService.js.map +2 -2
- package/dist/services/ContensisDevService.js +39 -22
- package/dist/services/ContensisDevService.js.map +3 -3
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +1 -1
- package/src/mappers/DevInit-to-CIWorkflow.ts +51 -39
- package/src/services/ContensisAuthService.ts +5 -0
- package/src/services/ContensisCliService.ts +11 -3
- package/src/services/ContensisDevService.ts +52 -29
- package/src/version.ts +1 -1
|
@@ -22,10 +22,12 @@ import { winSlash } from '~/util/os';
|
|
|
22
22
|
import { stringifyYaml } from '~/util/yaml';
|
|
23
23
|
import { createSpinner } from 'nanospinner';
|
|
24
24
|
import { mergeContentsToAddWithGitignore } from '~/util/gitignore';
|
|
25
|
+
import ContensisAuthService from './ContensisAuthService';
|
|
26
|
+
import ansiEscapes from 'ansi-escapes';
|
|
25
27
|
|
|
26
28
|
class ContensisDev extends ContensisRole {
|
|
27
29
|
git!: GitHelper;
|
|
28
|
-
blockId
|
|
30
|
+
blockId!: string;
|
|
29
31
|
|
|
30
32
|
constructor(
|
|
31
33
|
args: string[],
|
|
@@ -47,6 +49,8 @@ class ContensisDev extends ContensisRole {
|
|
|
47
49
|
const contensis = await this.ConnectContensis();
|
|
48
50
|
|
|
49
51
|
if (contensis) {
|
|
52
|
+
this.devinit = { ...this.devinit, invokedBy: this.invokedBy };
|
|
53
|
+
|
|
50
54
|
// First we need to get the block id from the user
|
|
51
55
|
const validateBlockId = (blockId: string) => {
|
|
52
56
|
const pattern = /^[0-9a-z](-?[0-9a-z])*$/;
|
|
@@ -117,10 +121,30 @@ class ContensisDev extends ContensisRole {
|
|
|
117
121
|
// check we have the deply key so we can assign them to this values
|
|
118
122
|
if (existingDeployKey) {
|
|
119
123
|
// Add client id and secret to global 'this'
|
|
120
|
-
this.
|
|
121
|
-
|
|
124
|
+
this.devinit = {
|
|
125
|
+
...this.devinit,
|
|
126
|
+
credentials: {
|
|
127
|
+
clientId: existingDeployKey?.id,
|
|
128
|
+
clientSecret: existingDeployKey?.sharedSecret,
|
|
129
|
+
},
|
|
130
|
+
};
|
|
122
131
|
}
|
|
123
132
|
|
|
133
|
+
// we need to credentials of the user so that we can create a auth service
|
|
134
|
+
const credentials = await this.GetCredentials(this.devinit.invokedBy);
|
|
135
|
+
|
|
136
|
+
// create new auth service using creds
|
|
137
|
+
let classicToken: string | undefined | null;
|
|
138
|
+
const auth = new ContensisAuthService({
|
|
139
|
+
username: credentials?.current?.account,
|
|
140
|
+
password: credentials?.current?.password,
|
|
141
|
+
projectId: currentProject,
|
|
142
|
+
rootUrl: `https://cms-${currentEnv}.cloud.contensis.com`,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// once we have auth service, we can go and fetch out classic token
|
|
146
|
+
classicToken = await auth.ClassicToken();
|
|
147
|
+
|
|
124
148
|
// const blockId = git.name;
|
|
125
149
|
const errors = [] as AppError[];
|
|
126
150
|
|
|
@@ -171,34 +195,27 @@ class ContensisDev extends ContensisRole {
|
|
|
171
195
|
|
|
172
196
|
let mappedWorkflow;
|
|
173
197
|
// Location for Client ID / Secret.
|
|
174
|
-
const {
|
|
175
|
-
name: '
|
|
198
|
+
const { loc } = await inquirer.prompt({
|
|
199
|
+
name: 'loc',
|
|
176
200
|
type: 'list',
|
|
177
201
|
prefix: '🔑',
|
|
178
|
-
// Where would you like to store your
|
|
202
|
+
// Where would you like to store your client id/secret?
|
|
179
203
|
message: messages.devinit.clientDetailsLocation(),
|
|
180
204
|
choices: [
|
|
181
|
-
|
|
182
|
-
|
|
205
|
+
{
|
|
206
|
+
name: messages.devinit.clientDetailsInGit(git),
|
|
207
|
+
value: 'git',
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
name: messages.devinit.clientDetailsInEnv(),
|
|
211
|
+
value: 'env',
|
|
212
|
+
},
|
|
183
213
|
],
|
|
184
214
|
});
|
|
185
215
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
} else {
|
|
190
|
-
this.clientDetailsLocation = 'git';
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (this.clientDetailsLocation === 'env') {
|
|
194
|
-
// Update CI Workflow to pull from ENV variables
|
|
195
|
-
mappedWorkflow = await mapCIWorkflowContent(this);
|
|
196
|
-
log.help(messages.devinit.ciIntro(git, 'env'));
|
|
197
|
-
} else {
|
|
198
|
-
// Look at the workflow file content and make updates
|
|
199
|
-
mappedWorkflow = await mapCIWorkflowContent(this);
|
|
200
|
-
log.help(messages.devinit.ciIntro(git, 'git'));
|
|
201
|
-
}
|
|
216
|
+
log.help(messages.devinit.ciIntro(git, loc));
|
|
217
|
+
// Update CI Workflow
|
|
218
|
+
mappedWorkflow = await mapCIWorkflowContent(this, loc);
|
|
202
219
|
|
|
203
220
|
if (!dryRun) {
|
|
204
221
|
// Confirm prompt
|
|
@@ -279,7 +296,7 @@ class ContensisDev extends ContensisRole {
|
|
|
279
296
|
};
|
|
280
297
|
if (accessToken) envContentsToAdd['ACCESS_TOKEN'] = accessToken;
|
|
281
298
|
// add client id and secret to the env file
|
|
282
|
-
if (
|
|
299
|
+
if (loc === 'env') {
|
|
283
300
|
envContentsToAdd['CONTENSIS_CLIENT_ID'] = existingDevKey?.id;
|
|
284
301
|
envContentsToAdd['CONTENSIS_CLIENT_SECRET'] =
|
|
285
302
|
existingDevKey?.sharedSecret;
|
|
@@ -303,7 +320,8 @@ class ContensisDev extends ContensisRole {
|
|
|
303
320
|
}
|
|
304
321
|
};
|
|
305
322
|
|
|
306
|
-
|
|
323
|
+
// remove client id and secret from env file
|
|
324
|
+
if (loc === 'git') {
|
|
307
325
|
removeEnvItems(['CONTENSIS_CLIENT_ID', 'CONTENSIS_CLIENT_SECRET']);
|
|
308
326
|
}
|
|
309
327
|
|
|
@@ -358,7 +376,7 @@ class ContensisDev extends ContensisRole {
|
|
|
358
376
|
}
|
|
359
377
|
}
|
|
360
378
|
|
|
361
|
-
if (
|
|
379
|
+
if (loc === 'git') {
|
|
362
380
|
// Echo Deployment API key to console, ask user to add secrets to repo
|
|
363
381
|
log.warning(messages.devinit.addGitSecretsIntro());
|
|
364
382
|
log.help(
|
|
@@ -376,9 +394,14 @@ class ContensisDev extends ContensisRole {
|
|
|
376
394
|
} else {
|
|
377
395
|
log.success(messages.devinit.success());
|
|
378
396
|
log.help(messages.devinit.startProjectTip());
|
|
379
|
-
//
|
|
397
|
+
// open the cms link -- if no classic token just return the cms url
|
|
380
398
|
log.help(
|
|
381
|
-
|
|
399
|
+
ansiEscapes.link(
|
|
400
|
+
`Open Contensis`,
|
|
401
|
+
`https://cms-${currentEnv}.cloud.contensis.com${
|
|
402
|
+
classicToken ? `?SecurityToken=${classicToken}` : ''
|
|
403
|
+
}`
|
|
404
|
+
)
|
|
382
405
|
);
|
|
383
406
|
}
|
|
384
407
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const LIB_VERSION = "1.0.
|
|
1
|
+
export const LIB_VERSION = "1.0.12-beta.0";
|