Skip to content

Commit

Permalink
Added server CLI for demos. (#4)
Browse files Browse the repository at this point in the history
* Added BAS to currency options.
* Added postman.environmentJSON option.
* Added server CLI for demos.
* Tools: Added highcharts as peer dependency.
* Tools: Added more lint rules.
* Tools: Fixed runtime bundling.
  • Loading branch information
bre1470 authored Aug 7, 2024
1 parent 4ac98a9 commit 73cff50
Show file tree
Hide file tree
Showing 34 changed files with 685 additions and 88 deletions.
30 changes: 23 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,27 @@
"parserOptions": {
"ecmaVersion": 2020
},
"rules": {
"camelcase": [2, {"properties": "always"}],
"comma-dangle": [2, "never"],
"dot-location": [2, "property"],
"lines-around-comment": 0,
"max-len": [2, {"code": 100, "comments": 80}],
"newline-after-var": 0,
"no-alert": 2,
"no-console": 2,
"no-debugger": 2,
"no-else-return": 2,
"no-nested-ternary": 0,
"no-unmodified-loop-condition": 0,
"no-unused-vars": 1,
"object-curly-spacing": [2, "always"],
"operator-linebreak": [2, "after"],
"quotes": [2, "single"],
"require-unicode-regexp": 1,
"space-before-function-paren": 2,
"strict": 0
},
"overrides": [
{
"files": ["*.ts"],
Expand Down Expand Up @@ -55,9 +76,10 @@
"operator-linebreak": [2, "after"],
"quotes": [2, "single"],
"require-unicode-regexp": 1,
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}], // JSLint style
"space-before-function-paren": 2,
"strict": 0,
"@typescript-eslint/restrict-plus-operands": 0,
"@typescript-eslint/restrict-template-expressions": 0,
"jsdoc/check-alignment": 1,
"jsdoc/check-param-names": 1,
"jsdoc/check-tag-names": 1,
Expand Down Expand Up @@ -91,12 +113,6 @@
}
}
}
},
{
"files": ["test/unit-tests/runtime.ts"],
"rules": {
"no-console": 0
}
}
]
}
10 changes: 10 additions & 0 deletions demos/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Morningstar Connectors Demos</title>
</head>
<body>
<a href="stock/demo.html">Highcharts Stock demo</a>
</body>
</html>
2 changes: 2 additions & 0 deletions package-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"author": "Highsoft AS",
"bugs": "https://www.highcharts.com/support/",
"homepage": "https://www.highcharts.com/",
"bin": "bin/morningstar-connectors.js",
"main": "es-modules/index.js",
"types": "es-modules/index.d.ts",
"files": [
"bin/",
"es-modules/",
"LICENSE.md",
"morningstar-*",
Expand Down
20 changes: 12 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 8 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@
"bugs": "https://github.com/highcharts/morningstar-connectors/issues",
"homepage": "https://github.com/highcharts/morningstar-connectors#readme",
"repository": "https://github.com/highcharts/morningstar-connectors.git",
"bin": "bin/morningstar-connectors.js",
"main": "code/es-modules/index.js",
"types": "code/es-modules/index.d.ts",
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^7.17.0",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.0.0",
"eslint": "^8.56.0",
"eslint-plugin-brackets": "^0.1.3",
"eslint-plugin-jsdoc": "^48.8.3",
Expand All @@ -30,19 +32,21 @@
]
},
"peerDependencies": {
"@highcharts/dashboards": "^2.2.0",
"@highcharts/dashboards": ">=2.2.0",
"highcharts": ">=11.4.0"
},
"scripts": {
"build": "npm run webpack && npm run build:prepare && npm run build:copy && npm run build:pack && npm run build:cleanup",
"build:cleanup": "rm -rf build/package/",
"build:copy": "cp -R code/* LICENSE.md README.md build/package/ && cp package-build.json build/package/package.json",
"build:copy": "cp -R bin code/* LICENSE.md README.md build/package/ && cp package-build.json build/package/package.json",
"build:pack": "npm pack build/package/ --pack-destination build/",
"build:prepare": "rm -rf build/ ; mkdir -p build/package/",
"demos": "npm run webpack && npm run demos:server",
"demos:server": "(sleep 1 ; open http://localhost:8080) & python3 -m http.server --bind localhost 8080",
"demos:server": "(sleep 1 ; open http://localhost:8080) & node bin/morningstar-connectors demos",
"prepare": "rm -rf '.husky/_' ; husky",
"scripts": "rm -rf code/ ; tsc -p src/",
"scripts": "npm run scripts:bin && npm run scripts:code",
"scripts:bin": "rm -rf bin/ ; tsc -p src/CLI/ ; chmod +x bin/*.js",
"scripts:code": "rm -rf code/ ; tsc -p src/",
"reset": "rm -rf bin/ build/ code/ node_modules/ ; npm i",
"test": "npm run test:unit-tests",
"test:morningstar": "npx -y newman run --bail tmp/Collection.json -e tmp/Environment.json",
Expand Down
113 changes: 113 additions & 0 deletions src/CLI/Library/Args.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* *
*
* (c) 2009-2024 Highsoft AS
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* Authors:
* - Sophie Bremer
*
* */


'use strict';


/* *
*
* Constants
*
* */


export const SHORTCUTS: Record<string, string> = {
'?': 'help',
h: 'help',
v: 'version'
};


/* *
*
* Interface
*
* */


export type Args = Record<string, ArgValue>;


export type ArgValue = (true|string|Array<string>);


/* *
*
* Functions
*
* */


/**
* Converts CLI arguments into a flexible dictionary.
*
* @param argv
* Arguments to convert.
*
* @param shortcuts
* Shortcut arguments as a map to their full counterpart.
*
* @return
* Converted CLI arguments.
*/
function getArgs (
argv = process.argv,
shortcuts = SHORTCUTS
): Args {
const args: Args = {};

let currentKey: string = '_';
let currentValue: ArgValue;

for (const arg of argv) {
if (
currentKey === '_' &&
arg.startsWith('/')
) {
continue;
}
if (arg.startsWith('--')) {
currentKey = arg.substring(2);
args[currentKey] = true;
} else if (arg.startsWith('-')) {
currentKey = shortcuts[arg.substring(1)];
args[currentKey] = true;
} else {
currentValue = args[currentKey];
if (currentKey === '_') {
args[currentKey] = arg;
} else if (currentValue instanceof Array) {
currentValue.push(arg);
} else if (typeof currentValue === 'string') {
args[currentKey] = [currentValue, arg];
} else {
args[currentKey] = arg;
}
}
}

return args;
}


/* *
*
* Default Export
*
* */


export default {
getArgs
};
Loading

0 comments on commit 73cff50

Please sign in to comment.