Skip to content

Commit

Permalink
cleanup core engine
Browse files Browse the repository at this point in the history
  • Loading branch information
vunb committed Jun 10, 2019
1 parent f8a995b commit fe5b81c
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 243 deletions.
29 changes: 0 additions & 29 deletions .release-it.json

This file was deleted.

7 changes: 7 additions & 0 deletions TODO.md
Expand Up @@ -2,3 +2,10 @@ TODO
====

* [ ] Write an article for implementing custom kites extension

Discover Mode
=============

* `discover: true` - Discover extensions in rootDirectory
* `discover: 'path-string'` - Discover extentions in `path-string`
* `discover: false` - Disable discover option
19 changes: 10 additions & 9 deletions kites.config.json
@@ -1,11 +1,12 @@
{
"extensionsLocationCache": true,
"logger": {
"console": {
"transport": "console",
"level": "info"
}
"discover": true,
"extensionsLocationCache": true,
"logger": {
"console": {
"transport": "console",
"level": "info"
}

},
"extensions": null
}
},
"extensions": null
}
23 changes: 9 additions & 14 deletions packages/core/src/engine/kites.spec.ts
Expand Up @@ -69,23 +69,23 @@ describe('kites engine', () => {

it('should auto discover when the feature is enabled', async () => {

await engine({
const rootDirectory = path.join(__dirname, '../../test');
const app = await engine({
discover: true,
extensionsLocationCache: false,
rootDirectory: path.resolve('test')
}).ready((core) => {
core.logger.info('Kites is ready!');
expect(core.aKitesExtensionInitialized).eq(true, 'found a kites extension which has initialized!');
rootDirectory: rootDirectory
}).init();

expect(app.aKitesExtensionInitialized).eq(true, 'found a kites extension which has initialized!');
});

it('should accept plain function as an extension', async () => {

await engine(false).use((core) => {
const app = await engine(false).use((core) => {
core.guest2 = true;
}).ready((app) => {
expect(app.guest2).eq(true, 'kites use function definition as an extension!');
}).init();

expect(app.guest2).eq(true, 'kites use function definition as an extension!');
});

});
Expand All @@ -112,12 +112,6 @@ describe('kites logs', () => {
expect(allTransportAreSilent).eq(true, 'all transports are silent');
});

it('should have Debug transport for logs enabled by default', () => {
engine(false).init().then((app) => {
expect(app.logger.transports).to.have.property('debug');
});
});

it('should fail to configure custom transport that does not have enough options', async () => {

await engine({
Expand Down Expand Up @@ -279,5 +273,6 @@ describe('kites utilities', () => {
it('should access app path', () => {
let app = new KitesInstance();
expect(app.rootDirectory).eq(path.resolve(process.cwd(), 'packages'));
expect(app.appDirectory).eq(path.resolve(process.cwd(), 'packages', 'core'));
});
});
18 changes: 17 additions & 1 deletion packages/core/src/engine/kites.ts
Expand Up @@ -24,7 +24,7 @@ export type KitesReadyCallback = (kites: IKites) => void;
*/
export interface IKitesOptions {
[key: string]: any;
discover?: boolean;
discover?: boolean | string; // string for path discovery
loadConfig?: boolean;
rootDirectory?: string;
appDirectory?: string;
Expand Down Expand Up @@ -211,6 +211,22 @@ export class KitesInstance extends EventEmitter implements IKites {
return this;
}

/**
* Thiết lập giá trị cấu hình cho các extensions
* Example:
* .set('express:static', './assets') -> kites.options.express.static = './assets'
* @param option
* @param value
*/
set(option: string, value: string) {
const tokens = option.split(':');
if (tokens.length === 2) {
this.options[tokens[0]][tokens[1]] = value;
} else if (tokens.length === 1) {
this.options[tokens[0]] = value;
}
}

/**
* Assign config loaded callback
* @param fn Function
Expand Down
64 changes: 0 additions & 64 deletions src/extend-config.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/kites.ts

This file was deleted.

15 changes: 0 additions & 15 deletions src/main.spec.ts

This file was deleted.

37 changes: 0 additions & 37 deletions src/main.ts

This file was deleted.

102 changes: 51 additions & 51 deletions tslint.json
@@ -1,54 +1,54 @@
{
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
"defaultSeverity": "error",
"extends": [
"tslint:recommended"
],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"no-console": false,
"no-var-keyword": false,
"no-empty": false,
"ban-types": false,
"object-literal-shorthand": false,
"member-access": false,
"prefer-const": false,
"trailing-comma": false,
"forin": false,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"jsRules": {
"no-unused-expression": true
},
"rules": {
"no-console": false,
"no-var-keyword": false,
"no-empty": false,
"ban-types": false,
"object-literal-shorthand": false,
"member-access": false,
"prefer-const": false,
"trailing-comma": false,
"forin": false,
"typedef-whitespace": [
true,
{
"call-signature": "nospace",
"index-signature": "nospace",
"parameter": "nospace",
"property-declaration": "nospace",
"variable-declaration": "nospace"
}
],
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"arrow-parens": false,
"max-line-length": [
true,
250
],
"curly": false,
"quotemark": [
true,
"single"
],
"interface-name": false,
"indent": [
true,
"spaces"
]
},
"rulesDirectory": []
"whitespace": [
true,
"check-branch",
"check-decl",
"check-operator",
"check-separator",
"check-type"
],
"arrow-parens": false,
"max-line-length": [
true,
250
],
"curly": false,
"quotemark": [
true,
"single"
],
"interface-name": false,
"indent": [
true,
"spaces"
]
},
"rulesDirectory": []
}

0 comments on commit fe5b81c

Please sign in to comment.