Skip to content

Commit

Permalink
Multiple changes - fixing the CLI
Browse files Browse the repository at this point in the history
Introducing `tsup` to bundle our packages together into a useable executable.
Introducing `pnpm` ( performance npm ) to allow for easy `inter-workspace` dependencies.
Migrated `spectral` into `shared` - updated README and steps - now the steps aren't referenced via file and are part of the code itself. Simplfying validation code.
  • Loading branch information
Thels committed Nov 26, 2024
1 parent 6acefb9 commit 177b8f0
Show file tree
Hide file tree
Showing 47 changed files with 6,465 additions and 10,286 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ node_modules/
**/.vscode-test/
**/out/
**/dependency-check-report/

**/tsconfig.tsbuildinfo
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ your project.
| -------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Common Architecture Language Model](./calm) | [@rocketstack-matt](https://github.com/rocketstack-matt), [@jpgough-ms](https://github.com/jpgough-ms) | [![Validation of CALM Samples](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml) |
| [Docs](./docs) | [@rocketstack-matt](https://github.com/rocketstack-matt) | [![Sync Docs to S3](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/s3-docs-sync.yml) |
| [CLI](./cli) & [Shared](./shared) | [@aidanm3341](https://github.com/aidanm3341), [@lbulanti-ms](https://github.com/lbulanti-ms), [@willosborne](https://github.com/willosborne), [@grahampacker-ms](https://github.com/grahampacker-ms) [@Thels](https://github.com/Thels) | [![Build CLI](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml) [![Build Shared Module](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml/badge.svg?branch=main)](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml) |
| [Spectral](./spectral) | [@willosborne](https://github.com/willosborne), [@lbulanti-ms](https://github.com/lbulanti-ms), [@grahampacker-ms](https://github.com/grahampacker-ms) | [![Validation of CALM Samples](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/spectral-validation.yml) |
| [CLI](./cli) & [Shared](./shared) | [@aidanm3341](https://github.com/aidanm3341), [@lbulanti-ms](https://github.com/lbulanti-ms), [@willosborne](https://github.com/willosborne), [@grahampacker-ms](https://github.com/grahampacker-ms) [@Thels](https://github.com/Thels) | [![Build CLI](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/cli-tests.yml) [![Build Shared Module](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml/badge.svg?branch=main)](https://github.com/finos/architecture-as-code/actions/workflows/shared-tests.yml) | |
| [Translators](./translator) | [@Budlee](https://github.com/Budlee) [@matthewgardner](https://github.com/matthewgardner) [@jpgough-ms](https://github.com/jpgough-ms) | [![Build Translators](https://github.com/finos/architecture-as-code/actions/workflows/translator.yml/badge.svg)](https://github.com/finos/architecture-as-code/actions/workflows/translator.yml) |

## Getting Involved
Expand Down Expand Up @@ -59,6 +58,19 @@ We accept contributions via Pull Request, to make a contribution:
6. Push to the branch (`git push origin feature/fooBar`)
7. Create a new Pull Request

## Language Dependencies

### TypeScript Packages

Currently we have three typescript packages - two of which are configured using `pnpm` and one which is configured using `npm` - we will aim for eventual consistency.

To get started with `pnpm` you need to run

```shell
npm install -g pnpm
pnpm setup
```

## License

Copyright 2024 FINOS
Expand Down
15 changes: 7 additions & 8 deletions cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ You can use these tools to create an instantiation of an architectural pattern,
Install the CLI on to your machine with this command:

```shell
% npm install -g @finos/calm-cli
% pnpm install -g @finos/calm-cli
```

Type `calm` into your terminal, and you should see the help text printed out.
Expand Down Expand Up @@ -185,7 +185,7 @@ Options:
## Coding for the CLI
The CLI module has its logic split into two modules, `cli` and `shared`. Both are managed by [npm workspaces](https://docs.npmjs.com/cli/v8/using-npm/workspaces).
The CLI module has its logic split into two modules, `cli` and `shared`. Both are managed by [pnpm workspaces](https://pnpm.io/workspaces).
* `cli` module is for anything pertaining to the calling of the core logic, the CLI wrapper
* `shared` module is where the logic being delegated to actually sits, so that it can be re-used for other use-cases if required.
Expand All @@ -196,18 +196,17 @@ Ensure you've cloned down the repository ( see root `README.md` for information
```shell
# Step 1: Install all necessary dependencies for the workspace
npm install
pnpm install
# Step 2: Build the workspace (compiles source code for all workspaces)
npm run build
pnpm run build
# Step 3: Link the workspace locally for testing
npm link:cli
# Step 4: Start the watch process for live development
npm run watch
pnpm link --global
```
**Currently** there is no support for `watch` based development - this will be improved as the depedency/bundling is better understood.
### CLI Tests
Expand Down
6 changes: 3 additions & 3 deletions cli/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = {
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['./**/*.spec.ts'],
testMatch: ['**/*.spec.ts'],
transformIgnorePatterns: [
"<rootDir>/node_modules/(?!calm-shared)",
"<rootDir>/node_modules/(?!@finos/calm-shared)",
'^.+\\.js$'
],
rootDir: '.',
Expand Down
20 changes: 14 additions & 6 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@
"calm": "dist/index.js"
},
"scripts": {
"build": "tsc",
"watch": "tsc -watch -p ./",
"clean": "rimraf dist",
"test": "jest --verbose",
"build": "tsup src/index.ts --format cjs --shims && pnpm run copy-calm-schema",
"copy-calm-schema": "copyfiles \"../calm/draft/2024-04/meta/*\" dist/calm/",
"test": "jest",
"lint": "eslint src",
"lint-fix": "eslint src --fix",
"dependency-check": "dependency-check --project 'calm-cli' --scan . --out ./dependency-check-report --format ALL --suppression ../.github/node-cve-ignore-list.xml"
Expand All @@ -28,21 +27,30 @@
"author": "",
"license": "ISC",
"dependencies": {
"@finos/calm-shared": "workspace:*",
"canvas": "^2.11.2",
"commander": "^12.0.0",
"copyfiles": "^2.4.1",
"mkdirp": "^3.0.1"
"mkdirp": "^3.0.1",
"ts-jest": "^29.2.5"
},
"devDependencies": {
"@finos/calm-shared": "workspace:*",
"@jest/globals": "^29.7.0",
"@types/jest": "^29.5.14",
"@types/json-pointer": "^1.0.34",
"@types/junit-report-builder": "^3.0.2",
"@types/lodash": "^4.17.0",
"@types/node": "^22.10.0",
"@types/xml2js": "^0.4.14",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.15.0",
"eslint": "^9.13.0",
"globals": "^15.12.0",
"jest": "^29.7.0",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-node": "10.9.2",
"tsup": "^8.0.0",
"typescript": "^5.4.3",
"xml2js": "^0.6.2"
}
Expand Down
9 changes: 5 additions & 4 deletions cli/src/cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ describe('CLI Integration Tests', () => {

beforeAll(async () => {
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), integrationTestPrefix));
await callNpmFunctionSync(`${projectRoot}`, 'link');
await callPnpmFunctionSync(`${projectRoot}`, 'link --global');
}, millisPerSecond * 20);

afterAll(async () => {
if (tempDir) {
fs.rmSync(tempDir, { recursive: true });
}
await callPnpmFunctionSync(`${projectRoot}`, 'unlink --global');
}, millisPerSecond * 20);

test('shows help if no arguments provided', (done) => {
Expand Down Expand Up @@ -83,7 +84,7 @@ describe('CLI Integration Tests', () => {
});
});

test('example validate command - no format or schema input - outputting JUNIT to stdout', (done) => {
test('example validate command - outputting JUNIT to stdout', (done) => {
const exampleValidateCommand = 'calm validate -p ../calm/pattern/api-gateway.json -i ../calm/samples/api-gateway-instantiation.json -f junit';
exec(exampleValidateCommand, async (_error, stdout, _stderr) => {
const parsedOutput = await parseStringPromise(stdout);
Expand Down Expand Up @@ -139,7 +140,7 @@ describe('CLI Integration Tests', () => {
});


async function callNpmFunctionSync(projectRoot: string, command: string) {
await execPromise(`npm ${command}`, { cwd: projectRoot });
async function callPnpmFunctionSync(projectRoot: string, command: string) {
await execPromise(`pnpm ${command}`, { cwd: projectRoot });
}

9 changes: 2 additions & 7 deletions cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#! /usr/bin/env node

import { CALM_META_SCHEMA_DIRECTORY, CALM_SPECTRAL_RULES_DIRECTORY, getFormattedOutput, runGenerate, validate, visualizeInstantiation, visualizePattern } from '@finos/calm-shared';
import { CALM_META_SCHEMA_DIRECTORY, getFormattedOutput, runGenerate, validate, visualizeInstantiation, visualizePattern, exitBasedOffOfValidationOutcome } from '@finos/calm-shared';
import { Option, program } from 'commander';
import path from 'path';
import { mkdirp } from 'mkdirp';
import { writeFileSync } from 'fs';
import { exitBasedOffOfValidationOutcome } from '@finos/calm-shared/dist/commands/validate/validate';

const FORMAT_OPTION = '-f, --format <format>';
const INSTANTIATION_OPTION = '-i, --instantiation <file>';
Expand Down Expand Up @@ -66,11 +65,7 @@ program
.option(VERBOSE_OPTION, 'Enable verbose logging.', false)
.action(async (options) => {
const outcome = await validate(options.instantiation, options.pattern, options.schemaDirectory, options.verbose);

const spectralRulesetForInstantiation = CALM_SPECTRAL_RULES_DIRECTORY + '/instantiation/validation-rules.yaml';
const spectralRulesetForPattern = CALM_SPECTRAL_RULES_DIRECTORY + '/pattern/validation-rules.yaml';

const content = getFormattedOutput(outcome, options.format,spectralRulesetForInstantiation, spectralRulesetForPattern);
const content = getFormattedOutput(outcome, options.format);
writeOutputFile(options.output, content);
exitBasedOffOfValidationOutcome(outcome, options.strict);
}
Expand Down
17 changes: 14 additions & 3 deletions cli/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,26 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"module": "CommonJS",
"target": "ES6",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true,
"resolveJsonModule": true,
"types": ["node", "jest"]
"moduleResolution": "node",
"types": [
"node",
"jest"
],
"typeRoots": [
"node_modules/@types"
]
},
"references": [
{
"path": "../shared"
}
],
"include": [
"src/**/*"
]
Expand Down
18 changes: 18 additions & 0 deletions cli/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@


import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
sourcemap: true,
clean: true,
external: ['canvas', 'fsevents', /node_modules/],
noExternal: ['@finos/calm-shared', /tsup/],
bundle: true,
splitting: false,
minify: false,
shims: true,
target: 'es2021',
treeshake: true
});
Loading

0 comments on commit 177b8f0

Please sign in to comment.