Comparing version 1.0.0 to 1.1.0
import { Options } from './cli'; | ||
import { PackageJson } from '@npm/types'; | ||
export interface Bag<T> { | ||
[script: string]: T; | ||
} | ||
export declare function addScripts(packageJson: PackageJson, options: Options): Promise<boolean>; | ||
@@ -14,2 +11,3 @@ export declare function addDependencies(packageJson: PackageJson, options: Options): Promise<boolean>; | ||
}; | ||
export declare function installDefaultTemplate(options: Options): Promise<boolean>; | ||
export declare function init(options: Options): Promise<boolean>; |
@@ -19,7 +19,11 @@ "use strict"; | ||
const cp = require("child_process"); | ||
const fs = require("fs"); | ||
const inquirer = require("inquirer"); | ||
const path = require("path"); | ||
const ncp_1 = require("ncp"); | ||
const util = require("util"); | ||
const util_1 = require("./util"); | ||
const chalk_1 = require("chalk"); | ||
const pkg = require('../../package.json'); | ||
const ncpp = util.promisify(ncp_1.ncp); | ||
const DEFAULT_PACKAGE_JSON = { | ||
@@ -56,3 +60,3 @@ name: '', | ||
let edits = false; | ||
const pkgManager = util_1.getPkgManagerName(options.yarn); | ||
const pkgManager = util_1.getPkgManagerCommand(options.yarn); | ||
const scripts = { | ||
@@ -94,2 +98,3 @@ check: `gts check`, | ||
typescript: pkg.devDependencies.typescript, | ||
'@types/node': pkg.devDependencies['@types/node'], | ||
}; | ||
@@ -184,2 +189,28 @@ if (!packageJson.devDependencies) { | ||
} | ||
async function installDefaultTemplate(options) { | ||
const cwd = process.cwd(); | ||
const sourceDirName = path.join(__dirname, '../template'); | ||
const targetDirName = path.join(cwd, 'src'); | ||
try { | ||
fs.mkdirSync(targetDirName); | ||
} | ||
catch (error) { | ||
if (error.code !== 'EEXIST') { | ||
throw error; | ||
} | ||
// Else, continue and populate files into the existing directory. | ||
} | ||
// Only install the template if no ts files exist in target directory. | ||
const files = fs.readdirSync(targetDirName); | ||
const tsFiles = files.filter(file => file.toLowerCase().endsWith('.ts')); | ||
if (tsFiles.length !== 0) { | ||
options.logger.log('Target src directory already has ts files. ' + | ||
'Template files not installed.'); | ||
return false; | ||
} | ||
await ncpp(sourceDirName, targetDirName); | ||
options.logger.log('Default template installed.'); | ||
return true; | ||
} | ||
exports.installDefaultTemplate = installDefaultTemplate; | ||
async function init(options) { | ||
@@ -214,2 +245,3 @@ let generatedPackageJson = false; | ||
await generatePrettierConfig(options); | ||
await installDefaultTemplate(options); | ||
// Run `npm install` after initial setup so `npm run check` works right away. | ||
@@ -219,3 +251,3 @@ if (!options.dryRun) { | ||
// source files yet. | ||
cp.spawnSync(util_1.getPkgManagerName(options.yarn), ['install', '--ignore-scripts'], { stdio: 'inherit' }); | ||
cp.spawnSync(util_1.getPkgManagerCommand(options.yarn), ['install', '--ignore-scripts'], { stdio: 'inherit' }); | ||
} | ||
@@ -222,0 +254,0 @@ return true; |
@@ -60,14 +60,14 @@ "use strict"; | ||
const configuration = tslint_1.Configuration.loadConfigurationFromPath(configPath); | ||
const linter = new tslint_1.Linter({ fix, formatter: 'codeFrame' }, program); | ||
files.forEach(file => { | ||
for (const file of files) { | ||
const sourceFile = program.getSourceFile(file); | ||
if (sourceFile) { | ||
const fileContents = sourceFile.getFullText(); | ||
const linter = new tslint_1.Linter({ fix, formatter: 'codeFrame' }, program); | ||
linter.lint(file, fileContents, configuration); | ||
const result = linter.getResult(); | ||
if (result.errorCount || result.warningCount) { | ||
options.logger.log(result.output); | ||
return false; | ||
} | ||
} | ||
}); | ||
const result = linter.getResult(); | ||
if (result.errorCount || result.warningCount) { | ||
options.logger.log(result.output); | ||
return false; | ||
} | ||
@@ -74,0 +74,0 @@ return true; |
@@ -18,5 +18,15 @@ /** | ||
import * as fs from 'fs'; | ||
export declare const readFilep: (...args: any[]) => Promise<any>; | ||
export declare const rimrafp: (...args: any[]) => Promise<any>; | ||
export declare const writeFileAtomicp: any; | ||
import * as rimraf from 'rimraf'; | ||
export declare const readFilep: typeof fs.readFile.__promisify__; | ||
export declare const rimrafp: typeof rimraf.__promisify__; | ||
export declare const writeFileAtomicp: Function; | ||
export declare const ncpp: (arg1: string, arg2: string) => Promise<void>; | ||
export interface Bag<T> { | ||
[script: string]: T; | ||
} | ||
export interface DefaultPackage extends Bag<string> { | ||
gts: string; | ||
typescript: string; | ||
'@types/node': string; | ||
} | ||
export declare function readJsonp(jsonPath: string): Promise<any>; | ||
@@ -51,2 +61,2 @@ export interface ReadFileP { | ||
export declare function isYarnUsed(existsSync?: typeof fs.existsSync): boolean; | ||
export declare function getPkgManagerName(isYarnUsed?: boolean): 'yarn' | 'npm'; | ||
export declare function getPkgManagerCommand(isYarnUsed?: boolean): string; |
@@ -20,9 +20,12 @@ "use strict"; | ||
const path = require("path"); | ||
const pify = require("pify"); | ||
const rimraf = require("rimraf"); | ||
exports.readFilep = pify(fs.readFile); | ||
exports.rimrafp = pify(rimraf); | ||
exports.writeFileAtomicp = pify(require('write-file-atomic')); | ||
const util_1 = require("util"); | ||
const ncp = require("ncp"); | ||
exports.readFilep = util_1.promisify(fs.readFile); | ||
exports.rimrafp = util_1.promisify(rimraf); | ||
exports.writeFileAtomicp = util_1.promisify(require('write-file-atomic')); | ||
exports.ncpp = util_1.promisify(ncp.ncp); | ||
async function readJsonp(jsonPath) { | ||
return JSON.parse(await exports.readFilep(jsonPath)); | ||
const contents = await exports.readFilep(jsonPath, { encoding: 'utf8' }); | ||
return JSON.parse(contents); | ||
} | ||
@@ -102,6 +105,6 @@ exports.readJsonp = readJsonp; | ||
exports.isYarnUsed = isYarnUsed; | ||
function getPkgManagerName(isYarnUsed) { | ||
return isYarnUsed ? 'yarn' : 'npm'; | ||
function getPkgManagerCommand(isYarnUsed) { | ||
return ((isYarnUsed ? 'yarn' : 'npm') + (process.platform === 'win32' ? '.cmd' : '')); | ||
} | ||
exports.getPkgManagerName = getPkgManagerName; | ||
exports.getPkgManagerCommand = getPkgManagerCommand; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "gts", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Google TypeScript Style", | ||
@@ -16,5 +16,7 @@ "repository": "google/gts", | ||
"build/types", | ||
"build/template", | ||
"prettier.config.js", | ||
"tsconfig-google.json", | ||
"tsconfig.json", | ||
"tslint-rules.json", | ||
"tslint.json" | ||
@@ -25,4 +27,5 @@ ], | ||
"clean": "rimraf ./build/", | ||
"codecov": "nyc report --reporter=json && codecov -f coverage/*.json", | ||
"codecov": "c8 report --reporter=json && codecov -f coverage/*.json", | ||
"compile": "tsc -p .", | ||
"postcompile": "ncp template build/template", | ||
"format-check": "prettier --list-different src/*.ts test/*.ts", | ||
@@ -33,6 +36,8 @@ "format": "prettier --write src/*.ts test/*.ts", | ||
"prepare": "npm run compile", | ||
"test": "nyc mocha build/test", | ||
"test": "c8 mocha build/test", | ||
"pretest": "npm run compile", | ||
"posttest": "npm run lint && npm run format-check && npm run license-check", | ||
"license-check": "jsgl --local ." | ||
"license-check": "jsgl --local .", | ||
"check": "gts check", | ||
"fix": "gts fix" | ||
}, | ||
@@ -48,10 +53,10 @@ "engines": { | ||
"diff": "^4.0.1", | ||
"entities": "^1.1.1", | ||
"inquirer": "^6.0.0", | ||
"meow": "^5.0.0", | ||
"pify": "^4.0.0", | ||
"ncp": "^2.0.0", | ||
"prettier": "^1.15.3", | ||
"rimraf": "^2.6.2", | ||
"tslint": "^5.12.0", | ||
"update-notifier": "^2.5.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"update-notifier": "^3.0.0", | ||
"write-file-atomic": "^2.3.0" | ||
@@ -61,6 +66,5 @@ }, | ||
"@npm/types": "^1.0.1", | ||
"@types/cross-spawn": "^6.0.0", | ||
"@types/diff": "^4.0.0", | ||
"@types/entities": "^1.1.0", | ||
"@types/execa": "^0.9.0", | ||
"@types/glob": "^7.0.0", | ||
"@types/fs-extra": "^8.0.0", | ||
"@types/inquirer": "^6.0.0", | ||
@@ -71,17 +75,20 @@ "@types/meow": "^5.0.0", | ||
"@types/node": "^10.0.3", | ||
"@types/pify": "^3.0.2", | ||
"@types/prettier": "^1.15.2", | ||
"@types/rimraf": "^2.0.2", | ||
"@types/sinon": "^7.0.11", | ||
"@types/tmp": "^0.1.0", | ||
"@types/update-notifier": "^2.2.0", | ||
"assert-rejects": "^1.0.0", | ||
"c8": "^5.0.0", | ||
"codecov": "^3.0.1", | ||
"execa": "^1.0.0", | ||
"inline-fixtures": "^1.0.0", | ||
"js-green-licenses": "^0.5.0", | ||
"cross-spawn": "^6.0.5", | ||
"fs-extra": "^8.0.0", | ||
"gts": "^1.0.0", | ||
"inline-fixtures": "^1.1.0", | ||
"js-green-licenses": "^1.0.0", | ||
"mocha": "^6.0.0", | ||
"ncp": "^2.0.0", | ||
"nyc": "^14.0.0", | ||
"sinon": "^7.3.1", | ||
"source-map-support": "^0.5.5", | ||
"tmp": "0.1.0", | ||
"typescript": "~3.4.0" | ||
"typescript": "~3.5.0" | ||
}, | ||
@@ -88,0 +95,0 @@ "peerDependencies": { |
@@ -11,4 +11,2 @@ # gts | ||
**NOTE: THIS README refers to the master branch which corresponds to the upcoming 1.0 release. To view documentation for the currently released version of this module see: https://github.com/google/gts/tree/v0.9.x.** | ||
[gts][npm-url] is Google's TypeScript style guide, and the configuration for our formatter, linter, and automatic code fixer. No lint rules to edit, no configuration to update, no more bike shedding over syntax. | ||
@@ -41,2 +39,3 @@ | ||
- `pretest`, `posttest` and `prepare`: convenience integrations. | ||
- If a source folder is not already present it will add a default template project. | ||
@@ -43,0 +42,0 @@ ### Individual files |
@@ -12,4 +12,5 @@ { | ||
"exclude": [ | ||
"test/fixtures/**/*.*" | ||
"test/fixtures/**/*.*", | ||
"template/**/*.*", | ||
] | ||
} | ||
} |
{ | ||
"rules": { | ||
"array-type": [true, "array-simple"], | ||
"arrow-return-shorthand": true, | ||
"ban": [true, | ||
{"name": ["it", "skip"]}, | ||
{"name": ["it", "only"]}, | ||
{"name": ["it", "async", "skip"]}, | ||
{"name": ["it", "async", "only"]}, | ||
{"name": ["describe", "skip"]}, | ||
{"name": ["describe", "only"]}, | ||
{"name": "parseInt", "message": "tsstyle#type-coercion"}, | ||
{"name": "parseFloat", "message": "tsstyle#type-coercion"}, | ||
{"name": "Array", "message": "tsstyle#array-constructor"}, | ||
{"name": ["*", "innerText"], "message": "Use .textContent instead. tsstyle#browser-oddities"} | ||
], | ||
"ban-ts-ignore": true, | ||
"ban-types": [true, | ||
["Object", "Use {} instead."], | ||
["String", "Use 'string' instead."], | ||
["Number", "Use 'number' instead."], | ||
["Boolean", "Use 'boolean' instead."] | ||
], | ||
"class-name": true, | ||
"curly": [true, "ignore-same-line"], | ||
"deprecation": true, | ||
"forin": true, | ||
"interface-name": [true, "never-prefix"], | ||
"interface-over-type-literal": true, | ||
"jsdoc-format": true, | ||
"label-position": true, | ||
"member-access": [true, "no-public"], | ||
"new-parens": true, | ||
"no-angle-bracket-type-assertion": true, | ||
"no-any": true, | ||
"no-arg": true, | ||
"no-conditional-assignment": true, | ||
"no-construct": true, | ||
"no-debugger": true, | ||
"no-default-export": true, | ||
"no-duplicate-variable": true, | ||
"no-inferrable-types": true, | ||
"no-namespace": [true, "allow-declarations"], | ||
"no-reference": true, | ||
"no-string-throw": true, | ||
"no-return-await": true, | ||
"no-unsafe-finally": true, | ||
"no-unused-expression": true, | ||
"no-var-keyword": true, | ||
"object-literal-shorthand": true, | ||
"only-arrow-functions": [true, "allow-declarations", "allow-named-functions"], | ||
"prefer-const": true, | ||
"radix": true, | ||
"semicolon": [true, "always", "ignore-bound-class-methods"], | ||
"switch-default": true, | ||
"trailing-comma": [ | ||
true, | ||
{ | ||
"multiline": { | ||
"objects": "always", | ||
"arrays": "always", | ||
"functions": "never", | ||
"typeLiterals": "ignore" | ||
}, | ||
"esSpecCompliant": true | ||
} | ||
], | ||
"triple-equals": [true, "allow-null-check"], | ||
"use-isnan": true, | ||
"variable-name": [ | ||
true, | ||
"check-format", | ||
"ban-keywords", | ||
"allow-leading-underscore", | ||
"allow-trailing-underscore" | ||
] | ||
} | ||
} | ||
"extends": [ | ||
"./tslint-rules.json", | ||
"tslint-config-prettier" | ||
] | ||
} |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
68291
27
923
1
27
81
5
+ Addedncp@^2.0.0
+ Added@sindresorhus/is@0.14.0(transitive)
+ Added@szmarczak/http-timer@1.1.2(transitive)
+ Addedansi-align@3.0.1(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedboxen@3.2.0(transitive)
+ Addedcacheable-request@6.1.0(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedci-info@2.0.0(transitive)
+ Addedcli-boxes@2.2.1(transitive)
+ Addedclone-response@1.0.3(transitive)
+ Addedconfigstore@4.0.0(transitive)
+ Addeddecompress-response@3.3.0(transitive)
+ Addeddefer-to-connect@1.1.3(transitive)
+ Addedemoji-regex@7.0.38.0.0(transitive)
+ Addedend-of-stream@1.4.4(transitive)
+ Addedget-stream@4.1.05.2.0(transitive)
+ Addedgot@9.6.0(transitive)
+ Addedhas-yarn@2.1.0(transitive)
+ Addedhttp-cache-semantics@4.1.1(transitive)
+ Addedis-ci@2.0.0(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedis-npm@3.0.0(transitive)
+ Addedis-yarn-global@0.3.0(transitive)
+ Addedjson-buffer@3.0.0(transitive)
+ Addedkeyv@3.1.0(transitive)
+ Addedlatest-version@5.1.0(transitive)
+ Addedlowercase-keys@2.0.0(transitive)
+ Addedmimic-response@1.0.1(transitive)
+ Addedncp@2.0.0(transitive)
+ Addednormalize-url@4.5.1(transitive)
+ Addedp-cancelable@1.1.0(transitive)
+ Addedpackage-json@6.5.0(transitive)
+ Addedprepend-http@2.0.0(transitive)
+ Addedpump@3.0.2(transitive)
+ Addedregistry-auth-token@4.2.2(transitive)
+ Addedregistry-url@5.1.0(transitive)
+ Addedresponselike@1.0.2(transitive)
+ Addedsemver@6.3.1(transitive)
+ Addedstring-width@3.1.04.2.3(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedto-readable-stream@1.0.0(transitive)
+ Addedtslint-config-prettier@1.18.0(transitive)
+ Addedtype-fest@0.3.1(transitive)
+ Addedupdate-notifier@3.0.1(transitive)
+ Addedurl-parse-lax@3.0.0(transitive)
- Removedentities@^1.1.1
- Removedpify@^4.0.0
- Removedansi-align@2.0.0(transitive)
- Removedboxen@1.3.0(transitive)
- Removedcapture-stack-trace@1.0.2(transitive)
- Removedci-info@1.6.0(transitive)
- Removedcli-boxes@1.0.0(transitive)
- Removedconfigstore@3.1.5(transitive)
- Removedcreate-error-class@3.0.2(transitive)
- Removedentities@1.1.2(transitive)
- Removedgot@6.7.1(transitive)
- Removedis-ci@1.2.1(transitive)
- Removedis-npm@1.0.0(transitive)
- Removedis-redirect@1.0.0(transitive)
- Removedis-retry-allowed@1.2.0(transitive)
- Removedlatest-version@3.1.0(transitive)
- Removedpackage-json@4.0.1(transitive)
- Removedpify@4.0.1(transitive)
- Removedprepend-http@1.0.4(transitive)
- Removedregistry-auth-token@3.4.0(transitive)
- Removedregistry-url@3.1.0(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedtimed-out@4.0.1(transitive)
- Removedunzip-response@2.0.1(transitive)
- Removedupdate-notifier@2.5.0(transitive)
- Removedurl-parse-lax@1.0.0(transitive)
Updatedupdate-notifier@^3.0.0