@contrail/flexplm 1.3.0-alpha.ccc03be → 1.3.1-alpha.3507ab6
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/commands/compile.d.ts +1 -0
- package/lib/cli/commands/compile.js +71 -0
- package/lib/cli/commands/compile.spec.d.ts +1 -0
- package/lib/cli/commands/compile.spec.js +80 -0
- package/lib/cli/commands/create.d.ts +1 -0
- package/lib/cli/commands/create.js +75 -0
- package/lib/cli/commands/create.spec.d.ts +1 -0
- package/lib/cli/commands/create.spec.js +78 -0
- package/lib/cli/commands/upload.d.ts +10 -0
- package/lib/cli/commands/upload.js +228 -0
- package/lib/cli/commands/upload.spec.d.ts +1 -0
- package/lib/cli/commands/upload.spec.js +88 -0
- package/lib/cli/index.d.ts +2 -0
- package/lib/cli/index.js +64 -0
- package/lib/cli/index.spec.d.ts +1 -0
- package/lib/cli/index.spec.js +79 -0
- package/lib/cli/template/mapping-template.ts.template +62 -0
- package/lib/entity-processor/base-entity-processor.d.ts +47 -0
- package/lib/entity-processor/base-entity-processor.js +53 -0
- package/lib/entity-processor/base-entity-processor.spec.js +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/interfaces/mapping-file.d.ts +460 -0
- package/lib/interfaces/mapping-file.js +2 -0
- package/lib/publish/base-process-publish-assortment.d.ts +25 -0
- package/lib/publish/base-process-publish-assortment.js +60 -6
- package/lib/publish/base-process-publish-assortment.spec.js +22 -4
- package/lib/publish/mockData.js +5 -0
- package/lib/transform/identifier-conversion-spec-mockData.js +34 -6
- package/lib/transform/identifier-conversion.d.ts +36 -0
- package/lib/transform/identifier-conversion.js +36 -0
- package/lib/transform/identifier-conversion.spec.js +4 -0
- package/lib/util/config-defaults.js +3 -0
- package/lib/util/config-defaults.spec.js +9 -0
- package/lib/util/data-converter-spec-mockData.js +17 -3
- package/lib/util/data-converter.d.ts +97 -0
- package/lib/util/data-converter.js +127 -1
- package/lib/util/data-converter.spec.js +2 -0
- package/lib/util/error-response-object.d.ts +5 -0
- package/lib/util/error-response-object.js +7 -0
- package/lib/util/event-short-message-status.js +1 -0
- package/lib/util/federation.js +8 -0
- package/lib/util/flexplm-connect.d.ts +7 -0
- package/lib/util/flexplm-connect.js +14 -0
- package/lib/util/logger-config.js +1 -0
- package/lib/util/map-util-spec-mockData.js +17 -3
- package/lib/util/map-utils.d.ts +27 -0
- package/lib/util/map-utils.js +27 -0
- package/lib/util/thumbnail-util.d.ts +21 -0
- package/lib/util/thumbnail-util.js +28 -1
- package/lib/util/thumbnail-util.spec.js +6 -0
- package/lib/util/type-conversion-utils-spec-mockData.js +3 -3
- package/lib/util/type-conversion-utils.d.ts +140 -0
- package/lib/util/type-conversion-utils.js +143 -0
- package/lib/util/type-defaults.d.ts +58 -0
- package/lib/util/type-defaults.js +58 -0
- package/lib/util/type-defaults.spec.js +5 -5
- package/lib/util/type-utils.d.ts +21 -0
- package/lib/util/type-utils.js +23 -0
- package/lib/util/type-utils.spec.js +2 -0
- package/package.json +21 -6
- package/scripts/copy-template.js +10 -0
- package/.github/pull_request_template.md +0 -31
- package/.github/workflows/flexplm-lib.yml +0 -27
- package/.github/workflows/publish-to-npm.yml +0 -121
- package/CHANGELOG.md +0 -32
- package/publish.bat +0 -5
- package/publish.sh +0 -5
- package/src/entity-processor/base-entity-processor.spec.ts +0 -460
- package/src/entity-processor/base-entity-processor.ts +0 -515
- package/src/flexplm-request.ts +0 -28
- package/src/flexplm-utils.spec.ts +0 -27
- package/src/flexplm-utils.ts +0 -29
- package/src/index.ts +0 -22
- package/src/interfaces/interfaces.ts +0 -122
- package/src/interfaces/item-family-changes.ts +0 -67
- package/src/interfaces/publish-change-data.ts +0 -43
- package/src/publish/base-process-publish-assortment-callback.ts +0 -50
- package/src/publish/base-process-publish-assortment.spec.ts +0 -1992
- package/src/publish/base-process-publish-assortment.ts +0 -1134
- package/src/publish/mockData.ts +0 -4561
- package/src/transform/identifier-conversion-spec-mockData.ts +0 -496
- package/src/transform/identifier-conversion.spec.ts +0 -354
- package/src/transform/identifier-conversion.ts +0 -282
- package/src/util/config-defaults.spec.ts +0 -350
- package/src/util/config-defaults.ts +0 -93
- package/src/util/data-converter-spec-mockData.ts +0 -231
- package/src/util/data-converter.spec.ts +0 -1041
- package/src/util/data-converter.ts +0 -762
- package/src/util/error-response-object.spec.ts +0 -116
- package/src/util/error-response-object.ts +0 -50
- package/src/util/event-short-message-status.ts +0 -22
- package/src/util/federation.ts +0 -172
- package/src/util/flexplm-connect.spec.ts +0 -132
- package/src/util/flexplm-connect.ts +0 -208
- package/src/util/logger-config.ts +0 -20
- package/src/util/map-util-spec-mockData.ts +0 -231
- package/src/util/map-utils.spec.ts +0 -103
- package/src/util/map-utils.ts +0 -41
- package/src/util/mockData.ts +0 -101
- package/src/util/thumbnail-util.spec.ts +0 -508
- package/src/util/thumbnail-util.ts +0 -272
- package/src/util/type-conversion-utils-spec-mockData.ts +0 -271
- package/src/util/type-conversion-utils.spec.ts +0 -968
- package/src/util/type-conversion-utils.ts +0 -460
- package/src/util/type-defaults.spec.ts +0 -669
- package/src/util/type-defaults.ts +0 -281
- package/src/util/type-utils.spec.ts +0 -227
- package/src/util/type-utils.ts +0 -144
- package/tsconfig.json +0 -24
- package/tslint.json +0 -57
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCompile(tsPath: string): Promise<void>;
|
|
@@ -0,0 +1,71 @@
|
|
|
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.runCompile = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
function loadTypescript() {
|
|
30
|
+
try {
|
|
31
|
+
return require('typescript');
|
|
32
|
+
}
|
|
33
|
+
catch (e) {
|
|
34
|
+
throw new Error('compile requires the "typescript" package. Install it in your project: npm install --save-dev typescript');
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
async function runCompile(tsPath) {
|
|
38
|
+
const absPath = path.resolve(process.cwd(), tsPath);
|
|
39
|
+
if (!fs.existsSync(absPath)) {
|
|
40
|
+
throw new Error(`File not found: ${absPath}`);
|
|
41
|
+
}
|
|
42
|
+
if (!absPath.endsWith('.ts')) {
|
|
43
|
+
throw new Error(`Expected a .ts file, got: ${absPath}`);
|
|
44
|
+
}
|
|
45
|
+
const ts = loadTypescript();
|
|
46
|
+
const source = fs.readFileSync(absPath, 'utf8');
|
|
47
|
+
const result = ts.transpileModule(source, {
|
|
48
|
+
fileName: path.basename(absPath),
|
|
49
|
+
compilerOptions: {
|
|
50
|
+
module: ts.ModuleKind.CommonJS,
|
|
51
|
+
target: ts.ScriptTarget.ES2020,
|
|
52
|
+
esModuleInterop: true,
|
|
53
|
+
},
|
|
54
|
+
reportDiagnostics: true,
|
|
55
|
+
});
|
|
56
|
+
const diagnostics = result.diagnostics || [];
|
|
57
|
+
if (diagnostics.length > 0) {
|
|
58
|
+
const formatHost = {
|
|
59
|
+
getCanonicalFileName: (f) => f,
|
|
60
|
+
getCurrentDirectory: () => process.cwd(),
|
|
61
|
+
getNewLine: () => '\n',
|
|
62
|
+
};
|
|
63
|
+
const formatted = ts.formatDiagnosticsWithColorAndContext(diagnostics, formatHost);
|
|
64
|
+
process.stderr.write(formatted);
|
|
65
|
+
throw new Error(`Compile failed: ${diagnostics.length} diagnostic(s)`);
|
|
66
|
+
}
|
|
67
|
+
const outPath = absPath.replace(/\.ts$/, '.js');
|
|
68
|
+
fs.writeFileSync(outPath, result.outputText, 'utf8');
|
|
69
|
+
console.log(`Compiled ${outPath}`);
|
|
70
|
+
}
|
|
71
|
+
exports.runCompile = runCompile;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
const fs = __importStar(require("fs"));
|
|
27
|
+
const os = __importStar(require("os"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const compile_1 = require("./compile");
|
|
30
|
+
describe('runCompile', () => {
|
|
31
|
+
let tempDir;
|
|
32
|
+
let originalCwd;
|
|
33
|
+
let logSpy;
|
|
34
|
+
let stderrSpy;
|
|
35
|
+
beforeEach(() => {
|
|
36
|
+
originalCwd = process.cwd();
|
|
37
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flexplm-compile-'));
|
|
38
|
+
process.chdir(tempDir);
|
|
39
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
40
|
+
stderrSpy = jest.spyOn(process.stderr, 'write').mockImplementation(() => true);
|
|
41
|
+
});
|
|
42
|
+
afterEach(() => {
|
|
43
|
+
logSpy.mockRestore();
|
|
44
|
+
stderrSpy.mockRestore();
|
|
45
|
+
process.chdir(originalCwd);
|
|
46
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
47
|
+
});
|
|
48
|
+
it('transpiles a .ts file to a sibling .js file', async () => {
|
|
49
|
+
const tsPath = path.join(tempDir, 'mapping.ts');
|
|
50
|
+
fs.writeFileSync(tsPath, `export const mapping = { orgName: 'acme' };\n`, 'utf8');
|
|
51
|
+
await (0, compile_1.runCompile)('mapping.ts');
|
|
52
|
+
const jsPath = path.join(tempDir, 'mapping.js');
|
|
53
|
+
expect(fs.existsSync(jsPath)).toBe(true);
|
|
54
|
+
const js = fs.readFileSync(jsPath, 'utf8');
|
|
55
|
+
expect(js).toContain('exports.mapping');
|
|
56
|
+
expect(js).toContain("orgName: 'acme'");
|
|
57
|
+
});
|
|
58
|
+
it('resolves the input path relative to cwd', async () => {
|
|
59
|
+
const subdir = path.join(tempDir, 'nested');
|
|
60
|
+
fs.mkdirSync(subdir);
|
|
61
|
+
const tsPath = path.join(subdir, 'm.ts');
|
|
62
|
+
fs.writeFileSync(tsPath, 'export const x = 1;\n', 'utf8');
|
|
63
|
+
await (0, compile_1.runCompile)('nested/m.ts');
|
|
64
|
+
expect(fs.existsSync(path.join(subdir, 'm.js'))).toBe(true);
|
|
65
|
+
});
|
|
66
|
+
it('throws when the input file does not exist', async () => {
|
|
67
|
+
await expect((0, compile_1.runCompile)('nope.ts')).rejects.toThrow(/File not found/);
|
|
68
|
+
});
|
|
69
|
+
it('throws when the input is not a .ts file', async () => {
|
|
70
|
+
const jsPath = path.join(tempDir, 'mapping.js');
|
|
71
|
+
fs.writeFileSync(jsPath, 'module.exports = {};', 'utf8');
|
|
72
|
+
await expect((0, compile_1.runCompile)('mapping.js')).rejects.toThrow(/Expected a \.ts file/);
|
|
73
|
+
});
|
|
74
|
+
it('throws on a TypeScript syntax error', async () => {
|
|
75
|
+
const tsPath = path.join(tempDir, 'broken.ts');
|
|
76
|
+
fs.writeFileSync(tsPath, 'export const = ;\n', 'utf8');
|
|
77
|
+
await expect((0, compile_1.runCompile)('broken.ts')).rejects.toThrow(/Compile failed/);
|
|
78
|
+
expect(fs.existsSync(path.join(tempDir, 'broken.js'))).toBe(false);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCreate(): Promise<void>;
|
|
@@ -0,0 +1,75 @@
|
|
|
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.runCreate = void 0;
|
|
27
|
+
const fs = __importStar(require("fs"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
const readline = __importStar(require("readline"));
|
|
30
|
+
const TEMPLATE_FILENAME = 'mapping-template.ts.template';
|
|
31
|
+
const PLACEHOLDER = '<ORG_NAME>';
|
|
32
|
+
function prompt(question) {
|
|
33
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
34
|
+
const onSigint = () => {
|
|
35
|
+
rl.close();
|
|
36
|
+
process.stdout.write('\n');
|
|
37
|
+
process.exit(130);
|
|
38
|
+
};
|
|
39
|
+
process.once('SIGINT', onSigint);
|
|
40
|
+
return new Promise((resolve) => {
|
|
41
|
+
rl.question(question, (answer) => {
|
|
42
|
+
process.removeListener('SIGINT', onSigint);
|
|
43
|
+
rl.close();
|
|
44
|
+
resolve(answer);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function findTemplate() {
|
|
49
|
+
const candidates = [
|
|
50
|
+
path.join(__dirname, '..', 'template', TEMPLATE_FILENAME),
|
|
51
|
+
path.join(__dirname, '..', '..', '..', 'src', 'cli', 'template', TEMPLATE_FILENAME),
|
|
52
|
+
];
|
|
53
|
+
for (const candidate of candidates) {
|
|
54
|
+
if (fs.existsSync(candidate)) {
|
|
55
|
+
return candidate;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
throw new Error(`Could not locate ${TEMPLATE_FILENAME}. Tried:\n ${candidates.join('\n ')}`);
|
|
59
|
+
}
|
|
60
|
+
async function runCreate() {
|
|
61
|
+
const orgName = (await prompt('orgName: ')).trim();
|
|
62
|
+
if (!orgName) {
|
|
63
|
+
throw new Error('orgName is required');
|
|
64
|
+
}
|
|
65
|
+
const templatePath = findTemplate();
|
|
66
|
+
const templateBody = fs.readFileSync(templatePath, 'utf8');
|
|
67
|
+
const rendered = templateBody.split(PLACEHOLDER).join(orgName);
|
|
68
|
+
const outPath = path.resolve(process.cwd(), `${orgName}-transformMapping.ts`);
|
|
69
|
+
if (fs.existsSync(outPath)) {
|
|
70
|
+
throw new Error(`Refusing to overwrite existing file: ${outPath}`);
|
|
71
|
+
}
|
|
72
|
+
fs.writeFileSync(outPath, rendered, 'utf8');
|
|
73
|
+
console.log(`Created ${outPath}`);
|
|
74
|
+
}
|
|
75
|
+
exports.runCreate = runCreate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,78 @@
|
|
|
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
|
+
const fs = __importStar(require("fs"));
|
|
27
|
+
const os = __importStar(require("os"));
|
|
28
|
+
const path = __importStar(require("path"));
|
|
29
|
+
let nextAnswer = '';
|
|
30
|
+
jest.mock('readline', () => ({
|
|
31
|
+
createInterface: () => ({
|
|
32
|
+
question: (_q, cb) => cb(nextAnswer),
|
|
33
|
+
close: () => { },
|
|
34
|
+
}),
|
|
35
|
+
}));
|
|
36
|
+
const create_1 = require("./create");
|
|
37
|
+
describe('runCreate', () => {
|
|
38
|
+
let tempDir;
|
|
39
|
+
let originalCwd;
|
|
40
|
+
let logSpy;
|
|
41
|
+
beforeEach(() => {
|
|
42
|
+
originalCwd = process.cwd();
|
|
43
|
+
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'flexplm-create-'));
|
|
44
|
+
process.chdir(tempDir);
|
|
45
|
+
logSpy = jest.spyOn(console, 'log').mockImplementation(() => { });
|
|
46
|
+
nextAnswer = '';
|
|
47
|
+
});
|
|
48
|
+
afterEach(() => {
|
|
49
|
+
logSpy.mockRestore();
|
|
50
|
+
process.chdir(originalCwd);
|
|
51
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
52
|
+
});
|
|
53
|
+
it('writes <orgName>-transformMapping.ts with the placeholder replaced', async () => {
|
|
54
|
+
nextAnswer = 'acme';
|
|
55
|
+
await (0, create_1.runCreate)();
|
|
56
|
+
const outPath = path.join(tempDir, 'acme-transformMapping.ts');
|
|
57
|
+
expect(fs.existsSync(outPath)).toBe(true);
|
|
58
|
+
const contents = fs.readFileSync(outPath, 'utf8');
|
|
59
|
+
expect(contents).toContain("orgName: 'acme'");
|
|
60
|
+
expect(contents).not.toContain('<ORG_NAME>');
|
|
61
|
+
});
|
|
62
|
+
it('trims whitespace around the orgName input', async () => {
|
|
63
|
+
nextAnswer = ' acme ';
|
|
64
|
+
await (0, create_1.runCreate)();
|
|
65
|
+
expect(fs.existsSync(path.join(tempDir, 'acme-transformMapping.ts'))).toBe(true);
|
|
66
|
+
});
|
|
67
|
+
it('throws when orgName is empty', async () => {
|
|
68
|
+
nextAnswer = ' ';
|
|
69
|
+
await expect((0, create_1.runCreate)()).rejects.toThrow(/orgName is required/);
|
|
70
|
+
});
|
|
71
|
+
it('refuses to overwrite an existing file', async () => {
|
|
72
|
+
const existing = path.join(tempDir, 'acme-transformMapping.ts');
|
|
73
|
+
fs.writeFileSync(existing, 'do not clobber', 'utf8');
|
|
74
|
+
nextAnswer = 'acme';
|
|
75
|
+
await expect((0, create_1.runCreate)()).rejects.toThrow(/Refusing to overwrite/);
|
|
76
|
+
expect(fs.readFileSync(existing, 'utf8')).toEqual('do not clobber');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
interface UploadOptions {
|
|
2
|
+
filePath: string;
|
|
3
|
+
message?: string;
|
|
4
|
+
branch?: string;
|
|
5
|
+
skipGit: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseUploadArgs(args: string[]): UploadOptions;
|
|
8
|
+
export declare function buildCommitMessage(userMessage: string, fileId: string): string;
|
|
9
|
+
export declare function runUpload(args: string[]): Promise<void>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,228 @@
|
|
|
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.buildCommitMessage = exports.parseUploadArgs = void 0;
|
|
27
|
+
const child_process_1 = require("child_process");
|
|
28
|
+
const fs = __importStar(require("fs"));
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const readline = __importStar(require("readline"));
|
|
31
|
+
const sdk_1 = require("@contrail/sdk");
|
|
32
|
+
const compile_1 = require("./compile");
|
|
33
|
+
function prompt(question) {
|
|
34
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
35
|
+
return new Promise((resolve) => {
|
|
36
|
+
rl.question(question, (answer) => {
|
|
37
|
+
rl.close();
|
|
38
|
+
resolve(answer.trim());
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function promptHidden(question) {
|
|
43
|
+
return new Promise((resolve) => {
|
|
44
|
+
const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: true });
|
|
45
|
+
const rlAny = rl;
|
|
46
|
+
rlAny._writeToOutput = (str) => {
|
|
47
|
+
if (str.includes(question)) {
|
|
48
|
+
rlAny.output.write(str);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
rl.question(question, (answer) => {
|
|
52
|
+
rl.close();
|
|
53
|
+
process.stdout.write('\n');
|
|
54
|
+
resolve(answer);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function parseUploadArgs(args) {
|
|
59
|
+
let filePath;
|
|
60
|
+
let message;
|
|
61
|
+
let branch;
|
|
62
|
+
let skipGit = false;
|
|
63
|
+
for (let i = 0; i < args.length; i++) {
|
|
64
|
+
const a = args[i];
|
|
65
|
+
if (a === '-m') {
|
|
66
|
+
message = args[++i];
|
|
67
|
+
if (message === undefined) {
|
|
68
|
+
throw new Error('-m requires a commit message argument');
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
else if (a === '-b') {
|
|
72
|
+
branch = args[++i];
|
|
73
|
+
if (branch === undefined) {
|
|
74
|
+
throw new Error('-b requires a branch name argument');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
else if (a === '--skip-git' || a === '--skipGit') {
|
|
78
|
+
skipGit = true;
|
|
79
|
+
}
|
|
80
|
+
else if (a.startsWith('-')) {
|
|
81
|
+
throw new Error(`Unknown option: ${a}`);
|
|
82
|
+
}
|
|
83
|
+
else if (!filePath) {
|
|
84
|
+
filePath = a;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
throw new Error(`Unexpected argument: ${a}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!filePath) {
|
|
91
|
+
throw new Error('upload: missing <path.ts> argument');
|
|
92
|
+
}
|
|
93
|
+
return { filePath, message, branch, skipGit };
|
|
94
|
+
}
|
|
95
|
+
exports.parseUploadArgs = parseUploadArgs;
|
|
96
|
+
function runGit(args, cwd) {
|
|
97
|
+
return (0, child_process_1.execFileSync)('git', args, { cwd, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
|
|
98
|
+
}
|
|
99
|
+
function tryRunGit(args, cwd) {
|
|
100
|
+
try {
|
|
101
|
+
const stdout = runGit(args, cwd);
|
|
102
|
+
return { ok: true, stdout, stderr: '' };
|
|
103
|
+
}
|
|
104
|
+
catch (err) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
stdout: err && err.stdout ? err.stdout.toString() : '',
|
|
108
|
+
stderr: err && err.stderr ? err.stderr.toString() : (err && err.message) || '',
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
function buildCommitMessage(userMessage, fileId) {
|
|
113
|
+
const lines = userMessage.split(/\r?\n/);
|
|
114
|
+
lines[0] = `${lines[0]} [fileId: ${fileId}]`;
|
|
115
|
+
return lines.join('\n');
|
|
116
|
+
}
|
|
117
|
+
exports.buildCommitMessage = buildCommitMessage;
|
|
118
|
+
async function commitToGit(absPaths, fileId, options) {
|
|
119
|
+
const repoDir = path.dirname(absPaths[0]);
|
|
120
|
+
const relPaths = absPaths.map((p) => path.basename(p));
|
|
121
|
+
const versionCheck = tryRunGit(['--version'], repoDir);
|
|
122
|
+
if (!versionCheck.ok) {
|
|
123
|
+
console.log('git command not available; skipping git commit.');
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const insideRepo = tryRunGit(['rev-parse', '--is-inside-work-tree'], repoDir);
|
|
127
|
+
if (!insideRepo.ok || insideRepo.stdout.trim() !== 'true') {
|
|
128
|
+
console.log(`Not inside a git working tree (${repoDir}); skipping git commit.`);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
for (const relPath of relPaths) {
|
|
132
|
+
const tracked = tryRunGit(['ls-files', '--error-unmatch', relPath], repoDir);
|
|
133
|
+
if (!tracked.ok) {
|
|
134
|
+
const answer = (await prompt(`File is not tracked by git: ${relPath}\nAdd it to git? (Y/n): `)).toLowerCase();
|
|
135
|
+
if (answer === 'n' || answer === 'no') {
|
|
136
|
+
console.log('Nothing was done in git.');
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (options.branch) {
|
|
142
|
+
const branchResult = tryRunGit(['checkout', '-b', options.branch], repoDir);
|
|
143
|
+
if (!branchResult.ok) {
|
|
144
|
+
throw new Error(`Failed to create branch "${options.branch}": ${branchResult.stderr.trim()}`);
|
|
145
|
+
}
|
|
146
|
+
console.log(`Created and switched to branch "${options.branch}"`);
|
|
147
|
+
}
|
|
148
|
+
let message = options.message;
|
|
149
|
+
if (!message) {
|
|
150
|
+
message = await prompt('Commit message: ');
|
|
151
|
+
if (!message) {
|
|
152
|
+
throw new Error('A commit message is required');
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
const finalMessage = buildCommitMessage(message, fileId);
|
|
156
|
+
const addResult = tryRunGit(['add', '--', ...relPaths], repoDir);
|
|
157
|
+
if (!addResult.ok) {
|
|
158
|
+
throw new Error(`git add failed: ${addResult.stderr.trim()}`);
|
|
159
|
+
}
|
|
160
|
+
const commitResult = tryRunGit(['commit', '-m', finalMessage, '--', ...relPaths], repoDir);
|
|
161
|
+
if (!commitResult.ok) {
|
|
162
|
+
throw new Error(`git commit failed: ${commitResult.stderr.trim() || commitResult.stdout.trim()}`);
|
|
163
|
+
}
|
|
164
|
+
console.log(commitResult.stdout.trim());
|
|
165
|
+
}
|
|
166
|
+
async function runUpload(args) {
|
|
167
|
+
const options = parseUploadArgs(args);
|
|
168
|
+
const tsAbsPath = path.resolve(process.cwd(), options.filePath);
|
|
169
|
+
if (!fs.existsSync(tsAbsPath)) {
|
|
170
|
+
throw new Error(`File not found: ${tsAbsPath}`);
|
|
171
|
+
}
|
|
172
|
+
if (!tsAbsPath.endsWith('.ts')) {
|
|
173
|
+
throw new Error(`Expected a .ts file, got: ${tsAbsPath}`);
|
|
174
|
+
}
|
|
175
|
+
await (0, compile_1.runCompile)(tsAbsPath);
|
|
176
|
+
const absPath = tsAbsPath.replace(/\.ts$/, '.js');
|
|
177
|
+
if (!fs.existsSync(absPath)) {
|
|
178
|
+
throw new Error(`Compiled file not found: ${absPath}`);
|
|
179
|
+
}
|
|
180
|
+
let email = process.env.CONTRAIL_CLI_EMAIL;
|
|
181
|
+
let password = process.env.CONTRAIL_CLI_PASSWORD;
|
|
182
|
+
if (!email) {
|
|
183
|
+
email = await prompt('Email: ');
|
|
184
|
+
}
|
|
185
|
+
if (!password) {
|
|
186
|
+
password = await promptHidden('Password: ');
|
|
187
|
+
}
|
|
188
|
+
if (!email || !password) {
|
|
189
|
+
throw new Error('Email and password are required');
|
|
190
|
+
}
|
|
191
|
+
delete require.cache[absPath];
|
|
192
|
+
const loaded = require(absPath);
|
|
193
|
+
const mapping = loaded && loaded.mapping;
|
|
194
|
+
if (!mapping || !mapping.orgInfo) {
|
|
195
|
+
throw new Error(`Mapping file is missing "mapping.orgInfo" export: ${absPath}`);
|
|
196
|
+
}
|
|
197
|
+
const { orgName, appIdentifier } = mapping.orgInfo;
|
|
198
|
+
if (!orgName) {
|
|
199
|
+
throw new Error(`Mapping file is missing "mapping.orgInfo.orgName": ${absPath}`);
|
|
200
|
+
}
|
|
201
|
+
if (!appIdentifier) {
|
|
202
|
+
throw new Error(`Mapping file is missing "mapping.orgInfo.appIdentifier": ${absPath}`);
|
|
203
|
+
}
|
|
204
|
+
await (0, sdk_1.login)({ orgSlug: orgName, email, password });
|
|
205
|
+
console.log(`Logged in to org "${orgName}" as ${email}`);
|
|
206
|
+
const apps = await new sdk_1.Entities().get({
|
|
207
|
+
entityName: 'app',
|
|
208
|
+
criteria: { identifier: appIdentifier },
|
|
209
|
+
});
|
|
210
|
+
if (!apps || apps.length !== 1) {
|
|
211
|
+
throw new Error(`Expected exactly one app with identifier "${appIdentifier}" in org "${orgName}", found ${apps ? apps.length : 0}`);
|
|
212
|
+
}
|
|
213
|
+
const app = apps[0];
|
|
214
|
+
const buffer = fs.readFileSync(absPath);
|
|
215
|
+
const fileName = path.basename(absPath);
|
|
216
|
+
const fileOwner = `app:${app.id}`;
|
|
217
|
+
const uploadedFile = await new sdk_1.Files().createAndUploadFileFromBuffer(buffer, 'application/javascript', fileName, fileOwner);
|
|
218
|
+
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
|
|
219
|
+
const responsePath = `${absPath}.uploaded-${timestamp}.json`;
|
|
220
|
+
fs.writeFileSync(responsePath, JSON.stringify(uploadedFile, null, 2), 'utf8');
|
|
221
|
+
console.log(`Wrote response to ${responsePath}`);
|
|
222
|
+
console.log(`FILE ID: ${uploadedFile.id}`);
|
|
223
|
+
if (options.skipGit) {
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
await commitToGit([tsAbsPath, absPath], uploadedFile.id, options);
|
|
227
|
+
}
|
|
228
|
+
exports.runUpload = runUpload;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
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_1 = require("./upload");
|
|
9
|
+
describe('parseUploadArgs', () => {
|
|
10
|
+
it('parses a bare file path', () => {
|
|
11
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts']);
|
|
12
|
+
expect(opts).toEqual({
|
|
13
|
+
filePath: 'mapping.ts',
|
|
14
|
+
message: undefined,
|
|
15
|
+
branch: undefined,
|
|
16
|
+
skipGit: false,
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
it('parses -m commit message option', () => {
|
|
20
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts', '-m', 'my message']);
|
|
21
|
+
expect(opts.message).toEqual('my message');
|
|
22
|
+
expect(opts.skipGit).toBe(false);
|
|
23
|
+
});
|
|
24
|
+
it('parses -b branch option', () => {
|
|
25
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts', '-b', 'feature/x']);
|
|
26
|
+
expect(opts.branch).toEqual('feature/x');
|
|
27
|
+
});
|
|
28
|
+
it('parses --skip-git flag', () => {
|
|
29
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts', '--skip-git']);
|
|
30
|
+
expect(opts.skipGit).toBe(true);
|
|
31
|
+
});
|
|
32
|
+
it('accepts the legacy --skipGit alias', () => {
|
|
33
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts', '--skipGit']);
|
|
34
|
+
expect(opts.skipGit).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
it('parses options before the file path', () => {
|
|
37
|
+
const opts = (0, upload_1.parseUploadArgs)(['-m', 'msg', '-b', 'br', 'mapping.ts']);
|
|
38
|
+
expect(opts).toEqual({
|
|
39
|
+
filePath: 'mapping.ts',
|
|
40
|
+
message: 'msg',
|
|
41
|
+
branch: 'br',
|
|
42
|
+
skipGit: false,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
it('parses all options together', () => {
|
|
46
|
+
const opts = (0, upload_1.parseUploadArgs)(['mapping.ts', '-m', 'msg', '-b', 'br', '--skip-git']);
|
|
47
|
+
expect(opts).toEqual({
|
|
48
|
+
filePath: 'mapping.ts',
|
|
49
|
+
message: 'msg',
|
|
50
|
+
branch: 'br',
|
|
51
|
+
skipGit: true,
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
it('throws when -m is missing its value', () => {
|
|
55
|
+
expect(() => (0, upload_1.parseUploadArgs)(['mapping.ts', '-m'])).toThrow(/-m requires a commit message/);
|
|
56
|
+
});
|
|
57
|
+
it('throws when -b is missing its value', () => {
|
|
58
|
+
expect(() => (0, upload_1.parseUploadArgs)(['mapping.ts', '-b'])).toThrow(/-b requires a branch name/);
|
|
59
|
+
});
|
|
60
|
+
it('throws on unknown option', () => {
|
|
61
|
+
expect(() => (0, upload_1.parseUploadArgs)(['mapping.ts', '--bogus'])).toThrow(/Unknown option: --bogus/);
|
|
62
|
+
});
|
|
63
|
+
it('throws when an extra positional argument is supplied', () => {
|
|
64
|
+
expect(() => (0, upload_1.parseUploadArgs)(['mapping.ts', 'extra.ts'])).toThrow(/Unexpected argument: extra\.ts/);
|
|
65
|
+
});
|
|
66
|
+
it('throws when no file path is provided', () => {
|
|
67
|
+
expect(() => (0, upload_1.parseUploadArgs)([])).toThrow(/missing <path\.ts>/);
|
|
68
|
+
});
|
|
69
|
+
it('throws when only options are provided', () => {
|
|
70
|
+
expect(() => (0, upload_1.parseUploadArgs)(['--skip-git'])).toThrow(/missing <path\.ts>/);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
describe('buildCommitMessage', () => {
|
|
74
|
+
it('appends fileId to the first line of a single-line message', () => {
|
|
75
|
+
expect((0, upload_1.buildCommitMessage)('initial commit', 'abc123')).toEqual('initial commit [fileId: abc123]');
|
|
76
|
+
});
|
|
77
|
+
it('only appends fileId to the first line of a multi-line message', () => {
|
|
78
|
+
const result = (0, upload_1.buildCommitMessage)('header line\nbody line 1\nbody line 2', 'xyz');
|
|
79
|
+
expect(result).toEqual('header line [fileId: xyz]\nbody line 1\nbody line 2');
|
|
80
|
+
});
|
|
81
|
+
it('handles CRLF line endings', () => {
|
|
82
|
+
const result = (0, upload_1.buildCommitMessage)('header\r\nbody', 'fid');
|
|
83
|
+
expect(result).toEqual('header [fileId: fid]\nbody');
|
|
84
|
+
});
|
|
85
|
+
it('handles an empty message', () => {
|
|
86
|
+
expect((0, upload_1.buildCommitMessage)('', 'fid')).toEqual(' [fileId: fid]');
|
|
87
|
+
});
|
|
88
|
+
});
|