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
This commit is contained in:
Родитель
4e12787014
Коммит
da261f73fa
|
@ -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<any> = [
|
||||
"template-drawer-navigation",
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче