@contrail/flexplm 1.7.0-alpha.71b4d30 → 1.7.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.
Files changed (41) hide show
  1. package/lib/cli/commands/{config-file/create.d.ts → create.d.ts} +1 -0
  2. package/lib/cli/commands/{mapping-file/create.js → create.js} +20 -4
  3. package/lib/cli/commands/{mapping-file/create.spec.js → create.spec.js} +1 -1
  4. package/lib/cli/commands/upload.d.ts +19 -0
  5. package/lib/cli/commands/upload.js +254 -0
  6. package/lib/cli/commands/upload.spec.js +95 -0
  7. package/lib/cli/index.js +37 -18
  8. package/lib/cli/index.spec.js +53 -111
  9. package/lib/publish/base-process-publish-assortment.d.ts +2 -0
  10. package/lib/publish/base-process-publish-assortment.js +59 -7
  11. package/lib/publish/base-process-publish-assortment.spec.js +188 -0
  12. package/package.json +2 -2
  13. package/scripts/copy-template.js +5 -16
  14. package/lib/cli/commands/config-file/create.js +0 -61
  15. package/lib/cli/commands/config-file/create.spec.js +0 -74
  16. package/lib/cli/commands/config-file/index.d.ts +0 -2
  17. package/lib/cli/commands/config-file/index.js +0 -47
  18. package/lib/cli/commands/config-file/upload.d.ts +0 -8
  19. package/lib/cli/commands/config-file/upload.js +0 -84
  20. package/lib/cli/commands/config-file/upload.spec.js +0 -51
  21. package/lib/cli/commands/mapping-file/create.d.ts +0 -4
  22. package/lib/cli/commands/mapping-file/create.spec.d.ts +0 -1
  23. package/lib/cli/commands/mapping-file/index.d.ts +0 -2
  24. package/lib/cli/commands/mapping-file/index.js +0 -57
  25. package/lib/cli/commands/mapping-file/upload.d.ts +0 -3
  26. package/lib/cli/commands/mapping-file/upload.js +0 -70
  27. package/lib/cli/commands/shared/git.d.ts +0 -6
  28. package/lib/cli/commands/shared/git.js +0 -100
  29. package/lib/cli/commands/shared/prompts.d.ts +0 -2
  30. package/lib/cli/commands/shared/prompts.js +0 -61
  31. package/lib/cli/commands/shared/upload-base.d.ts +0 -24
  32. package/lib/cli/commands/shared/upload-base.js +0 -138
  33. package/lib/cli/commands/shared/upload-base.spec.d.ts +0 -1
  34. package/lib/cli/commands/shared/upload-base.spec.js +0 -99
  35. package/lib/cli/template/config-template.json.template +0 -5
  36. /package/lib/cli/commands/{mapping-file/compile.d.ts → compile.d.ts} +0 -0
  37. /package/lib/cli/commands/{mapping-file/compile.js → compile.js} +0 -0
  38. /package/lib/cli/commands/{mapping-file/compile.spec.d.ts → compile.spec.d.ts} +0 -0
  39. /package/lib/cli/commands/{mapping-file/compile.spec.js → compile.spec.js} +0 -0
  40. /package/lib/cli/commands/{config-file/create.spec.d.ts → create.spec.d.ts} +0 -0
  41. /package/lib/cli/commands/{config-file/upload.spec.d.ts → upload.spec.d.ts} +0 -0
@@ -1,138 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.runUpload = exports.parseUploadArgs = void 0;
27
- const fs = __importStar(require("fs"));
28
- const path = __importStar(require("path"));
29
- const sdk_1 = require("@contrail/sdk");
30
- const prompts_1 = require("./prompts");
31
- const git_1 = require("./git");
32
- function parseUploadArgs(args, sourceLabel) {
33
- let filePath;
34
- let message;
35
- let branch;
36
- let skipGit = false;
37
- let updateConfig = false;
38
- for (let i = 0; i < args.length; i++) {
39
- const a = args[i];
40
- if (a === '-m') {
41
- message = args[++i];
42
- if (message === undefined) {
43
- throw new Error('-m requires a commit message argument');
44
- }
45
- }
46
- else if (a === '-b') {
47
- branch = args[++i];
48
- if (branch === undefined) {
49
- throw new Error('-b requires a branch name argument');
50
- }
51
- }
52
- else if (a === '--skip-git' || a === '--skipGit') {
53
- skipGit = true;
54
- }
55
- else if (a === '--update-config') {
56
- updateConfig = true;
57
- }
58
- else if (a.startsWith('-')) {
59
- throw new Error(`Unknown option: ${a}`);
60
- }
61
- else if (!filePath) {
62
- filePath = a;
63
- }
64
- else {
65
- throw new Error(`Unexpected argument: ${a}`);
66
- }
67
- }
68
- if (!filePath) {
69
- throw new Error(`upload: missing <${sourceLabel}> argument`);
70
- }
71
- return { filePath, message, branch, skipGit, updateConfig };
72
- }
73
- exports.parseUploadArgs = parseUploadArgs;
74
- async function runUpload(strategy, args) {
75
- const sourceLabel = `path${strategy.sourceExtension}`;
76
- const options = parseUploadArgs(args, sourceLabel);
77
- const absSourcePath = path.resolve(process.cwd(), options.filePath);
78
- if (!fs.existsSync(absSourcePath)) {
79
- throw new Error(`File not found: ${absSourcePath}`);
80
- }
81
- if (!absSourcePath.endsWith(strategy.sourceExtension)) {
82
- throw new Error(`Expected a ${strategy.sourceExtension} file, got: ${absSourcePath}`);
83
- }
84
- const prepared = await strategy.prepare(absSourcePath);
85
- let email = process.env.CONTRAIL_CLI_EMAIL;
86
- let password = process.env.CONTRAIL_CLI_PASSWORD;
87
- if (!email) {
88
- email = await (0, prompts_1.prompt)('Email: ');
89
- }
90
- if (!password) {
91
- password = await (0, prompts_1.promptHidden)('Password: ');
92
- }
93
- if (!email || !password) {
94
- throw new Error('Email and password are required');
95
- }
96
- await (0, sdk_1.login)({ orgSlug: prepared.orgName, email, password });
97
- console.log(`Logged in to org "${prepared.orgName}" as ${email}`);
98
- const apps = await new sdk_1.Entities().get({
99
- entityName: 'app',
100
- criteria: { identifier: prepared.appIdentifier },
101
- });
102
- if (!apps || apps.length !== 1) {
103
- throw new Error(`Expected exactly one app with identifier "${prepared.appIdentifier}" in org "${prepared.orgName}", found ${apps ? apps.length : 0}`);
104
- }
105
- const app = apps[0];
106
- const fileOwner = `app:${app.id}`;
107
- const uploadedFile = await new sdk_1.Files().createAndUploadFileFromBuffer(prepared.uploadBuffer, prepared.uploadContentType, prepared.uploadFileName, fileOwner);
108
- const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
109
- const responsePath = `${absSourcePath}.uploaded-${timestamp}.json`;
110
- fs.writeFileSync(responsePath, JSON.stringify(uploadedFile, null, 2), 'utf8');
111
- console.log(`Wrote response to ${responsePath}`);
112
- console.log(`FILE ID: ${uploadedFile.id}`);
113
- if (options.updateConfig) {
114
- const appOrgs = await new sdk_1.Entities().get({
115
- entityName: 'app-org',
116
- criteria: { appId: app.id },
117
- });
118
- if (!appOrgs || appOrgs.length === 0) {
119
- throw new Error(`App "${prepared.appIdentifier}" is not installed in org "${prepared.orgName}". Install it via the admin console before using --update-config.`);
120
- }
121
- if (appOrgs.length > 1) {
122
- throw new Error(`Expected exactly one app-org for app "${prepared.appIdentifier}" in org "${prepared.orgName}", found ${appOrgs.length}`);
123
- }
124
- const appOrg = appOrgs[0];
125
- const nextAppConfig = { ...(appOrg.appConfig || {}), [prepared.configPropertyName]: uploadedFile.id };
126
- await new sdk_1.Entities().update({
127
- entityName: 'app-org',
128
- id: appOrg.id,
129
- object: { appConfig: nextAppConfig },
130
- });
131
- console.log(`Updated app-org ${appOrg.id}: appConfig.${prepared.configPropertyName} = ${uploadedFile.id}`);
132
- }
133
- if (options.skipGit) {
134
- return;
135
- }
136
- await (0, git_1.commitFiles)(prepared.filesToCommit, uploadedFile.id, options);
137
- }
138
- exports.runUpload = runUpload;
@@ -1 +0,0 @@
1
- export {};
@@ -1,99 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- jest.mock('@contrail/sdk', () => ({
4
- Entities: jest.fn(),
5
- Files: jest.fn(),
6
- login: jest.fn(),
7
- }));
8
- const upload_base_1 = require("./upload-base");
9
- const git_1 = require("./git");
10
- describe('parseUploadArgs', () => {
11
- it('parses a bare file path', () => {
12
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts'], 'path.ts');
13
- expect(opts).toEqual({
14
- filePath: 'mapping.ts',
15
- message: undefined,
16
- branch: undefined,
17
- skipGit: false,
18
- updateConfig: false,
19
- });
20
- });
21
- it('parses -m commit message option', () => {
22
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '-m', 'my message'], 'path.ts');
23
- expect(opts.message).toEqual('my message');
24
- expect(opts.skipGit).toBe(false);
25
- });
26
- it('parses -b branch option', () => {
27
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '-b', 'feature/x'], 'path.ts');
28
- expect(opts.branch).toEqual('feature/x');
29
- });
30
- it('parses --skip-git flag', () => {
31
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '--skip-git'], 'path.ts');
32
- expect(opts.skipGit).toBe(true);
33
- });
34
- it('accepts the legacy --skipGit alias', () => {
35
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '--skipGit'], 'path.ts');
36
- expect(opts.skipGit).toBe(true);
37
- });
38
- it('parses --update-config flag', () => {
39
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '--update-config'], 'path.ts');
40
- expect(opts.updateConfig).toBe(true);
41
- });
42
- it('parses options before the file path', () => {
43
- const opts = (0, upload_base_1.parseUploadArgs)(['-m', 'msg', '-b', 'br', 'mapping.ts'], 'path.ts');
44
- expect(opts).toEqual({
45
- filePath: 'mapping.ts',
46
- message: 'msg',
47
- branch: 'br',
48
- skipGit: false,
49
- updateConfig: false,
50
- });
51
- });
52
- it('parses all options together', () => {
53
- const opts = (0, upload_base_1.parseUploadArgs)(['mapping.ts', '-m', 'msg', '-b', 'br', '--skip-git', '--update-config'], 'path.ts');
54
- expect(opts).toEqual({
55
- filePath: 'mapping.ts',
56
- message: 'msg',
57
- branch: 'br',
58
- skipGit: true,
59
- updateConfig: true,
60
- });
61
- });
62
- it('throws when -m is missing its value', () => {
63
- expect(() => (0, upload_base_1.parseUploadArgs)(['mapping.ts', '-m'], 'path.ts')).toThrow(/-m requires a commit message/);
64
- });
65
- it('throws when -b is missing its value', () => {
66
- expect(() => (0, upload_base_1.parseUploadArgs)(['mapping.ts', '-b'], 'path.ts')).toThrow(/-b requires a branch name/);
67
- });
68
- it('throws on unknown option', () => {
69
- expect(() => (0, upload_base_1.parseUploadArgs)(['mapping.ts', '--bogus'], 'path.ts')).toThrow(/Unknown option: --bogus/);
70
- });
71
- it('throws when an extra positional argument is supplied', () => {
72
- expect(() => (0, upload_base_1.parseUploadArgs)(['mapping.ts', 'extra.ts'], 'path.ts')).toThrow(/Unexpected argument: extra\.ts/);
73
- });
74
- it('throws when no file path is provided', () => {
75
- expect(() => (0, upload_base_1.parseUploadArgs)([], 'path.ts')).toThrow(/missing <path\.ts>/);
76
- });
77
- it('throws when only options are provided', () => {
78
- expect(() => (0, upload_base_1.parseUploadArgs)(['--skip-git'], 'path.ts')).toThrow(/missing <path\.ts>/);
79
- });
80
- it('uses the supplied source label in the missing-argument error', () => {
81
- expect(() => (0, upload_base_1.parseUploadArgs)([], 'path.json')).toThrow(/missing <path\.json>/);
82
- });
83
- });
84
- describe('buildCommitMessage', () => {
85
- it('appends fileId to the first line of a single-line message', () => {
86
- expect((0, git_1.buildCommitMessage)('initial commit', 'abc123')).toEqual('initial commit [fileId: abc123]');
87
- });
88
- it('only appends fileId to the first line of a multi-line message', () => {
89
- const result = (0, git_1.buildCommitMessage)('header line\nbody line 1\nbody line 2', 'xyz');
90
- expect(result).toEqual('header line [fileId: xyz]\nbody line 1\nbody line 2');
91
- });
92
- it('handles CRLF line endings', () => {
93
- const result = (0, git_1.buildCommitMessage)('header\r\nbody', 'fid');
94
- expect(result).toEqual('header [fileId: fid]\nbody');
95
- });
96
- it('handles an empty message', () => {
97
- expect((0, git_1.buildCommitMessage)('', 'fid')).toEqual(' [fileId: fid]');
98
- });
99
- });
@@ -1,5 +0,0 @@
1
- {
2
- "orgName": "<ORG_NAME>",
3
- "appIdentifier": "@vibeiq/flexplm-connector",
4
- "config": {}
5
- }