-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
moved to typescript, added prettier/eslint, etc.
- Loading branch information
Showing
4 changed files
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"env": { | ||
"browser": true, | ||
"es2020": true | ||
}, | ||
"extends": [ | ||
"google", | ||
"plugin:@typescript-eslint/recommended", | ||
"prettier/@typescript-eslint", | ||
"plugin:prettier/recommended" | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": 11, | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"trailingComma": "all", | ||
"tabWidth": 4, | ||
"semi": true, | ||
"printWidth": 120, | ||
"singleQuote": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import _ from 'lodash'; | ||
import fs from 'fs'; | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const axios = require('axios').default; | ||
|
||
// the location of the markdown file | ||
const url = | ||
'https://raw.githubusercontent.com/colemujadzic/azure-docs/master/articles/active-directory/users-groups-roles/licensing-service-plan-reference.md'; | ||
|
||
// a Microsoft online service product | ||
interface Product { | ||
productName: string; | ||
stringID: string; | ||
guid: string; | ||
servicePlansIncluded: string | string[]; | ||
servicePlansIncludedFriendlyNames: string | string[]; | ||
} | ||
|
||
// fetchMarkdown() makes a GET request to fetch the contents of the markdown file | ||
const fetchMarkdown = () => { | ||
const options = { | ||
method: 'get', | ||
url: url, | ||
}; | ||
// TODO: figure out a type here! | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
return axios(options).then((response: any) => { | ||
return Promise.resolve(response.data); | ||
}); | ||
}; | ||
|
||
// parseArray() takes an array of type string and parses out objects of type Product into a single array of objects | ||
const parseArray = (arr: Array<string>) => { | ||
const products: Product[] = []; | ||
_.some(arr, (l: string, index: number) => { | ||
const productString = _.trim(l, '|').split('|'); | ||
products.push({ | ||
productName: productString[0].trim(), | ||
stringID: productString[1].trim(), | ||
guid: productString[2].trim(), | ||
servicePlansIncluded: | ||
productString[3].indexOf('<br/>') > -1 | ||
? productString[3].trim().split('<br/>') | ||
: productString[3].trim(), | ||
servicePlansIncludedFriendlyNames: | ||
productString[4].indexOf('<br/>') > -1 | ||
? productString[4].trim().split('<br/>') | ||
: productString[4].trim(), | ||
}); | ||
return arr[index + 1] === ''; | ||
}); | ||
return products; | ||
}; | ||
|
||
// writeToFile() writes the resultant Product array to a file | ||
const writeToFile = (arr: Product[]) => { | ||
return fs.writeFileSync('./data.json', JSON.stringify(arr, null, 2), 'utf-8'); | ||
}; | ||
|
||
const main = async () => { | ||
try { | ||
const response = await fetchMarkdown(); | ||
const lines = response.split('\n'); | ||
const index = _.findIndex(lines, (l: string) => { | ||
return _.startsWith(l, '|'); | ||
}); | ||
const splitLines = lines.splice(index + 2); | ||
const parsed = parseArray(splitLines); | ||
writeToFile(parsed); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}; | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"node_modules", | ||
"**/*.spec.ts" | ||
], | ||
"compilerOptions": { | ||
"target": "es6", | ||
"module": "commonjs", | ||
"allowJs": true, | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"pretty": true, | ||
"esModuleInterop": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noEmitOnError": true, | ||
"noFallthroughCasesInSwitch": true, | ||
"noImplicitReturns": true, | ||
"noImplicitThis": true, | ||
} | ||
} |