in functions/src/project.ts [131:216]
getProjectConfig(id: string) {
const idParsed = Util.parseProjectId(id);
return this.github
.hasProjectConfig(id)
.then((exists: boolean) => {
if (exists) {
// Config exists, fetch and parse it
return this.github.getProjectConfig(id).then(data => {
// Parse and remove comments
const contents = data.toString();
return cjson.parse(contents, null, true);
});
} else {
// If the project has no config, make one up
Logger.debug(id, "WARN: Using default config.");
return this.github
.getRepoReadmeFile(idParsed.owner, idParsed.repo)
.then((readme: string) => {
Logger.debug(id, `README: ${readme}`);
return {
name: idParsed.repo,
type: "library",
content: readme
};
});
}
})
.then(config => {
// Add inferred platforms
if (!config.platforms) {
config.platforms = this.inferPlatforms(id);
}
// Consult the feature blacklist
if (Config.FEATURED_BLACKLIST_PROJECTS.indexOf(id) >= 0) {
config.blacklist = true;
} else {
config.blacklist = false;
}
// Normalize the formatting of "pages"
if (config.pages) {
const normalizedPages: PageConfig[] = [];
if (Array.isArray(config.pages)) {
// In v0 pages was just an array of paths
for (const path of config.pages) {
normalizedPages.push({
path
});
}
} else {
// In v1 it is a map of { path: title }
Object.keys(config.pages).forEach((path: string) => {
const name = config.pages[path];
normalizedPages.push({
name,
path
});
});
}
config.pages = normalizedPages;
}
// Merge the config with repo metadata like stars
// and updated time.
return this.github
.getRepoMetadata(idParsed.owner, idParsed.repo)
.then(meta => {
if (meta.description) {
config.description = meta.description;
}
config.fork = meta.fork;
config.stars = meta.stars;
config.last_updated = meta.last_updated;
return config;
});
})
.then(config => {
return this.sanitizeForStorage(config);
});
}