@contrail/cli 1.0.44 → 1.0.47

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/lib/cli.js CHANGED
@@ -13,6 +13,7 @@ import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTempl
13
13
  import { installApp, uninstallApp } from './apps/install-app/app-installer';
14
14
  import { upgradeApp } from './apps/upgrade-app/app-upgrader';
15
15
  import { cliInstallWorkflowTemplateDefinitions, listWorkflowTemplateDefinitions } from './workflow-template-definitions/workflow-template-definition-commands';
16
+ import { configureProject } from './projects/project-uploader';
16
17
  const cliUsage = require('command-line-usage');
17
18
  /**
18
19
  * Built using documentation here:
@@ -135,6 +136,18 @@ export async function cli(args) {
135
136
  }
136
137
  break;
137
138
  }
139
+ case 'projects': {
140
+ switch (command) {
141
+ case 'configure': {
142
+ await configureProject(args);
143
+ break;
144
+ }
145
+ default: {
146
+ printIllegalCommand();
147
+ }
148
+ }
149
+ break;
150
+ }
138
151
  case 'workflow-templates': {
139
152
  switch (command) {
140
153
  case 'load': {
@@ -0,0 +1,73 @@
1
+ export declare class CommonConfiguration {
2
+ [key: string]: any;
3
+ }
4
+ export declare enum AssortmentType {
5
+ ASSORTMENT = "ASSORTMENT",
6
+ BOARD = "BOARD",
7
+ PLAN = "PLAN",
8
+ SHOWCASE = "SHOWCASE"
9
+ }
10
+ export declare class AssortmentConfiguration {
11
+ identifier: string;
12
+ name: string;
13
+ type: AssortmentType;
14
+ sourceAssortmentIdentifier?: string;
15
+ composedFromAssortmentIdentifiers?: string[];
16
+ ownerAtts?: {
17
+ [key: string]: any;
18
+ };
19
+ assortmentAtts?: {
20
+ [key: string]: any;
21
+ };
22
+ }
23
+ export declare class Folder {
24
+ identifier: string;
25
+ name: string;
26
+ assortments: AssortmentConfiguration[];
27
+ subFolders: Folder[];
28
+ }
29
+ export declare class ProjectConfiguration {
30
+ projectName: string;
31
+ identifier: string;
32
+ commonConfig: CommonConfiguration;
33
+ assortments: AssortmentConfiguration[];
34
+ subFolders: Folder[];
35
+ }
36
+ export declare class ProjectConfigurationTemplate {
37
+ projectName: string;
38
+ identifier: string;
39
+ commonConfig: CommonConfiguration;
40
+ allFolders: FolderSlim[];
41
+ allAssortments: AssortmentConfigurationSlim[];
42
+ allAssortmentRelationships: AssortmentConfigurationRelationships[];
43
+ }
44
+ export declare class FolderSlim {
45
+ identifier: string;
46
+ name: string;
47
+ folderIdentifier: string;
48
+ }
49
+ export declare class AssortmentConfigurationSlim {
50
+ identifier: string;
51
+ name: string;
52
+ type: AssortmentType;
53
+ folderIdentifier: string;
54
+ sourceAssortmentIdentifier?: string;
55
+ composedFromAssortmentIdentifiers?: string[];
56
+ ownerAtts?: {
57
+ [key: string]: any;
58
+ };
59
+ assortmentAtts?: {
60
+ [key: string]: any;
61
+ };
62
+ }
63
+ export declare class AssortmentConfigurationRelationships {
64
+ identifier: string;
65
+ sourceAssortmentIdentifier?: string;
66
+ composedFromAssortmentIdentifiers?: string[];
67
+ ownerAtts?: {
68
+ [key: string]: any;
69
+ };
70
+ assortmentAtts?: {
71
+ [key: string]: any;
72
+ };
73
+ }
@@ -0,0 +1,23 @@
1
+ export class CommonConfiguration {
2
+ }
3
+ export var AssortmentType;
4
+ (function (AssortmentType) {
5
+ AssortmentType["ASSORTMENT"] = "ASSORTMENT";
6
+ AssortmentType["BOARD"] = "BOARD";
7
+ AssortmentType["PLAN"] = "PLAN";
8
+ AssortmentType["SHOWCASE"] = "SHOWCASE";
9
+ })(AssortmentType || (AssortmentType = {}));
10
+ export class AssortmentConfiguration {
11
+ }
12
+ export class Folder {
13
+ }
14
+ export class ProjectConfiguration {
15
+ }
16
+ export class ProjectConfigurationTemplate {
17
+ }
18
+ export class FolderSlim {
19
+ }
20
+ export class AssortmentConfigurationSlim {
21
+ }
22
+ export class AssortmentConfigurationRelationships {
23
+ }
@@ -0,0 +1 @@
1
+ export declare function configureProject(args: any): Promise<void>;
@@ -0,0 +1,104 @@
1
+ import { Request } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import fs from 'fs';
4
+ import { authUser } from '../auth/login';
5
+ import { getSeparatorByPlatform } from '../common';
6
+ import yaml from 'js-yaml';
7
+ export async function configureProject(args) {
8
+ try {
9
+ await authUser();
10
+ console.log('%s Parsing Template.', chalk.blue.bold('START'));
11
+ console.log('%s Uploading', chalk.yellow.bold('PROJECT'));
12
+ const templateFileLocation = args[3];
13
+ console.log('Using Template File Location: ', templateFileLocation);
14
+ await uploadProject(templateFileLocation);
15
+ console.log('%s Uploaded', chalk.yellow.bold('PROJECT'));
16
+ }
17
+ catch (e) {
18
+ console.log(`%s Project Upload Failed. ${e}`, chalk.red.bold('FAIL'));
19
+ return;
20
+ }
21
+ console.log('%s Project Upload Complete.', chalk.green.bold('COMPLETE'));
22
+ }
23
+ function getProjectFile(fileName) {
24
+ const CURRENT_DIR = process.cwd();
25
+ try {
26
+ const separator = getSeparatorByPlatform();
27
+ const fullPath = CURRENT_DIR + separator + fileName;
28
+ console.log('Getting file from path: ', fullPath);
29
+ const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
30
+ return doc.projectConfiguration;
31
+ }
32
+ catch (e) {
33
+ throw new Error(`ERROR PARSING YAML: ${e}`);
34
+ }
35
+ }
36
+ async function uploadProject(templateFileLocation) {
37
+ const projectConfigurationFromFile = getProjectFile(templateFileLocation);
38
+ const projectConfiguration = getProjectConfiguration(projectConfigurationFromFile);
39
+ console.log('Configuring Project.');
40
+ await Request.request('/project-configurator', {
41
+ method: 'POST',
42
+ body: JSON.stringify(projectConfiguration),
43
+ headers: {
44
+ Accept: 'application/json',
45
+ 'Content-Type': 'application/json',
46
+ },
47
+ });
48
+ }
49
+ function getProjectConfiguration(projectConfigurationFromFile) {
50
+ if (!projectConfigurationFromFile.allFolders && !projectConfigurationFromFile.allAssortments && !projectConfigurationFromFile.allAssortmentRelationships) {
51
+ return projectConfigurationFromFile;
52
+ }
53
+ const parsed = parseToProjectConfiguration(projectConfigurationFromFile);
54
+ return parsed;
55
+ }
56
+ function parseToProjectConfiguration(projectConfigurationFromFile) {
57
+ const projectConfiguration = {
58
+ projectName: projectConfigurationFromFile.projectName,
59
+ identifier: projectConfigurationFromFile.identifier,
60
+ commonConfig: projectConfigurationFromFile.commonConfig,
61
+ assortments: [],
62
+ subFolders: [],
63
+ };
64
+ const foldersByIdentifier = { [projectConfiguration.identifier]: projectConfiguration };
65
+ for (const folder of projectConfigurationFromFile.allFolders) {
66
+ foldersByIdentifier[folder.identifier] = folder;
67
+ }
68
+ const assortmentsByIdentifier = {};
69
+ for (const assortment of projectConfigurationFromFile.allAssortments) {
70
+ assortmentsByIdentifier[assortment.identifier] = assortment;
71
+ }
72
+ for (const assortmentRelationships of projectConfigurationFromFile.allAssortmentRelationships) {
73
+ const assortment = assortmentsByIdentifier[assortmentRelationships.identifier];
74
+ if (!assortment) {
75
+ console.warn('Relationship defined for assortment that is not defined.', assortmentRelationships);
76
+ }
77
+ else {
78
+ Object.assign(assortment, assortmentRelationships);
79
+ }
80
+ }
81
+ for (const assortment of projectConfigurationFromFile.allAssortments) {
82
+ const folder = foldersByIdentifier[assortment.folderIdentifier];
83
+ if (!folder) {
84
+ console.warn('Assortment defined for folder that is not defined.', assortment);
85
+ }
86
+ if (!folder.assortments) {
87
+ folder.assortments = [];
88
+ }
89
+ delete assortment.folderIdentifier;
90
+ folder.assortments.push(assortment);
91
+ }
92
+ for (const folderSlim of projectConfigurationFromFile.allFolders) {
93
+ const folder = foldersByIdentifier[folderSlim.folderIdentifier];
94
+ if (!folder) {
95
+ console.warn('Folder defined for folder that is not defined.', folderSlim);
96
+ }
97
+ if (!folder.subFolders) {
98
+ folder.subFolders = [];
99
+ }
100
+ delete folderSlim.folderIdentifier;
101
+ folder.subFolders.push(folderSlim);
102
+ }
103
+ return projectConfiguration;
104
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/cli",
3
- "version": "1.0.44",
3
+ "version": "1.0.47",
4
4
  "description": "VibeIQ's Contrail Platform CLI.",
5
5
  "main": "lib/index.js",
6
6
  "bin": {
@@ -23,8 +23,8 @@
23
23
  "author": "",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@contrail/sdk": "^1.0.154",
27
- "@contrail/types": "^2.0.75",
26
+ "@contrail/sdk": "^1.1.43",
27
+ "@contrail/types": "^3.0.20",
28
28
  "@contrail/util": "^1.0.17",
29
29
  "amazon-cognito-identity-js": "^5.2.3",
30
30
  "arg": "^4.0.1",
package/src/cli.ts CHANGED
@@ -14,6 +14,8 @@ import { deleteWorkflowTemplates, localDeployWorkflowTemplate, listWorkflowTempl
14
14
  import { installApp, uninstallApp } from './apps/install-app/app-installer';
15
15
  import { upgradeApp } from './apps/upgrade-app/app-upgrader';
16
16
  import { cliInstallWorkflowTemplateDefinitions, listWorkflowTemplateDefinitions } from './workflow-template-definitions/workflow-template-definition-commands';
17
+ import { configureProject } from './projects/project-uploader';
18
+
17
19
  const cliUsage = require('command-line-usage');
18
20
 
19
21
  /**
@@ -145,6 +147,18 @@ export async function cli(args) {
145
147
  }
146
148
  break;
147
149
  }
150
+ case 'projects': {
151
+ switch (command) {
152
+ case 'configure': {
153
+ await configureProject(args);
154
+ break;
155
+ }
156
+ default: {
157
+ printIllegalCommand();
158
+ }
159
+ }
160
+ break;
161
+ }
148
162
  case 'workflow-templates': {
149
163
  switch (command) {
150
164
  case 'load': {
@@ -0,0 +1,69 @@
1
+ export class CommonConfiguration {
2
+ [key: string]: any;
3
+ }
4
+
5
+ export enum AssortmentType {
6
+ ASSORTMENT = 'ASSORTMENT',
7
+ BOARD = 'BOARD',
8
+ PLAN = 'PLAN',
9
+ SHOWCASE = 'SHOWCASE',
10
+ }
11
+
12
+ export class AssortmentConfiguration {
13
+ identifier: string;
14
+ name: string;
15
+ type: AssortmentType;
16
+ sourceAssortmentIdentifier?: string;
17
+ composedFromAssortmentIdentifiers?: string[];
18
+ ownerAtts?: {[key: string]: any};
19
+ assortmentAtts?: {[key: string]: any};
20
+ }
21
+
22
+ export class Folder {
23
+ identifier: string;
24
+ name: string;
25
+ assortments: AssortmentConfiguration[];
26
+ subFolders: Folder[];
27
+ }
28
+
29
+ export class ProjectConfiguration {
30
+ projectName: string;
31
+ identifier: string;
32
+ commonConfig: CommonConfiguration;
33
+ assortments: AssortmentConfiguration[];
34
+ subFolders: Folder[];
35
+ }
36
+
37
+ export class ProjectConfigurationTemplate {
38
+ projectName: string;
39
+ identifier: string;
40
+ commonConfig: CommonConfiguration;
41
+ allFolders: FolderSlim[];
42
+ allAssortments: AssortmentConfigurationSlim[];
43
+ allAssortmentRelationships: AssortmentConfigurationRelationships[];
44
+ }
45
+
46
+ export class FolderSlim {
47
+ identifier: string;
48
+ name: string;
49
+ folderIdentifier: string;
50
+ }
51
+
52
+ export class AssortmentConfigurationSlim {
53
+ identifier: string;
54
+ name: string;
55
+ type: AssortmentType;
56
+ folderIdentifier: string;
57
+ sourceAssortmentIdentifier?: string;
58
+ composedFromAssortmentIdentifiers?: string[];
59
+ ownerAtts?: {[key: string]: any};
60
+ assortmentAtts?: {[key: string]: any};
61
+ }
62
+
63
+ export class AssortmentConfigurationRelationships {
64
+ identifier: string;
65
+ sourceAssortmentIdentifier?: string;
66
+ composedFromAssortmentIdentifiers?: string[];
67
+ ownerAtts?: {[key: string]: any};
68
+ assortmentAtts?: {[key: string]: any};
69
+ }
@@ -0,0 +1,130 @@
1
+ import { Request } from '@contrail/sdk';
2
+ import chalk from 'chalk';
3
+ import fs from 'fs';
4
+ import { authUser } from '../auth/login';
5
+ import { getSeparatorByPlatform } from '../common';
6
+ import { ProjectConfiguration, ProjectConfigurationTemplate } from './interfaces';
7
+
8
+ import yaml from 'js-yaml';
9
+
10
+ export async function configureProject(args) {
11
+ try {
12
+ await authUser();
13
+ console.log('%s Parsing Template.', chalk.blue.bold('START'));
14
+
15
+ console.log('%s Uploading', chalk.yellow.bold('PROJECT'));
16
+ const templateFileLocation = args[3];
17
+ console.log('Using Template File Location: ', templateFileLocation);
18
+ await uploadProject(templateFileLocation);
19
+ console.log('%s Uploaded', chalk.yellow.bold('PROJECT'));
20
+
21
+ }
22
+ catch (e) {
23
+ console.log(`%s Project Upload Failed. ${e}`, chalk.red.bold('FAIL'));
24
+ return;
25
+ }
26
+
27
+ console.log('%s Project Upload Complete.', chalk.green.bold('COMPLETE'));
28
+ }
29
+
30
+ function getProjectFile(fileName){
31
+ const CURRENT_DIR = process.cwd();
32
+ try {
33
+ const separator = getSeparatorByPlatform();
34
+ const fullPath = CURRENT_DIR + separator + fileName;
35
+ console.log('Getting file from path: ', fullPath);
36
+
37
+ const doc = yaml.load(fs.readFileSync(fullPath, 'utf8'));
38
+ return doc.projectConfiguration;
39
+ } catch (e) {
40
+ throw new Error(`ERROR PARSING YAML: ${e}`);
41
+ }
42
+ }
43
+
44
+ async function uploadProject(templateFileLocation) {
45
+ const projectConfigurationFromFile = getProjectFile(templateFileLocation);
46
+ const projectConfiguration: ProjectConfiguration = getProjectConfiguration(projectConfigurationFromFile);
47
+
48
+ console.log('Configuring Project.');
49
+
50
+ await Request.request(
51
+ '/project-configurator',
52
+ {
53
+ method: 'POST',
54
+ body: JSON.stringify(projectConfiguration),
55
+ headers: {
56
+ Accept: 'application/json',
57
+ 'Content-Type': 'application/json',
58
+ },
59
+ });
60
+ }
61
+
62
+ function getProjectConfiguration(projectConfigurationFromFile): ProjectConfiguration {
63
+ if (!projectConfigurationFromFile.allFolders && !projectConfigurationFromFile.allAssortments && !projectConfigurationFromFile.allAssortmentRelationships) {
64
+ return projectConfigurationFromFile;
65
+ }
66
+
67
+ const parsed = parseToProjectConfiguration(projectConfigurationFromFile);
68
+ return parsed;
69
+ }
70
+
71
+ function parseToProjectConfiguration(projectConfigurationFromFile: ProjectConfigurationTemplate): ProjectConfiguration {
72
+
73
+ const projectConfiguration: ProjectConfiguration = {
74
+ projectName: projectConfigurationFromFile.projectName,
75
+ identifier: projectConfigurationFromFile.identifier,
76
+ commonConfig: projectConfigurationFromFile.commonConfig,
77
+ assortments: [],
78
+ subFolders: [],
79
+ };
80
+
81
+ const foldersByIdentifier: any = {[projectConfiguration.identifier]: projectConfiguration};
82
+ for (const folder of projectConfigurationFromFile.allFolders) {
83
+ foldersByIdentifier[folder.identifier] = folder;
84
+ }
85
+
86
+ const assortmentsByIdentifier = {};
87
+ for (const assortment of projectConfigurationFromFile.allAssortments) {
88
+ assortmentsByIdentifier[assortment.identifier] = assortment;
89
+ }
90
+
91
+ for (const assortmentRelationships of projectConfigurationFromFile.allAssortmentRelationships) {
92
+ const assortment = assortmentsByIdentifier[assortmentRelationships.identifier];
93
+ if (!assortment) {
94
+ console.warn('Relationship defined for assortment that is not defined.', assortmentRelationships);
95
+ }
96
+ else {
97
+ Object.assign(assortment, assortmentRelationships);
98
+ }
99
+ }
100
+
101
+ for (const assortment of projectConfigurationFromFile.allAssortments) {
102
+ const folder = foldersByIdentifier[assortment.folderIdentifier];
103
+ if (!folder) {
104
+ console.warn('Assortment defined for folder that is not defined.', assortment);
105
+ }
106
+
107
+ if (!folder.assortments) {
108
+ folder.assortments = [];
109
+ }
110
+
111
+ delete assortment.folderIdentifier;
112
+ folder.assortments.push(assortment);
113
+ }
114
+
115
+ for (const folderSlim of projectConfigurationFromFile.allFolders) {
116
+ const folder = foldersByIdentifier[folderSlim.folderIdentifier];
117
+ if (!folder) {
118
+ console.warn('Folder defined for folder that is not defined.', folderSlim);
119
+ }
120
+
121
+ if (!folder.subFolders) {
122
+ folder.subFolders = [];
123
+ }
124
+
125
+ delete folderSlim.folderIdentifier;
126
+ folder.subFolders.push(folderSlim);
127
+ }
128
+
129
+ return projectConfiguration;
130
+ }