Add new tslint rules and apply some refactoring.
This commit is contained in:
Родитель
dd7d4962ae
Коммит
cdc5398988
|
@ -72,7 +72,6 @@ references.d.ts
|
|||
*.js.map
|
||||
|
||||
# but don't ignoreimportant js files
|
||||
!config.js
|
||||
!/consts/backup-data.js
|
||||
|
||||
#ignore templates folder
|
||||
|
|
11
config.js
11
config.js
|
@ -1,11 +0,0 @@
|
|||
'use strict';
|
||||
|
||||
const Config = {};
|
||||
|
||||
Config.options = {
|
||||
cacheTime: 3600, // Value in sec
|
||||
orgBaseUrl: 'https://api.github.com/orgs/NativeScript/repos?per_page=100'
|
||||
};
|
||||
|
||||
|
||||
module.exports = Config;
|
|
@ -1,3 +1,3 @@
|
|||
import * as path from 'path';
|
||||
import * as path from "path";
|
||||
|
||||
$injector.requirePublicClass('templateService', path.join(__dirname, 'services', 'template-service'));
|
||||
$injector.requirePublicClass("templateService", path.join(__dirname, "services", "template-service"));
|
||||
|
|
|
@ -9,7 +9,7 @@ interface ITemplateService {
|
|||
|
||||
/**
|
||||
* @description Get template's resources from the github repo
|
||||
* @param templateName
|
||||
* @param templateName <String>
|
||||
* @param asset <Object> - asset name and platform
|
||||
* @returns {Promise<any>} - Template's image recources in base64 encoding
|
||||
*/
|
||||
|
@ -17,14 +17,14 @@ interface ITemplateService {
|
|||
|
||||
/**
|
||||
* @description The method returns various meta data from template package.json
|
||||
* @param packageJson - Valid package.json
|
||||
* @param packageJson <Object> - Valid package.json
|
||||
* @returns {Promise<any>} - Template description, version, displayName, gitUrl
|
||||
*/
|
||||
getTemplateMetaData(packageJson: any): any;
|
||||
|
||||
/**
|
||||
* @description Check templates flavors E.g [@angularTs, vanillaJs, Ts ]
|
||||
* @param templateName
|
||||
* @param packageJson <Object> - Valid package.json
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
checkTemplateFlavor(packageJson: any): any;
|
||||
|
@ -44,9 +44,9 @@ interface ITemplateService {
|
|||
|
||||
/**
|
||||
* @description Download an app template in your local project folder
|
||||
* @param templateName <String>
|
||||
* @param url <String> - url to the app template repository
|
||||
*/
|
||||
downloadAppTemplate(templateName: string): void;
|
||||
downloadAppTemplate(url: string): void;
|
||||
|
||||
/**
|
||||
* @description The method returns details about a page template in JSON Format
|
||||
|
@ -57,15 +57,15 @@ interface ITemplateService {
|
|||
|
||||
/**
|
||||
* @description Create App method
|
||||
* @param appName
|
||||
* @param location
|
||||
* @param appName <String>
|
||||
* @param location <String>
|
||||
* @returns Promise
|
||||
*/
|
||||
createApp(appName: string, location: string): any;
|
||||
|
||||
/**
|
||||
* @description Add page
|
||||
* @param pageName
|
||||
* @param pageName <String>
|
||||
* @returns Promise
|
||||
*/
|
||||
addPage(pageName: string, location: string): any;
|
||||
|
|
|
@ -1,167 +1,85 @@
|
|||
import * as path from 'path';
|
||||
import * as fs from 'fs';
|
||||
import * as childProcess from 'child_process';
|
||||
import * as childProcess from "child_process";
|
||||
import * as fs from "fs";
|
||||
import * as path from "path";
|
||||
|
||||
const request = require('request-promise');
|
||||
const Config = require('../../config.js');
|
||||
const Backup = require('../../consts/backup-data');
|
||||
import { Config } from "../shared/config";
|
||||
import util from "../shared/util";
|
||||
|
||||
const request = require("request-promise");
|
||||
// tslint:disable-next-line:variable-name
|
||||
const NodeCache = require("node-cache");
|
||||
|
||||
// tslint:disable-next-line:variable-name
|
||||
const Backup = require("../../consts/backup-data");
|
||||
|
||||
const tmpCache = new NodeCache();
|
||||
const _indexof = require('lodash.indexof');
|
||||
const _sortby = require('lodash.sortby');
|
||||
|
||||
export class TemplateService implements ITemplateService {
|
||||
constructor() {
|
||||
}
|
||||
tmpPackageJsonFromSrc(templateName: string) {
|
||||
let content: any;
|
||||
|
||||
public _sortTmpData(templates: Array<any>) {
|
||||
let flavOrder: Array<string> = ['JavaScript', 'TypeScript', 'Angular & TypeScript'],
|
||||
typeOrder: Array<string> = ['Blank', 'Navigation Drawer', 'Tabs', 'Master-Detail with Firebase', 'Master-Detail with Kinvey'],
|
||||
sortedByType: Array<any>,
|
||||
sortByFlav: Array<any>;
|
||||
|
||||
sortedByType = _sortby(templates, function (temp: any) {
|
||||
return _indexof(typeOrder, temp.displayName);
|
||||
});
|
||||
|
||||
sortByFlav = _sortby(sortedByType, function (temp: any) {
|
||||
return _indexof(flavOrder, temp.templateFlavor);
|
||||
});
|
||||
|
||||
return sortByFlav;
|
||||
}
|
||||
|
||||
public _getTemplatesNames() {
|
||||
let repos: Array<any> = [
|
||||
'template-drawer-navigation',
|
||||
'template-tab-navigation',
|
||||
'template-master-detail',
|
||||
'template-blank',
|
||||
'template-drawer-navigation-ts',
|
||||
'template-master-detail-ts',
|
||||
'template-blank-ts',
|
||||
'template-tab-navigation-ts',
|
||||
'template-drawer-navigation-ng',
|
||||
'template-tab-navigation-ng',
|
||||
'template-master-detail-ng',
|
||||
'template-blank-ng',
|
||||
'template-master-detail-kinvey',
|
||||
'template-master-detail-kinvey-ng',
|
||||
'template-master-detail-kinvey-ts'
|
||||
];
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!repos || typeof repos === 'undefined') {
|
||||
reject('Error retrieving Template Name');
|
||||
} else {
|
||||
resolve(repos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public _getTmpAssetsContent(templateName: string) {
|
||||
let that = this,
|
||||
platforms: any = {};
|
||||
return request({
|
||||
method: "GET",
|
||||
uri: 'https://api.github.com/repos/NativeScript/' + templateName + '/contents/tools/assets',
|
||||
uri: util.format("https://raw.githubusercontent.com/NativeScript/%s/master/package.json", templateName),
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
headers: {
|
||||
'user-agent': 'nativescript-starter-kits'
|
||||
}
|
||||
headers: util.defaultHeaders
|
||||
})
|
||||
.then(function (res: any) {
|
||||
for (let i = 0; i < res.body.length; i++) {
|
||||
if (res.body[i].name.indexOf('phone') === -1) {
|
||||
let platform = res.body[i].name.split('-').pop().split('.').shift();
|
||||
if (platform !== 'android' || platform !== 'ios') {
|
||||
let rep = platform.match(/^(?!android|ios).*$/g);
|
||||
platform = platform.replace(rep, 'thumbnail');
|
||||
}
|
||||
|
||||
platforms[platform] = res.body[i].name;
|
||||
}
|
||||
}
|
||||
return that.tmpResourcesFromSrc(templateName, platforms);
|
||||
|
||||
})
|
||||
.catch(function (err: any) {
|
||||
return {message: 'Error retrieving assets from repository', err: err};
|
||||
});
|
||||
}
|
||||
|
||||
public tmpPackageJsonFromSrc(templateName: string) {
|
||||
let content: any;
|
||||
return request({
|
||||
method: 'GET',
|
||||
uri: 'https://raw.githubusercontent.com/NativeScript/' + templateName + '/master/package.json',
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
headers: {
|
||||
'user-agent': 'nativescript-starter-kits'
|
||||
}
|
||||
})
|
||||
.then(function (res: any) {
|
||||
content = res.body;
|
||||
if (content.hasOwnProperty('templateType')) {
|
||||
.then((response: any) => {
|
||||
content = response.body;
|
||||
if (content.hasOwnProperty("templateType")) {
|
||||
return content;
|
||||
}
|
||||
})
|
||||
.catch(function (err: any) {
|
||||
.catch((error: any) => {
|
||||
return {
|
||||
message: 'Error retrieving ' + templateName + ' package.json from src',
|
||||
err: err
|
||||
message: "Error retrieving " + templateName + " package.json from src",
|
||||
err: error
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
public tmpResourcesFromSrc(templateName: string, asset: any) {
|
||||
let content: any = {},
|
||||
promises: Array<any> = [];
|
||||
return new Promise(function (resolve, reject) {
|
||||
for (let key in asset) {
|
||||
tmpResourcesFromSrc(templateName: string, asset: any) {
|
||||
const content: any = {};
|
||||
const promises: Array<any> = [];
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
for (const key in asset) {
|
||||
if (asset.hasOwnProperty(key)) {
|
||||
promises.push(
|
||||
request({
|
||||
method: 'GET',
|
||||
uri: 'https://raw.githubusercontent.com/NativeScript/' + templateName + '/master/tools/assets/' + asset[key],
|
||||
method: "GET",
|
||||
// tslint:disable-next-line:max-line-length
|
||||
uri: util.format("https://raw.githubusercontent.com/NativeScript/%s/master/tools/assets/%s", templateName, asset[key]),
|
||||
resolveWithFullResponse: true,
|
||||
encoding: 'binary',
|
||||
headers: {
|
||||
'user-agent': 'nativescript-starter-kits'
|
||||
}
|
||||
encoding: "binary",
|
||||
headers: util.defaultHeaders
|
||||
})
|
||||
.then(function (res: any) {
|
||||
content[key] = 'data:image/png;base64,' + new Buffer(res.body.toString(), 'binary').toString('base64');
|
||||
.then((response: any) => {
|
||||
// tslint:disable-next-line:max-line-length
|
||||
content[key] = "data:image/png;base64," + new Buffer(response.body.toString(), "binary").toString("base64");
|
||||
})
|
||||
.catch(function (err: any) {
|
||||
.catch((error: any) => {
|
||||
return {
|
||||
message: 'Error retrieving ' + templateName + ' assets from source',
|
||||
err: err
|
||||
message: "Error retrieving " + templateName + " assets from source",
|
||||
err: error
|
||||
};
|
||||
}));
|
||||
|
||||
}
|
||||
}
|
||||
Promise.all(promises)
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
resolve(content);
|
||||
})
|
||||
.catch(function (err) {
|
||||
reject(err);
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public imageEncode(filePath: string) {
|
||||
let bitmap = fs.readFileSync(filePath);
|
||||
|
||||
return new Buffer(bitmap).toString('base64');
|
||||
}
|
||||
|
||||
public checkTemplateFlavor(packageJson: any) {
|
||||
return new Promise(function (resolve) {
|
||||
checkTemplateFlavor(packageJson: any) {
|
||||
return new Promise((resolve) => {
|
||||
if (packageJson.name.indexOf("-ng") > -1) {
|
||||
resolve("Angular & TypeScript");
|
||||
} else if (packageJson.name.indexOf("-ts") > -1) {
|
||||
|
@ -172,12 +90,12 @@ export class TemplateService implements ITemplateService {
|
|||
});
|
||||
}
|
||||
|
||||
public getTemplateMetaData(packageJson: any) {
|
||||
let meta: any = {};
|
||||
getTemplateMetaData(packageJson: any) {
|
||||
const meta: any = {};
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (typeof packageJson === 'undefined') {
|
||||
reject({message: 'Missing package.json'});
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof packageJson === "undefined") {
|
||||
reject({ message: "Missing package.json" });
|
||||
} else {
|
||||
meta.name = packageJson.name;
|
||||
meta.displayName = packageJson.displayName;
|
||||
|
@ -191,16 +109,15 @@ export class TemplateService implements ITemplateService {
|
|||
});
|
||||
}
|
||||
|
||||
public getAppTemplateDetails(templateName: string) {
|
||||
let that = this,
|
||||
templateDetails: any = {};
|
||||
getAppTemplateDetails(templateName: string) {
|
||||
const templateDetails: any = {};
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
that.tmpPackageJsonFromSrc(templateName)
|
||||
.then(function (pj: any) {
|
||||
let packageJson = pj;
|
||||
that.getTemplateMetaData(packageJson)
|
||||
.then(function (data: any) {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.tmpPackageJsonFromSrc(templateName)
|
||||
.then((packageJsonData: any) => {
|
||||
const packageJson = packageJsonData;
|
||||
this.getTemplateMetaData(packageJson)
|
||||
.then((data: any) => {
|
||||
templateDetails.name = data.name;
|
||||
templateDetails.displayName = data.displayName;
|
||||
templateDetails.description = data.description;
|
||||
|
@ -208,68 +125,69 @@ export class TemplateService implements ITemplateService {
|
|||
templateDetails.gitUrl = data.gitUrl;
|
||||
templateDetails.type = data.type;
|
||||
|
||||
return that.checkTemplateFlavor(packageJson);
|
||||
return this.checkTemplateFlavor(packageJson);
|
||||
})
|
||||
.then(function (flav) {
|
||||
templateDetails.templateFlavor = flav;
|
||||
return that._getTmpAssetsContent(templateName);
|
||||
.then((flavor) => {
|
||||
templateDetails.templateFlavor = flavor;
|
||||
|
||||
return this.getTmpAssetsContent(templateName);
|
||||
})
|
||||
.then(function (resources) {
|
||||
.then((resources) => {
|
||||
templateDetails.resources = resources;
|
||||
resolve(templateDetails);
|
||||
})
|
||||
.catch(function (error) {
|
||||
.catch((error) => {
|
||||
reject({
|
||||
message: 'Error retrieving data for ' + templateName,
|
||||
error: error
|
||||
message: "Error retrieving data for " + templateName,
|
||||
error
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
.catch((error: any) => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public getTemplates() {
|
||||
let that = this,
|
||||
tempDetails: Array<any> = [],
|
||||
promises: Array<any> = [];
|
||||
getTemplates() {
|
||||
let tempDetails: Array<any> = [];
|
||||
const promises: Array<any> = [];
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
tmpCache.get("tempDetails", function (err: any, value: any) {
|
||||
if (!err) {
|
||||
return new Promise((resolve, reject) => {
|
||||
tmpCache.get("tempDetails", (error: any, value: any) => {
|
||||
if (!error) {
|
||||
if (value === undefined) {
|
||||
that._getTemplatesNames()
|
||||
.then(function (repos: any) {
|
||||
return repos;
|
||||
this.getTemplatesNames()
|
||||
.then((templateNames: any) => {
|
||||
return templateNames;
|
||||
})
|
||||
.then(function (names: any) {
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
.then((names: any) => {
|
||||
names.forEach((name: string) => {
|
||||
promises.push(
|
||||
that.getAppTemplateDetails(names[i])
|
||||
.then(function (details) {
|
||||
this.getAppTemplateDetails(name)
|
||||
.then((details) => {
|
||||
tempDetails.push(details);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error);
|
||||
.catch((errorDetails) => {
|
||||
reject(errorDetails);
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
Promise.all(promises)
|
||||
.then(function () {
|
||||
tempDetails = that._sortTmpData(tempDetails);
|
||||
tmpCache.set('tempDetails', tempDetails, Config.options.cacheTime);
|
||||
.then(() => {
|
||||
tempDetails = this.sortTmpData(tempDetails);
|
||||
tmpCache.set("tempDetails", tempDetails, Config.cacheTime);
|
||||
resolve(tempDetails);
|
||||
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
.catch((errorPromises: any) => {
|
||||
// TODO Implement error logger
|
||||
resolve(Backup.fallback);
|
||||
});
|
||||
})
|
||||
.catch(function (error: any) {
|
||||
console.error(error);
|
||||
.catch((errorTemplates: any) => {
|
||||
console.error(errorTemplates);
|
||||
});
|
||||
} else {
|
||||
// Load data from cache
|
||||
|
@ -280,19 +198,19 @@ export class TemplateService implements ITemplateService {
|
|||
});
|
||||
}
|
||||
|
||||
public downloadAppTemplate(url: string) {
|
||||
let command = 'git clone ' + url,
|
||||
templatesDir = __dirname.replace('services', 'templates'), // Temp hack
|
||||
exists;
|
||||
downloadAppTemplate(url: string) {
|
||||
const command = "git clone " + url;
|
||||
const templatesDir = __dirname.replace("services", "templates"); // Temp hack
|
||||
let folderStats;
|
||||
|
||||
try {
|
||||
exists = fs.statSync(templatesDir);
|
||||
folderStats = fs.statSync(templatesDir);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
childProcess.exec(command, {cwd: templatesDir}, function (error, stdout, stderr) {
|
||||
if (folderStats) {
|
||||
childProcess.exec(command, { cwd: templatesDir }, (error, stdout, stderr) => {
|
||||
if (error) {
|
||||
console.error(error);
|
||||
} else if (stderr) {
|
||||
|
@ -302,32 +220,32 @@ export class TemplateService implements ITemplateService {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
console.error('Missing templates directory');
|
||||
console.error("Missing templates directory");
|
||||
}
|
||||
}
|
||||
|
||||
public getPageTemplateDetails(templateName: string) {
|
||||
let version: string,
|
||||
flavor: string,
|
||||
description: string,
|
||||
templateDetails: any;
|
||||
getPageTemplateDetails(templateName: string) {
|
||||
const version: string = "";
|
||||
const flavor: string = "";
|
||||
const description: string = "";
|
||||
let templateDetails: any;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
//version = that.getTemplateVersion(templateName);
|
||||
//flavor = that.checkTemplateFlavor(templateName);
|
||||
//description = that.getTemplateDescription(templateName);
|
||||
// version = that.getTemplateVersion(templateName);
|
||||
// flavor = that.checkTemplateFlavor(templateName);
|
||||
// description = that.getTemplateDescription(templateName);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
templateDetails = {
|
||||
name: templateName,
|
||||
description: description,
|
||||
version: version,
|
||||
description,
|
||||
version,
|
||||
templateFlavor: flavor,
|
||||
gitUrl: 'https://github.com/NativeScript/template-drawer-navigation-ts.git',
|
||||
type: 'Page template',
|
||||
gitUrl: "https://github.com/NativeScript/template-drawer-navigation-ts.git",
|
||||
type: "Page template",
|
||||
resources: []
|
||||
};
|
||||
|
||||
|
@ -336,49 +254,116 @@ export class TemplateService implements ITemplateService {
|
|||
});
|
||||
}
|
||||
|
||||
public createApp(appName: string, location: string) {
|
||||
let appPath: string = path.join(location, appName);
|
||||
createApp(appName: string, location: string) {
|
||||
const appPath: string = path.join(location, appName);
|
||||
|
||||
//TODO: Check if path is a valid system path!!!
|
||||
return new Promise(function (resolve, reject) {
|
||||
fs.mkdir(appPath, '0744', function (err) {
|
||||
if (err && err.code === 'EEXIST') {
|
||||
// TODO: Check if path is a valid system path!!!
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.mkdir(appPath, "0744", (err) => {
|
||||
if (err && err.code === "EEXIST") {
|
||||
reject({
|
||||
message: appName + ' App already exists',
|
||||
message: appName + " App already exists",
|
||||
error: err
|
||||
});
|
||||
} else {
|
||||
resolve({
|
||||
message: 'Successfully created ' + appName + ' App',
|
||||
appPath: appPath
|
||||
message: "Successfully created " + appName + " App",
|
||||
appPath
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public addPage(pageName: string, location: string) {
|
||||
let pagePath: string = path.join(location, pageName),
|
||||
exists: any;
|
||||
addPage(pageName: string, location: string) {
|
||||
const pagePath: string = path.join(location, pageName);
|
||||
let dolderStatsexists: any;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
exists = fs.statSync(location);
|
||||
dolderStatsexists = fs.statSync(location);
|
||||
} catch (err) {
|
||||
reject(err);
|
||||
}
|
||||
|
||||
if (!exists.isDirectory()) {
|
||||
reject({message: 'Invalid Path'});
|
||||
if (!dolderStatsexists.isDirectory()) {
|
||||
reject({ message: "Invalid Path" });
|
||||
} else {
|
||||
// TODO: add Page logic here
|
||||
resolve({
|
||||
message: 'Page' + pageName + ' added successfully!',
|
||||
pagePath: pagePath
|
||||
message: "Page" + pageName + " added successfully!",
|
||||
pagePath
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private sortTmpData(templates: Array<any>) {
|
||||
const flavOrder: Array<string> = ["JavaScript", "TypeScript", "Angular & TypeScript"];
|
||||
|
||||
// tslint:disable-next-line:max-line-length
|
||||
const typeOrder: Array<string> = ["Blank", "Navigation Drawer", "Tabs", "Master-Detail with Firebase", "Master-Detail with Kinvey"];
|
||||
let sortedByType: Array<any>;
|
||||
let sortByFlav: Array<any>;
|
||||
|
||||
sortedByType = util.sortBy(templates, (temp: any) => {
|
||||
return util.indexOf(typeOrder, temp.displayName);
|
||||
});
|
||||
|
||||
sortByFlav = util.sortBy(sortedByType, (temp: any) => {
|
||||
return util.indexOf(flavOrder, temp.templateFlavor);
|
||||
});
|
||||
|
||||
return sortByFlav;
|
||||
}
|
||||
|
||||
private getTemplatesNames() {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!Config.availableTemplateRepos || !Config.availableTemplateRepos.length) {
|
||||
reject("No available repositories found");
|
||||
} else {
|
||||
resolve(Config.availableTemplateRepos);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getTmpAssetsContent(templateName: string) {
|
||||
const platforms: any = {};
|
||||
|
||||
return request({
|
||||
method: "GET",
|
||||
uri: util.format("https://api.github.com/repos/NativeScript/%s/contents/tools/assets", templateName),
|
||||
json: true,
|
||||
resolveWithFullResponse: true,
|
||||
headers: util.defaultHeaders
|
||||
})
|
||||
.then((response: any) => {
|
||||
response.body.forEach((element: any) => {
|
||||
if (element.name.indexOf("phone") === -1) {
|
||||
let platform = element.name.split("-").pop().split(".").shift();
|
||||
if (platform !== "android" || platform !== "ios") {
|
||||
const rep = platform.match(/^(?!android|ios).*$/g);
|
||||
platform = platform.replace(rep, "thumbnail");
|
||||
}
|
||||
|
||||
platforms[platform] = element.name;
|
||||
}
|
||||
});
|
||||
|
||||
return this.tmpResourcesFromSrc(templateName, platforms);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
return { message: "Error retrieving assets from repository", error };
|
||||
});
|
||||
}
|
||||
|
||||
// Temporary unused method
|
||||
// private imageEncode(filePath: string) {
|
||||
// let bitmap = fs.readFileSync(filePath);
|
||||
|
||||
// return new Buffer(bitmap).toString('base64');
|
||||
// }
|
||||
}
|
||||
|
||||
$injector.register('templateService', TemplateService);
|
||||
$injector.register("templateService", TemplateService);
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
export class Config {
|
||||
static cacheTime = 3600;
|
||||
static orgBaseUrl = "https://api.github.com/orgs/NativeScript/repos?per_page=100";
|
||||
|
||||
static availableTemplateRepos: Array<any> = [
|
||||
"template-drawer-navigation",
|
||||
"template-tab-navigation",
|
||||
"template-master-detail",
|
||||
"template-blank",
|
||||
"template-drawer-navigation-ts",
|
||||
"template-master-detail-ts",
|
||||
"template-blank-ts",
|
||||
"template-tab-navigation-ts",
|
||||
"template-drawer-navigation-ng",
|
||||
"template-tab-navigation-ng",
|
||||
"template-master-detail-ng",
|
||||
"template-blank-ng",
|
||||
"template-master-detail-kinvey",
|
||||
"template-master-detail-kinvey-ng",
|
||||
"template-master-detail-kinvey-ts"
|
||||
];
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
import * as nodeUtil from "util";
|
||||
|
||||
const indexOf = require("lodash.indexof");
|
||||
const sortBy = require("lodash.sortby");
|
||||
|
||||
export default class Util {
|
||||
static defaultHeaders = {
|
||||
"user-agent": "nativescript-starter-kits"
|
||||
};
|
||||
|
||||
static indexOf = indexOf;
|
||||
static sortBy = sortBy;
|
||||
static format = nodeUtil.format;
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
"description": "CLI extension for the NatvieScript CLI",
|
||||
"main": "lib/bootstrap.js",
|
||||
"scripts": {
|
||||
"lint": "tslint \"lib/**/*.ts\"",
|
||||
"test": "node_modules/.bin/istanbul cover node_modules/mocha/bin/_mocha -- --recursive --reporter spec-xunit-file --require test/test-bootstrap.js --timeout 1000 test/"
|
||||
},
|
||||
"repository": {
|
||||
|
@ -32,7 +33,7 @@
|
|||
"grunt-contrib-watch": "1.0.0",
|
||||
"grunt-shell": "1.3.0",
|
||||
"grunt-ts": "6.0.0-beta.11",
|
||||
"grunt-tslint": "4.0.1",
|
||||
"grunt-tslint": "5.0.1",
|
||||
"istanbul": "0.4.5",
|
||||
"mobile-cli-lib": "https://github.com/telerik/mobile-cli-lib/tarball/master",
|
||||
"mocha": "3.1.2",
|
||||
|
@ -40,7 +41,7 @@
|
|||
"nativescript": "https://github.com/NativeScript/nativescript-cli/tarball/master",
|
||||
"should": "7.0.2",
|
||||
"spec-xunit-file": "0.0.1-3",
|
||||
"tslint": "4.3.1",
|
||||
"tslint": "5.6.0",
|
||||
"typescript": "2.1.5"
|
||||
},
|
||||
"dependencies": {
|
||||
|
@ -50,5 +51,4 @@
|
|||
"request": "^2.81.0",
|
||||
"request-promise": "^4.2.1"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
import {TemplateService} from "../lib/services/template-service";
|
||||
import {Yok} from "mobile-cli-lib/yok";
|
||||
import { Yok } from "mobile-cli-lib/yok";
|
||||
import { TemplateService } from "../lib/services/template-service";
|
||||
|
||||
const chai = require("chai");
|
||||
const should = require("chai").should();
|
||||
|
@ -9,15 +9,15 @@ chai.use(require("chai-things"));
|
|||
let testInjector: any;
|
||||
|
||||
describe("TemplateService Api", () => {
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
testInjector = new Yok();
|
||||
testInjector.register("templateService", TemplateService);
|
||||
});
|
||||
|
||||
describe("Check template flavor", function () {
|
||||
let templateService = new TemplateService();
|
||||
it("Returns a template flavor", function () {
|
||||
let flavor = templateService.checkTemplateFlavor({});
|
||||
describe("Check template flavor", () => {
|
||||
const templateService = new TemplateService();
|
||||
it("Returns a template flavor", () => {
|
||||
const flavor = templateService.checkTemplateFlavor({});
|
||||
|
||||
flavor.should.be.a("string");
|
||||
flavor.should.not.be.an("object");
|
||||
|
@ -25,8 +25,8 @@ describe("TemplateService Api", () => {
|
|||
flavor.should.not.be.instanceOf(Error);
|
||||
});
|
||||
|
||||
it("handles errors gracefully ", function () {
|
||||
let flavor = templateService.checkTemplateFlavor({});
|
||||
it("handles errors gracefully ", () => {
|
||||
const flavor = templateService.checkTemplateFlavor({});
|
||||
|
||||
flavor.should.be.instanceOf(Error);
|
||||
flavor.should.not.be.a("string");
|
||||
|
@ -36,10 +36,10 @@ describe("TemplateService Api", () => {
|
|||
|
||||
});
|
||||
|
||||
describe("Get App template Details", function () {
|
||||
let templateService = new TemplateService();
|
||||
it("Returns a Template Details object via a Promise", function () {
|
||||
templateService.getAppTemplateDetails("template-hello-world-ng").then(function (details) {
|
||||
describe("Get App template Details", () => {
|
||||
const templateService = new TemplateService();
|
||||
it("Returns a Template Details object via a Promise", () => {
|
||||
templateService.getAppTemplateDetails("template-hello-world-ng").then((details) => {
|
||||
should.exist(details);
|
||||
details.should.be.an("object");
|
||||
details.should.have.property("name");
|
||||
|
@ -48,25 +48,25 @@ describe("TemplateService Api", () => {
|
|||
details.should.have.property("templateFlavor");
|
||||
details.should.not.be.instanceOf(Error);
|
||||
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
should.not.exist(err);
|
||||
});
|
||||
});
|
||||
|
||||
it("It handles error trough Promise Reject", function () {
|
||||
templateService.getAppTemplateDetails("template-hello-world-ng").then(function (details) {
|
||||
it("It handles error trough Promise Reject", () => {
|
||||
templateService.getAppTemplateDetails("template-hello-world-ng").then((details) => {
|
||||
should.not.exist(details);
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
should.exist(err);
|
||||
err.should.be.instanceOf(Error);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Get Available templates", function () {
|
||||
let templateService = new TemplateService();
|
||||
it("Returns a Template Details array for all available templates", function () {
|
||||
templateService.getTemplates().then(function (templates) {
|
||||
describe("Get Available templates", () => {
|
||||
const templateService = new TemplateService();
|
||||
it("Returns a Template Details array for all available templates", () => {
|
||||
templateService.getTemplates().then((templates) => {
|
||||
should.exist(templates);
|
||||
templates.should.be.an("array");
|
||||
|
||||
|
@ -75,7 +75,7 @@ describe("TemplateService Api", () => {
|
|||
templates.should.contain.a.thing.with.property("description");
|
||||
templates.should.contain.a.thing.with.property("templateFlavor");*/
|
||||
|
||||
}).catch(function (err) {
|
||||
}).catch((err) => {
|
||||
should.not.exist(err);
|
||||
});
|
||||
});
|
||||
|
|
77
tslint.json
77
tslint.json
|
@ -1,62 +1,47 @@
|
|||
{
|
||||
"extends": "tslint:latest",
|
||||
"rules": {
|
||||
"class-name": true,
|
||||
"curly": true,
|
||||
"eofline": true,
|
||||
"indent": [
|
||||
"array-type": [
|
||||
true,
|
||||
"spaces"
|
||||
"generic"
|
||||
],
|
||||
"interface-name": true,
|
||||
"jsdoc-format": true,
|
||||
"max-line-length": [
|
||||
false,
|
||||
140
|
||||
"arrow-return-shorthand": true,
|
||||
"member-access": [
|
||||
true,
|
||||
"no-public"
|
||||
],
|
||||
"no-consecutive-blank-lines": true,
|
||||
"no-construct": true,
|
||||
"no-debugger": true,
|
||||
"no-duplicate-variable": true,
|
||||
"no-shadowed-variable": true,
|
||||
"no-empty": false,
|
||||
"no-eval": true,
|
||||
"no-switch-case-fall-through": true,
|
||||
"no-trailing-whitespace": true,
|
||||
"no-unused-expression": true,
|
||||
"no-use-before-declare": true,
|
||||
"no-var-keyword": true,
|
||||
"newline-before-return": true,
|
||||
"no-angle-bracket-type-assertion": false,
|
||||
"no-consecutive-blank-lines": [
|
||||
true,
|
||||
1
|
||||
],
|
||||
"no-console": [
|
||||
false
|
||||
],
|
||||
"no-irregular-whitespace": true,
|
||||
"no-unnecessary-initializer": true,
|
||||
"no-var-requires": false,
|
||||
"one-line": [
|
||||
"object-literal-key-quotes": [
|
||||
true,
|
||||
"check-catch",
|
||||
"check-finally",
|
||||
"check-else",
|
||||
"check-open-brace",
|
||||
"check-whitespace"
|
||||
"as-needed"
|
||||
],
|
||||
"quotemark": [
|
||||
false,
|
||||
"double"
|
||||
"object-literal-sort-keys": false,
|
||||
"one-variable-per-declaration": [
|
||||
true,
|
||||
"ignore-for-loop"
|
||||
],
|
||||
"semicolon": true,
|
||||
"space-before-function-paren": false,
|
||||
"switch-default": false,
|
||||
"trailing-comma": [
|
||||
false,
|
||||
true,
|
||||
{
|
||||
"multiline": "always",
|
||||
"singleline": "always"
|
||||
"multiline": "never",
|
||||
"singleline": "never"
|
||||
}
|
||||
],
|
||||
"triple-equals": [
|
||||
true,
|
||||
"allow-null-check"
|
||||
],
|
||||
"typeof-compare": true,
|
||||
"use-isnan": true,
|
||||
"variable-name": [
|
||||
true,
|
||||
"ban-keywords",
|
||||
"check-format",
|
||||
"allow-leading-underscore"
|
||||
],
|
||||
"whitespace": [
|
||||
|
@ -65,7 +50,9 @@
|
|||
"check-decl",
|
||||
"check-operator",
|
||||
"check-module",
|
||||
"check-separator"
|
||||
"check-separator",
|
||||
"check-type",
|
||||
"check-preblock"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче