Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@finos/calm-cli",
"version": "0.6.1",
"version": "0.6.2",
"description": "A set of tools for interacting with the Common Architecture Language Model (CALM)",
"main": "dist/index.js",
"files": [
Expand All @@ -13,7 +13,7 @@
"build": "tsup && npm run copy-calm-schema && npm run copy-docify-templates",
"watch": "node watch.mjs",
"copy-calm-schema": "copyfiles \"../calm/draft/2024-10/meta/*\" dist/calm/",
"copy-docify-templates": "copyfiles \"../shared/src/docify/template-bundles/**/*\" dist --up 4",
"copy-docify-templates": "copyfiles \"../shared/dist/template-bundles/**/*\" dist --up 3",
"test": "vitest run",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
Expand Down
7 changes: 3 additions & 4 deletions cli/src/cli.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as os from 'os';
import { parseStringPromise } from 'xml2js';
import util from 'util';
import axios from 'axios';

import { Mock } from 'vitest';
// Mock axios
vi.mock('axios');

Expand Down Expand Up @@ -189,7 +189,7 @@ describe('CLI Integration Tests', () => {


test('server command starts and responds to /health', async () => {
(axios.get as vi.Mock).mockResolvedValue({ status: 200, data: { status: 'ok' } });
(axios.get as Mock).mockResolvedValue({ status: 200, data: { status: 'ok' } });
const serverCmd = calm('server -p 3002 --schemaDirectory ../../dist/calm/');
const serverProcess = exec(serverCmd);

Expand Down Expand Up @@ -222,8 +222,7 @@ describe('CLI Integration Tests', () => {
expect(actualContent).toEqual(expectedContent);
});

//TODO: This simulates Issue 2 of https://github.com/finos/architecture-as-code/issues/1043. Remove skip once fixed.
test.skip('docify command generates expected files', async () => {
test('docify command generates expected files', async () => {
const fixtureDir = path.resolve(__dirname, '../test_fixtures/template');
const testModelPath = path.join(fixtureDir, 'model/document-system.json');
const localDirectory = path.join(fixtureDir, 'model/url-to-file-directory.json');
Expand Down
16 changes: 7 additions & 9 deletions cli/src/command-helpers/validate.spec.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { getFormattedOutput, validate, exitBasedOffOfValidationOutcome } from '@finos/calm-shared';
import { initLogger } from '@finos/calm-shared/logger';
import { initLogger } from '@finos/calm-shared';
import { mkdirp } from 'mkdirp';
import { writeFileSync } from 'fs';
import path from 'path';
import {runValidate, writeOutputFile, checkValidateOptions} from './validate';
import { Command } from 'commander';
import { Mock } from 'vitest';

vi.mock('@finos/calm-shared', async () => ({
...vi.importActual('@finos/calm-shared'),
validate: vi.fn(),
getFormattedOutput: vi.fn(),
exitBasedOffOfValidationOutcome: vi.fn(),
}));

vi.mock('@finos/calm-shared/logger', () => ({
initLogger: vi.fn(),
initLogger: vi.fn()
}));

vi.mock('mkdirp', () => ({
Expand Down Expand Up @@ -43,8 +41,8 @@ describe('runValidate', () => {
};

const fakeOutcome = { valid: true };
(validate as vi.Mock).mockResolvedValue(fakeOutcome);
(getFormattedOutput as vi.Mock).mockReturnValue('formatted output');
(validate as Mock).mockResolvedValue(fakeOutcome);
(getFormattedOutput as Mock).mockReturnValue('formatted output');

await runValidate(options);

Expand All @@ -69,9 +67,9 @@ describe('runValidate', () => {
};

const error = new Error('Validation failed');
(validate as vi.Mock).mockRejectedValue(error);
(validate as Mock).mockRejectedValue(error);
const loggerMock = { error: vi.fn(), debug: vi.fn() };
(initLogger as vi.Mock).mockReturnValue(loggerMock);
(initLogger as Mock).mockReturnValue(loggerMock);
const exitSpy = vi.spyOn(process, 'exit').mockImplementation((code?: number) => {
throw new Error(`process.exit called with ${code}`);
});
Expand Down
2 changes: 1 addition & 1 deletion cli/src/command-helpers/validate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { getFormattedOutput, validate, exitBasedOffOfValidationOutcome } from '@finos/calm-shared';
import { initLogger } from '@finos/calm-shared/logger';
import { initLogger } from '@finos/calm-shared';
import path from 'path';
import { mkdirp } from 'mkdirp';
import { writeFileSync } from 'fs';
Expand Down
1 change: 0 additions & 1 deletion cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#! /usr/bin/env node
import { program } from 'commander';
import { setupCLI } from './cli';

Expand Down
2 changes: 1 addition & 1 deletion cli/src/server/routes/validation-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';
import os from 'os';
import { v4 as uuidv4 } from 'uuid';
import winston from 'winston';
import { ValidationOutcome } from '@finos/calm-shared/commands/validate/validation.output';
import { ValidationOutcome } from '@finos/calm-shared';
import rateLimit from 'express-rate-limit';

export class ValidationRouter {
Expand Down
4 changes: 4 additions & 0 deletions cli/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.spec.ts"]
}
37 changes: 9 additions & 28 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
{
"extends": "../tsconfig.json",
"extends": "../tsconfig.base.json",
"module": "Preserve",
"moduleResolution": "bundler",
"compilerOptions": {
"outDir": "./dist",
"module": "CommonJS",
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
"moduleResolution": "node",
"types": [
"node",
"jest",
"../vitest/globals"
],
"typeRoots": [
"node_modules/@types",
"../node_modules/@types"
]
"outDir": "dist",
},
"references": [
{
"path": "../shared"
}
],
"include": [
"src/**/*",
"package.json"
"include": ["src", "../vitest-globals.d.ts"],
"lib": [
"esnext"
]
}

}
7 changes: 7 additions & 0 deletions cli/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@ export default defineConfig({
shims: true,
target: 'es2021',
treeshake: true,
banner: ({ format }) => {
if (format === 'cjs') {
return {
js: '#! /usr/bin/env node'
};
}
}
});
7 changes: 1 addition & 6 deletions cli/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {defineConfig} from 'vitest/config';
import path from 'path';
import {CoverageV8Options} from "vitest/node";

const v8CoverageSettings: CoverageV8Options = {
Expand All @@ -14,13 +13,9 @@ const v8CoverageSettings: CoverageV8Options = {
}

export default defineConfig({
resolve: {
alias: {
'@finos/calm-shared': path.resolve(__dirname, '../shared/src'),
}
},
test: {
globals: true,
environment: 'node',
coverage: {
provider: 'v8',
...v8CoverageSettings,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"calm-hub-ui:run": "npm run start --workspace calm-hub-ui"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.0.9",
"link": "^2.1.1",
"npm-run-all2": "^5.0.0",
"vitest": "^3.0.9",
"@vitest/coverage-v8": "^3.0.9"
"vitest": "^3.0.9"
},
"dependencies": {
"@finos/calm-shared": "^0.2.2"
Expand Down
15 changes: 8 additions & 7 deletions shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
],
"private": true,
"scripts": {
"build": "tsc",
"watch": "tsc -watch -p ./",
"clean": "rimraf dist tsconfig.tsbuildinfo",
"build": "tsup && tsc -p ./tsconfig.build.json && npm run copy:docify-template-bundle",
"copy:docify-template-bundle": "node scripts/copy-templates.mjs",
"watch": "tsc -watch -p ./tsconfig.build.json",
"clean": "rimraf dist tsconfig.build.tsbuildinfo",
"test": "vitest run",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
Expand All @@ -26,8 +27,8 @@
],
"author": "",
"license": "ISC",
"module": "commonjs",
"type": "commonjs",
"module": "esnext",
"type": "module",
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.9.3",
"@stoplight/spectral-cli": "^6.13.1",
Expand All @@ -43,8 +44,8 @@
"lodash": "^4.17.21",
"mkdirp": "^3.0.1",
"string-table": "^0.1.5",
"winston": "^3.14.1",
"ts-node": "10.9.2"
"ts-node": "10.9.2",
"winston": "^3.14.1"
},
"devDependencies": {
"@stoplight/types": "^14.1.1",
Expand Down
32 changes: 32 additions & 0 deletions shared/scripts/copy-templates.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);


const projectRoot = path.resolve(__dirname, '..');
const srcDir = path.join(projectRoot, 'src/docify/template-bundles/docusaurus');
const outDir = path.join(projectRoot, 'dist/template-bundles/docusaurus');
const excludedFile = 'docusaurus-transformer.ts';

function copyRecursive(currentDir, baseDir) {
const entries = fs.readdirSync(currentDir, { withFileTypes: true });

for (const entry of entries) {
const srcPath = path.join(currentDir, entry.name);
const relPath = path.relative(baseDir, srcPath);
const destPath = path.join(outDir, relPath);

if (entry.isDirectory()) {
copyRecursive(srcPath, baseDir);
} else if (entry.isFile() && entry.name !== excludedFile) {
fs.mkdirSync(path.dirname(destPath), { recursive: true });
fs.copyFileSync(srcPath, destPath);
}
}
}

fs.mkdirSync(outDir, { recursive: true });
copyRecursive(srcDir, srcDir);
11 changes: 5 additions & 6 deletions shared/src/docify/docifier.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Docifier } from './docifier';
import { TemplateProcessor } from '../template/template-processor';

import { Mock } from 'vitest';
vi.mock('../template/template-processor');

const mockedTemplateProcessor = TemplateProcessor as vi.mockedClass<typeof TemplateProcessor>;
const MockedTemplateProcessor: Mock = vi.mocked(TemplateProcessor);

describe('Docifier', () => {
const inputPath = 'some/input/path';
Expand All @@ -23,15 +23,14 @@ describe('Docifier', () => {
it('should instantiate TemplateProcessor for mode "WEBSITE" and call processTemplate', async () => {
const processTemplateMock = vi.fn().mockResolvedValue(undefined);

mockedTemplateProcessor.mockImplementationOnce(() => ({
MockedTemplateProcessor.mockImplementationOnce(() => ({
processTemplate: processTemplateMock,
}) as never);
}));

const docifier = new Docifier('WEBSITE', inputPath, outputPath, urlToLocalPathMapping);
await docifier.docify();

// Verify that TemplateProcessor was instantiated with the correct parameters.
expect(mockedTemplateProcessor).toHaveBeenCalledWith(
expect(MockedTemplateProcessor).toHaveBeenCalledWith(
inputPath,
expect.stringContaining('template-bundles/docusaurus'),
outputPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import {Architecture, CalmControl, CalmCore, CalmFlowTransition, CalmTemplateTransformer} from '@finos/calm-shared';
import {CalmCoreSchema} from '@finos/calm-shared/types/core-types';
import {CalmRelationshipGraph, C4Model} from '@finos/calm-shared';

import {Architecture,CalmCore} from '../../../model/core';
import {CalmControl} from '../../../model/control';
import {CalmFlowTransition} from '../../../model/flow';
import {CalmTemplateTransformer} from '../../../template/types';
import {CalmCoreSchema} from '../../../types/core-types';
import {CalmRelationshipGraph} from '../../graphing/relationship-graph';
import {C4Model} from '../../graphing/c4';

export default class DocusaurusTransformer implements CalmTemplateTransformer {
getTransformedModel(calmJson: string) {
Expand Down Expand Up @@ -202,3 +205,4 @@ export default class DocusaurusTransformer implements CalmTemplateTransformer {
return relationshipId.split('-uses-').slice(-1)[0];
}
}
module.exports = DocusaurusTransformer;
2 changes: 1 addition & 1 deletion shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ export * from './model/metadata.js';
export * from './model/interface.js';
export {C4Model} from './docify/graphing/c4.js';
export {CalmRelationshipGraph} from './docify/graphing/relationship-graph.js';

export {ValidationOutcome} from './commands/validate/validation.output';
Loading