Skip to content

Commit 9d1bbe4

Browse files
committed
Added @kephas/commands to Angular 12 build system
1 parent 9990c56 commit 9d1bbe4

17 files changed

+353
-1
lines changed

src/angular.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@
9595
}
9696
}
9797
}
98+
},
99+
"@kephas/commands": {
100+
"projectType": "library",
101+
"root": "projects/kephas/commands",
102+
"sourceRoot": "projects/kephas/commands/src",
103+
"prefix": "lib",
104+
"architect": {
105+
"build": {
106+
"builder": "@angular-devkit/build-angular:ng-packagr",
107+
"options": {
108+
"project": "projects/kephas/commands/ng-package.json"
109+
},
110+
"configurations": {
111+
"production": {
112+
"tsConfig": "projects/kephas/commands/tsconfig.lib.prod.json"
113+
},
114+
"development": {
115+
"tsConfig": "projects/kephas/commands/tsconfig.lib.json"
116+
}
117+
},
118+
"defaultConfiguration": "production"
119+
},
120+
"test": {
121+
"builder": "@angular-devkit/build-angular:karma",
122+
"options": {
123+
"main": "projects/kephas/commands/src/test.ts",
124+
"tsConfig": "projects/kephas/commands/tsconfig.spec.json",
125+
"karmaConfig": "projects/kephas/commands/karma.conf.js"
126+
}
127+
}
128+
}
98129
}
99130
},
100131
"defaultProject": "@kephas/core"

src/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
"build": "ng build",
88
"test": "ng test",
99
"lint": "ng lint",
10-
"package": "ng build --project=@kephas/core && ng build --project=@kephas/reflection && ng build --project=@kephas/messaging"
10+
"pack-core": "ng build --project=@kephas/core",
11+
"pack-reflection": "ng build --project=@kephas/reflection",
12+
"pack-messaging": "ng build --project=@kephas/messaging",
13+
"pack-commands": "ng build --project=@kephas/commands",
14+
"pack-all": "ng build --project=@kephas/core && ng build --project=@kephas/reflection && ng build --project=@kephas/messaging && ng build --project=@kephas/commands"
1115
},
1216
"private": true,
1317
"dependencies": {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Commands
2+
3+
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 12.2.0.
4+
5+
## Code scaffolding
6+
7+
Run `ng generate component component-name --project commands` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project commands`.
8+
> Note: Don't forget to add `--project commands` or else it will be added to the default project in your `angular.json` file.
9+
10+
## Build
11+
12+
Run `ng build commands` to build the project. The build artifacts will be stored in the `dist/` directory.
13+
14+
## Publishing
15+
16+
After building your library with `ng build commands`, go to the dist folder `cd dist/commands` and run `npm publish`.
17+
18+
## Running unit tests
19+
20+
Run `ng test commands` to execute the unit tests via [Karma](https://karma-runner.github.io).
21+
22+
## Further help
23+
24+
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Karma configuration file, see link for more information
2+
// https://karma-runner.github.io/1.0/config/configuration-file.html
3+
4+
module.exports = function (config) {
5+
config.set({
6+
basePath: '',
7+
frameworks: ['jasmine', '@angular-devkit/build-angular'],
8+
plugins: [
9+
require('karma-jasmine'),
10+
require('karma-chrome-launcher'),
11+
require('karma-jasmine-html-reporter'),
12+
require('karma-coverage'),
13+
require('@angular-devkit/build-angular/plugins/karma')
14+
],
15+
client: {
16+
jasmine: {
17+
// you can add configuration options for Jasmine here
18+
// the possible options are listed at https://jasmine.github.io/api/edge/Configuration.html
19+
// for example, you can disable the random execution with `random: false`
20+
// or set a specific seed with `seed: 4321`
21+
},
22+
clearContext: false // leave Jasmine Spec Runner output visible in browser
23+
},
24+
jasmineHtmlReporter: {
25+
suppressAll: true // removes the duplicated traces
26+
},
27+
coverageReporter: {
28+
dir: require('path').join(__dirname, '../../../coverage/kephas/commands'),
29+
subdir: '.',
30+
reporters: [
31+
{ type: 'html' },
32+
{ type: 'text-summary' }
33+
]
34+
},
35+
reporters: ['progress', 'kjhtml'],
36+
port: 9876,
37+
colors: true,
38+
logLevel: config.LOG_INFO,
39+
autoWatch: true,
40+
browsers: ['Chrome'],
41+
singleRun: false,
42+
restartOnFileChange: true
43+
});
44+
};
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"$schema": "../../../node_modules/ng-packagr/ng-package.schema.json",
3+
"dest": "../../../dist/kephas/commands",
4+
"lib": {
5+
"entryFile": "src/public-api.ts",
6+
"umdModuleIds": {
7+
"@kephas/core": "@kephas/core",
8+
"rxjs": "rxjs"
9+
}
10+
}
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "@kephas/commands",
3+
"version": "1.0.0-preview.1",
4+
"description": "Provides the commands infrastructure.",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/kephas-software/kephas-js/tree/master/src/projects/kephas/commands"
8+
},
9+
"keywords": [
10+
"kephas",
11+
"commands"
12+
],
13+
"author": {
14+
"name": "Kephas Software SRL"
15+
},
16+
"license": "MIT",
17+
"peerDependencies": {
18+
"@kephas/core": "^1.0.0-preview.1",
19+
"rxjs": "^6.5.3"
20+
},
21+
"dependencies": {
22+
"tslib": "^2.3.0"
23+
},
24+
"devDependencies": {
25+
"typescript": "4.2.4"
26+
}
27+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { LogLevel, Expando } from '@kephas/core';
2+
3+
/**
4+
* The base command response.
5+
*
6+
* @export
7+
* @interface CommandResponse
8+
*/
9+
export interface CommandResponse extends Expando {
10+
/**
11+
* The severity.
12+
*
13+
* @type {LogLevel}
14+
* @memberof CommandResponse
15+
*/
16+
severity: LogLevel;
17+
18+
/**
19+
* The message.
20+
*
21+
* @type {string}
22+
* @memberof CommandResponse
23+
*/
24+
message?: string;
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { Context } from '@kephas/core';
2+
3+
/**
4+
* Options for controlling the command execution.
5+
*
6+
* @export
7+
* @interface CommandClientContext
8+
*/
9+
export interface CommandClientContext extends Context {
10+
/**
11+
* Indicates whether warnings should be notified. Default is true.
12+
*
13+
* @type {boolean}
14+
* @memberof CommandClientContext
15+
*/
16+
notifyWarnings?: boolean;
17+
18+
/**
19+
* Indicates whether errors should be notified. Default is true.
20+
*
21+
* @type {boolean}
22+
* @memberof CommandClientContext
23+
*/
24+
notifyErrors?: boolean;
25+
26+
/**
27+
* Indicates the number of retries if the operation fails. Default is none.
28+
*
29+
* @type {number}
30+
* @memberof CommandClientContext
31+
*/
32+
retries?: number;
33+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { CommandResponse } from "./command";
2+
3+
/**
4+
* Signals that a command error occurred.
5+
*
6+
* @export
7+
* @class CommandError
8+
* @extends {Error}
9+
*/
10+
export class CommandError extends Error {
11+
/**
12+
* Creates an instance of CommandError.
13+
* @param {string} message The error message.
14+
* @param {CommandResponse} [response] Optional. The command response.
15+
* @memberof CommandError
16+
*/
17+
constructor(message: string, public readonly response?: CommandResponse) {
18+
super(message);
19+
}
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { expect } from 'chai';
2+
import 'mocha';
3+
4+
import { CommandProcessorClient } from '.';
5+
import { LiteCompositionContext } from '@kephas/core';
6+
7+
describe('CommandProcessorClient.composition', () => {
8+
it('should be available', () => {
9+
const container = LiteCompositionContext.Instance;
10+
const processor = container.get(CommandProcessorClient);
11+
expect(processor).to.be.instanceOf(CommandProcessorClient);
12+
});
13+
});
14+
15+
describe('CommandProcessorClient.process', () => {
16+
it('should fail', () => {
17+
const processor = new CommandProcessorClient();
18+
expect(() => processor.process('help')).to.throw();
19+
});
20+
});

0 commit comments

Comments
 (0)