From da261f73fad8ef9974cf1e2bac3e5f459af62023 Mon Sep 17 00:00:00 2001 From: boris Date: Mon, 4 Sep 2017 15:59:51 +0300 Subject: [PATCH] Added two new functions to the util class pageExists() - Checks if page template has been prevoisly downloaded getPageTemplatesBaseUrl() - returns a base url to the NativeScript Github Organization page based on page template flavor --- lib/shared/config.ts | 2 +- lib/shared/util.ts | 45 ++++++++++++++++++++++++++++++++++++++++++-- package.json | 4 +++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/shared/config.ts b/lib/shared/config.ts index 2d83c2a..0daa68a 100644 --- a/lib/shared/config.ts +++ b/lib/shared/config.ts @@ -1,6 +1,6 @@ export class Config { static cacheTime = 3600; - static orgBaseUrl = "https://api.github.com/orgs/NativeScript/%s"; + static orgBaseUrl = "https://github.com/NativeScript/%s"; static availableTemplateRepos: Array = [ "template-drawer-navigation", diff --git a/lib/shared/util.ts b/lib/shared/util.ts index 7f654d2..76d1ebb 100644 --- a/lib/shared/util.ts +++ b/lib/shared/util.ts @@ -1,11 +1,12 @@ +import * as childProcess from "child_process"; import * as nodeUtil from "util"; import * as path from "path"; -import * as fs from "fs"; -import * as childProcess from "child_process"; +import { Config } from "./config"; const indexOf = require("lodash.indexof"); const sortBy = require("lodash.sortby"); const request = require("request-promise"); +const fs = require("fs-extra"); export default class Util { static defaultHeaders = { @@ -43,4 +44,44 @@ export default class Util { }; }); } + + static pageExists(location: string, pageName: string) { + return new Promise((resolve, reject) => { + this.fs.readdir(location, (err: any, content: any) => { + if (err) { + reject(err); + } + + if (content.indexOf(pageName) > -1) { + resolve(true); + } else { + resolve(false); + } + }); + }); + } + + static getPageTemplatesBaseUrl(flavor: string) { + let baseUrl: string ; + + return new Promise((resolve, reject) => { + switch (flavor) { + case "JavaScript": + baseUrl = this.format(Config.orgBaseUrl, "nativescript-page-templates"); + resolve(baseUrl); + break; + + case "TypeScript": + baseUrl = this.format(Config.orgBaseUrl, "nativescript-page-templates-ts"); + resolve(baseUrl); + break; + case "Angular & TypeScript": + baseUrl = this.format(Config.orgBaseUrl, "nativescript-page-templates-ng"); + resolve(baseUrl); + break; + default: + reject("Bad Flavor"); + } + }); + } } diff --git a/package.json b/package.json index 7d60b01..7ac62cc 100644 --- a/package.json +++ b/package.json @@ -46,10 +46,12 @@ "typescript": "2.1.5" }, "dependencies": { + "fs-extra": "^4.0.1", "lodash.indexof": "^4.0.5", "lodash.sortby": "^4.7.0", "node-cache": "^4.1.1", "request": "^2.81.0", "request-promise": "^4.2.1" } -} \ No newline at end of file +} +