-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(crawler): read data from npm and display on page (#44)
* chore(crawler): refactor github crawler * feat(crawler): read data from npm * remove github env
- Loading branch information
Showing
7 changed files
with
198 additions
and
211 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
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 |
---|---|---|
@@ -1,40 +1,36 @@ | ||
// require("dotenv").config(); | ||
// import { readFileSync, writeFileSync } from "fs"; | ||
import { readFileSync, writeFileSync } from "fs"; | ||
|
||
import GitHubRepositoriesProvider from "./gh-repos"; | ||
import { Artifact, Package } from "./types"; | ||
import NPMProvider from "./npm"; | ||
import { Artifact, Package, Source, Type, DataJson } from "./types"; | ||
|
||
(async () => { | ||
// get current month data | ||
let currentTrendsJson: any = {}; | ||
// let currentAllItemsJson: any = {}; | ||
// try { | ||
// const filecontentTrends = readFileSync(`${__dirname}/../../frontend/trends/webapp/model/trends.json`, "utf8"); | ||
// currentTrendsJson = JSON.parse(filecontentTrends); | ||
// } catch (e) { | ||
// if (e.code !== "ENOENT") { | ||
// throw e; | ||
// } | ||
// } | ||
// try { | ||
// const filecontentAllItems = readFileSync(`${__dirname}/../../frontend/trends/webapp/model/allItems.json`, "utf8"); | ||
// currentAllItemsJson = JSON.parse(filecontentAllItems); | ||
// } catch (e) { | ||
// if (e.code !== "ENOENT") { | ||
// throw e; | ||
// } | ||
// } | ||
|
||
// update only github an npm | ||
const Providers = [GitHubRepositoriesProvider]; | ||
|
||
const artifacts = await Promise.all( | ||
Providers.map(async (provider) => { | ||
// console.log(`Start provider '${provider.name}'.`); | ||
const items: Package[] = await provider.get(currentTrendsJson); | ||
// console.log(`Provider '${provider.name}' returned ${items.length} items.`); | ||
return items; | ||
}) | ||
); | ||
let dataJson: DataJson = { | ||
types: [], | ||
packages: [], | ||
}; | ||
|
||
const sourcesJsonString = readFileSync(`${__dirname}/../sources.json`, "utf8"); | ||
let sources: Source[] = JSON.parse(sourcesJsonString); | ||
|
||
let githubPackages: Package[] = await GitHubRepositoriesProvider.get(sources); | ||
githubPackages = await NPMProvider.get(githubPackages); | ||
|
||
// extract type from packages info | ||
let typesArray: Type[] = []; | ||
for (const packageContent of githubPackages) { | ||
let type: Type = { | ||
name: packageContent.type, | ||
}; | ||
if (!typesArray.find((type) => type.name === packageContent.type)) { | ||
typesArray.push(type); | ||
} | ||
} | ||
|
||
dataJson.packages = githubPackages; | ||
dataJson.types = typesArray; | ||
|
||
writeFileSync(`${__dirname}/../../uimodule/src/model/data.json`, JSON.stringify(dataJson)); | ||
|
||
})(); |
Oops, something went wrong.