arylo-init
Advanced tools
Comparing version 2.1.4 to 2.1.5
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const path = require("path"); | ||
const constants = require("../constants"); | ||
const json = require("../utils/json"); | ||
const pkg_1 = require("../utils/pkg"); | ||
exports.ADD_LIST = [".lintstagedrc", ".huskyrc.json"]; | ||
@@ -12,14 +11,16 @@ exports.UPDATE_LIST = ["package.json"]; | ||
} | ||
const filePath = path.resolve(constants.targetPath, filePoint); | ||
const data = json.read(filePath); | ||
if (!data.keywords) { | ||
data.keywords = []; | ||
} | ||
if (data.keywords.indexOf("typescript") === -1) { | ||
data.keywords.push("typescript"); | ||
} | ||
data.devDependencies.husky = "^1.1.2"; | ||
data.devDependencies["lint-staged"] = "^7.3.0"; | ||
data.devDependencies.prettier = "^1.14.3"; | ||
json.write(filePath, data); | ||
new pkg_1.Pkg(constants.targetPath) | ||
.modify((obj) => { | ||
if (!obj.keywords) { | ||
obj.keywords = []; | ||
} | ||
if (obj.keywords.indexOf("typescript") === -1) { | ||
obj.keywords.push("typescript"); | ||
} | ||
return obj; | ||
}) | ||
.updateDevDependencies("husky", "^1.1.2") | ||
.updateDevDependencies("lint-staged", "^7.3.0") | ||
.updateDevDependencies("prettier", "^1.14.3") | ||
.save(); | ||
}; |
@@ -20,1 +20,18 @@ "use strict"; | ||
}; | ||
class Json { | ||
constructor(p) { | ||
this.filePath = p.toString(); | ||
this.object = exports.read(this.filePath); | ||
} | ||
modify(fn) { | ||
this.object = fn(this.object); | ||
return this; | ||
} | ||
save() { | ||
return exports.write(this.filePath, this.object); | ||
} | ||
toObject() { | ||
return this.object; | ||
} | ||
} | ||
exports.Json = Json; |
@@ -13,1 +13,40 @@ "use strict"; | ||
}; | ||
class Pkg extends json.Json { | ||
constructor(p) { | ||
super(path.resolve(p.toString(), "package.json")); | ||
} | ||
getSaveDependencies(name) { | ||
return this.object.dependencies[name]; | ||
} | ||
updateSaveDependencies(name, version) { | ||
this.object.dependencies[name] = version; | ||
return this; | ||
} | ||
deleteSaveDependencies(name) { | ||
delete this.object.dependencies[name]; | ||
return this; | ||
} | ||
getDevDependencies(name) { | ||
return this.object.devDependencies[name]; | ||
} | ||
updateDevDependencies(name, version) { | ||
this.object.devDependencies[name] = version; | ||
return this; | ||
} | ||
deleteDevDependencies(name) { | ||
delete this.object.devDependencies[name]; | ||
return this; | ||
} | ||
getScript(action) { | ||
return this.object.scripts[action]; | ||
} | ||
updateScript(action, command) { | ||
this.object.scripts[action] = command; | ||
return this; | ||
} | ||
deleteScript(action) { | ||
delete this.object.scripts[action]; | ||
return this; | ||
} | ||
} | ||
exports.Pkg = Pkg; |
@@ -1,4 +0,3 @@ | ||
import * as path from "path"; | ||
import constants = require("../constants"); | ||
import * as json from "../utils/json"; | ||
import { Pkg } from "../utils/pkg"; | ||
@@ -12,16 +11,16 @@ export const ADD_LIST = [".lintstagedrc", ".huskyrc.json"]; | ||
} | ||
const filePath = path.resolve(constants.targetPath, filePoint); | ||
const data = json.read(filePath); | ||
if (!data.keywords) { | ||
data.keywords = []; | ||
} | ||
if (data.keywords.indexOf("typescript") === -1) { | ||
data.keywords.push("typescript"); | ||
} | ||
data.devDependencies.husky = "^1.1.2"; | ||
data.devDependencies["lint-staged"] = "^7.3.0"; | ||
data.devDependencies.prettier = "^1.14.3"; | ||
json.write(filePath, data); | ||
new Pkg(constants.targetPath) | ||
.modify((obj) => { | ||
if (!obj.keywords) { | ||
obj.keywords = []; | ||
} | ||
if (obj.keywords.indexOf("typescript") === -1) { | ||
obj.keywords.push("typescript"); | ||
} | ||
return obj; | ||
}) | ||
.updateDevDependencies("husky", "^1.1.2") | ||
.updateDevDependencies("lint-staged", "^7.3.0") | ||
.updateDevDependencies("prettier", "^1.14.3") | ||
.save(); | ||
}; |
@@ -19,1 +19,22 @@ import * as fs from "fs"; | ||
}; | ||
export class Json<T extends { [name: string]: any } = any> { | ||
protected filePath: string; | ||
protected object: T; | ||
constructor(p: fs.PathLike) { | ||
this.filePath = p.toString(); | ||
this.object = read(this.filePath); | ||
} | ||
public modify(fn: (obj: T) => T) { | ||
this.object = fn(this.object); | ||
return this; | ||
} | ||
public save() { | ||
return write(this.filePath, this.object); | ||
} | ||
public toObject() { | ||
return this.object; | ||
} | ||
} |
@@ -5,3 +5,26 @@ import * as fs from "fs"; | ||
export const read = (p: fs.PathLike) => { | ||
interface IPkgObj { | ||
name: string; | ||
version: string; | ||
description: string; | ||
main: string; | ||
author: string; | ||
homepage?: string; | ||
yVersion: string; | ||
license: string; | ||
keywords: string[]; | ||
files: string[]; | ||
scripts?: { | ||
[name: string]: string; | ||
}; | ||
dependencies?: { | ||
[name: string]: string; | ||
}; | ||
devDependencies?: { | ||
[name: string]: string; | ||
}; | ||
[key: string]: any; | ||
} | ||
export const read = (p: fs.PathLike): IPkgObj => { | ||
const filePath = path.resolve(p.toString(), "package.json"); | ||
@@ -15,1 +38,49 @@ return json.read(filePath); | ||
}; | ||
export class Pkg extends json.Json<IPkgObj> { | ||
constructor(p: fs.PathLike) { | ||
super(path.resolve(p.toString(), "package.json")); | ||
} | ||
public getSaveDependencies(name: string) { | ||
return this.object.dependencies[name]; | ||
} | ||
public updateSaveDependencies(name: string, version: string) { | ||
this.object.dependencies[name] = version; | ||
return this; | ||
} | ||
public deleteSaveDependencies(name: string) { | ||
delete this.object.dependencies[name]; | ||
return this; | ||
} | ||
public getDevDependencies(name: string) { | ||
return this.object.devDependencies[name]; | ||
} | ||
public updateDevDependencies(name: string, version: string) { | ||
this.object.devDependencies[name] = version; | ||
return this; | ||
} | ||
public deleteDevDependencies(name: string) { | ||
delete this.object.devDependencies[name]; | ||
return this; | ||
} | ||
public getScript(action: string) { | ||
return this.object.scripts[action]; | ||
} | ||
public updateScript(action: string, command: string) { | ||
this.object.scripts[action] = command; | ||
return this; | ||
} | ||
public deleteScript(action: string) { | ||
delete this.object.scripts[action]; | ||
return this; | ||
} | ||
} |
{ | ||
"name": "arylo-init", | ||
"version": "2.1.4", | ||
"version": "2.1.5", | ||
"description": "Initial Node.js Project for Arylo Edition", | ||
@@ -55,5 +55,8 @@ "main": "./dist/index.js", | ||
"@types/node": "^10.1.2", | ||
"@types/request": "^2.47.1", | ||
"@types/request-promise-native": "^1.0.15", | ||
"@types/rimraf": "^2.0.2", | ||
"@types/update-notifier": "^2.2.0", | ||
"ava": "^0.25.0", | ||
"dtss": "^1.0.1", | ||
"eslint": "^4.19.1", | ||
@@ -70,2 +73,4 @@ "eslint-config-standard": "^11.0.0", | ||
"prettier": "^1.14.3", | ||
"request": "^2.88.0", | ||
"request-promise-native": "^1.0.5", | ||
"tslint": "^5.10.0", | ||
@@ -72,0 +77,0 @@ "typescript": "^3.1.3", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56813
57
1321
26