Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 39f77e1

Browse files
authored
Extract config (#7)
- Extracted SnConfig* Classes, they will be referenced from __sn-client-js__
1 parent 62211cc commit 39f77e1

17 files changed

Lines changed: 63 additions & 231 deletions

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sn-client-cli",
3-
"version": "1.0.0",
3+
"version": "1.0.0-development-4",
44
"description": "Command line tooling for Sense/NET ECM client",
55
"main": "dist/index.js",
66
"bin": {
@@ -13,7 +13,8 @@
1313
"dist_tests",
1414
"documentation",
1515
"src",
16-
"test"
16+
"test",
17+
"sn.config.js"
1718
],
1819
"scripts": {
1920
"pretest": "npm run build:tests",
@@ -24,8 +25,9 @@
2425
"build": "tsc",
2526
"build:tests": "tsc -p tsconfig.test.json",
2627
"typedoc": "gulp typedoc",
27-
"tslint": "tslint --project tsconfig.json && tslint --project tsconfig.test.json",
28-
"commit": "git-cz"
28+
"tslint": "tslint --project tsconfig.json ./src/**/*.ts && tslint --project tsconfig.test.json ./test/**/*.ts",
29+
"commit": "git-cz",
30+
"publish:development": "npm publish --tag development"
2931
},
3032
"repository": {
3133
"type": "git",
@@ -46,19 +48,18 @@
4648
"homepage": "https://github.com/SenseNet/sn-client-cli#readme",
4749
"devDependencies": {
4850
"@types/chai": "^3.4.35",
51+
"@types/mocha": "^2.2.40",
52+
"@types/node": "^7.0.12",
4953
"chai": "^3.5.0",
5054
"commitizen": "^2.9.6",
5155
"mocha": "^3.2.0",
5256
"mocha-typescript": "^1.0.23",
5357
"prompt": "^1.0.0",
5458
"tslint": "^5.0.0",
5559
"typedoc": "^0.5.9",
56-
"typescript": "^2.2.2"
60+
"typescript": "^2.3.2"
5761
},
5862
"dependencies": {
59-
"@types/chai": "^3.4.35",
60-
"@types/mocha": "^2.2.40",
61-
"@types/node": "^7.0.12",
6263
"adm-zip": "^0.4.7",
6364
"command-line-args": "^4.0.2",
6465
"command-line-commands": "^2.0.0",
@@ -71,7 +72,7 @@
7172
"gulp-run": "^1.7.1",
7273
"gulp-typedoc": "^2.0.2",
7374
"path": "^0.12.7",
74-
"sn-client-js": "^1.1.1-beta.1"
75+
"sn-client-js": "1.1.1-development.3"
7576
},
7677
"czConfig": {
7778
"path": "node_modules/cz-conventional-changelog"

src/help.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as CommandLineUsage from 'command-line-usage';
2-
import { SnConfigFieldModel } from "./utils/snconfig/snconfigfieldmodel";
2+
import { Config } from "sn-client-js";
33

44
/**
55
* This class will be used to display help information on 'help' command or when the user enters invalit runtime arguments
@@ -10,7 +10,7 @@ export class Help {
1010
* Displays the help info.
1111
* @param validOptions {SnConfigFieldModel[]} The valid option values from the SnConfigModel
1212
*/
13-
public static Show(validOptions: SnConfigFieldModel[]) {
13+
public static Show(validOptions: Config.SnConfigFieldModel[]) {
1414
const definitionDocs = [
1515
{
1616
header: 'SN-Client-CLI',

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import * as CommadLineArgs from 'command-line-args';
22
import * as CommandLineCommands from 'command-line-commands';
33
import * as FileSystem from 'fs';
44
import * as Path from 'path';
5+
import { Config } from 'sn-client-js';
56
import { Help } from './help';
67
import { DoInitializeConfigs } from './initialize-config';
78
import { Initializer } from './initializer';
89
import { DoFetchTypes } from './sn-fetch-types';
9-
import { SnConfigFieldModelStore } from './utils/snconfig/snconfigfieldmodelstore';
10-
import { SnConfigModel } from "./utils/snconfig/snconfigmodel";
10+
import { SnCliConfigModel } from "./utils/snconfig/snconfigmodel";
1111

1212
/**
1313
* Entry point for the 'sn-client' command
@@ -35,11 +35,13 @@ const Start = async () => {
3535
}
3636

3737
const validCommands = [CMD_INIT, CMD_FETCH_TYPES, CMD_HELP];
38-
const validOptions = SnConfigFieldModelStore.GetCommandOptions();
38+
const validOptions = Config.SnConfigFieldModelStore.GetCommandOptions();
3939

4040
try {
4141
const { command } = CommandLineCommands(validCommands);
42-
const options: Partial<SnConfigModel> = CommadLineArgs(validOptions.map((op) => {
42+
const options: Partial<SnCliConfigModel> = CommadLineArgs(validOptions
43+
.filter((op) => op.StoreKey.indexOf(SnCliConfigModel.name) === 0)
44+
.map((op) => {
4345
return {
4446
name: op.FieldName
4547
};

src/initializer.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as Path from 'path';
22
import { PathHelper } from "./utils/pathhelper";
3+
import { SnCliConfigModel } from "./utils/snconfig/snconfigmodel";
34
import { SnConfigReader } from "./utils/snconfig/snconfigreader";
45
import { Stage } from "./utils/stage";
56

@@ -25,8 +26,8 @@ export class Initializer {
2526
return this.pathHelper;
2627
}
2728

28-
private configReader: SnConfigReader;
29-
public get SnConfigReader(): SnConfigReader {
29+
private configReader: SnConfigReader<SnCliConfigModel>;
30+
public get SnConfigReader(): SnConfigReader<SnCliConfigModel> {
3031
return this.configReader;
3132
}
3233

@@ -37,7 +38,7 @@ export class Initializer {
3738
`${process.cwd()}${Path.sep}node_modules${Path.sep}sn-client-cli`);
3839
this.stage = new Stage(this.pathHelper);
3940
await this.stage.PrepareAsync();
40-
this.configReader = new SnConfigReader(this.pathHelper.PackageRootPath);
41+
this.configReader = new SnConfigReader(SnCliConfigModel, this.pathHelper.PackageRootPath);
4142
this.configReader.ReadConfigFile();
4243
}
4344
}

src/utils/ask.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as Prompt from 'prompt';
2-
import { SnConfigBehavior } from "./snconfig/snconfigbehavior";
3-
import { SnConfigFieldModelStore } from './snconfig/snconfigfieldmodelstore';
4-
import { SnConfigModel } from './snconfig/snconfigmodel';
2+
import { Config } from "sn-client-js";
3+
import { SnCliConfigModel } from './snconfig/snconfigmodel';
54

65
/**
76
* This class is a wrapper for command-line data input in Node.Js console applications
@@ -47,10 +46,10 @@ export class Ask {
4746
}
4847

4948
public static createPromptQuestionFromConfigName(fieldName: string) {
50-
const cfg = SnConfigFieldModelStore.Get(fieldName);
49+
const cfg = Config.SnConfigFieldModelStore.Get(fieldName);
5150
return {
5251
description: cfg.Question, // ??
53-
hidden: cfg.Behavior | SnConfigBehavior.HideConsoleInput,
52+
hidden: cfg.Behavior | Config.SnConfigBehavior.HideConsoleInput,
5453
name: cfg.FieldName,
5554
};
5655
}
@@ -59,8 +58,8 @@ export class Ask {
5958
* Asks about a list of provided config values
6059
* @param missingConfigs {K[]} A keys from SnConfigModel's fields which has to be asked
6160
*/
62-
public static async MissingConfigs<K extends keyof SnConfigModel>(...missingConfigs: K[]): Promise<Partial<SnConfigModel>> {
63-
return new Promise<Partial<SnConfigModel>>((resolve, reject) => {
61+
public static async MissingConfigs<K extends keyof SnCliConfigModel>(...missingConfigs: K[]): Promise<Partial<SnCliConfigModel>> {
62+
return new Promise<Partial<SnCliConfigModel>>((resolve, reject) => {
6463
Prompt.start();
6564
const configs = missingConfigs.map((cfg) => {
6665
this.createPromptQuestionFromConfigName(cfg);

src/utils/download.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,12 @@ export class Download {
5353
*/
5454
public async GetAsBufferAsync(): Promise<Buffer> {
5555
return new Promise<Buffer>((resolve) => {
56+
57+
const url = new URL(this.host);
58+
5659
Http.get({
5760
headers: this.headers,
58-
host: this.host,
61+
host: url.origin,
5962
path: this.path,
6063
}, (response: Http.IncomingMessage) => this.HandleResponse(response, resolve));
6164
});

src/utils/snconfig/snconfigbehavior.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/utils/snconfig/snconfigfielddecorator.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/utils/snconfig/snconfigfieldmodel.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/utils/snconfig/snconfigfieldmodelstore.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

0 commit comments

Comments
 (0)