Skip to content

Commit

Permalink
feat: create starter package with modern tooling
Browse files Browse the repository at this point in the history
Use ESLint instead of TSLint, use yarn instead of npm, use newer JSON Schemas for validation.
  • Loading branch information
sqs committed Apr 19, 2020
1 parent 6cbd1fd commit 1eca224
Show file tree
Hide file tree
Showing 9 changed files with 3,738 additions and 1,214 deletions.
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
"scripts": {
"eslint": "eslint 'src/**/*.ts'",
"build": "tsc -p .",
"package-schema": "download http://json.schemastore.org/package | json2ts | prettier --parser typescript > src/package.ts",
"travis-schema": "download http://json.schemastore.org/travis | json2ts | prettier --parser typescript > src/travis.ts",
"tsconfig-schema": "download http://json.schemastore.org/tsconfig | json2ts | prettier --parser typescript > src/tsconfig.ts",
"tslint-schema": "download http://json.schemastore.org/tslint | json2ts | prettier --parser typescript > src/tslint.ts",
"package-schema": "download http://json.schemastore.org/package | json2ts | prettier --parser typescript > src/package-schema.ts",
"travis-schema": "download http://json.schemastore.org/travis | json2ts | prettier --parser typescript > src/travis-schema.ts",
"tsconfig-schema": "download http://json.schemastore.org/tsconfig | json2ts | prettier --parser typescript > src/tsconfig-schema.ts",
"eslintrc-schema": "download http://json.schemastore.org/eslintrc | json2ts | prettier --parser typescript > src/eslintrc-schema.ts",
"prettier": "prettier '**/*.{js?(on),ts}' --write --list-different",
"semantic-release": "semantic-release",
"pre-commit": "yarn run eslint && yarn run prettier"
Expand Down Expand Up @@ -61,9 +61,10 @@
"@types/js-yaml": "3.12.3",
"@types/mz": "0.0.32",
"@types/request-promise": "4.1.42",
"download-cli": "^1.1.1",
"eslint": "^6.8.0",
"husky": "1.2.0",
"json-schema-to-typescript": "6.1.0",
"json-schema-to-typescript": "8.2.0",
"prettier": "2.0.3",
"semantic-release": "15.12.5",
"typescript": "3.8.3"
Expand Down
47 changes: 25 additions & 22 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import chalk from 'chalk'
import exec from 'execa'
import GitUrlParse from 'git-url-parse'
import { exists, mkdir, readFile, writeFile } from 'mz/fs'
import { JsonSchemaForNpmPackageJsonFiles } from './package-schema'
import { JSONSchemaForNPMPackageJsonFiles } from './package-schema'
import * as prompt from './prompt'
import { JsonSchemaForTheTypeScriptCompilersConfigurationFile } from './tsconfig-schema'
import { JsonSchemaForTheTsLintConfigurationFiles } from './tslint-schema'
import { JSONSchemaForTheTypeScriptCompilerSConfigurationFile } from './tsconfig-schema'
import { JSONSchemaForESLintConfigurationFiles } from './eslintrc-schema'

interface Repository {
type: string
Expand Down Expand Up @@ -104,12 +104,12 @@ async function main(): Promise<void> {
if (await exists('tsconfig.json')) {
console.log('📄 tsconfig.json already exists, skipping creation')
} else {
const tsconfigJson: JsonSchemaForTheTypeScriptCompilersConfigurationFile = {
const tsconfigJson: JSONSchemaForTheTypeScriptCompilerSConfigurationFile = {
extends: './node_modules/@sourcegraph/tsconfig/tsconfig.json',
compilerOptions: {
target: 'es2016',
module: 'esnext',
moduleResolution: 'node',
target: 'ES2019',
module: 'ESNext',
moduleResolution: 'Node',
sourceMap: true,
declaration: true,
outDir: 'dist',
Expand All @@ -122,14 +122,17 @@ async function main(): Promise<void> {
await writeFile('tsconfig.json', JSON.stringify(tsconfigJson, null, 2))
}

if (await exists('tslint.json')) {
console.log('📄 tslint.json already exists, skipping creation')
if (await exists('eslint.json')) {
console.log('📄 eslint.json already exists, skipping creation')
} else {
console.log('📄 Adding tslint.json')
const tslintJson: JsonSchemaForTheTsLintConfigurationFiles = {
extends: ['@sourcegraph/tslint-config'],
console.log('📄 Adding .eslintrc.json')
const eslintJson: JSONSchemaForESLintConfigurationFiles = {
extends: ['@sourcegraph/eslint-config'],
parserOptions: {
project: 'tsconfig.json',
},
}
await writeFile('tslint.json', JSON.stringify(tslintJson, null, 2))
await writeFile('eslint.json', JSON.stringify(eslintJson, null, 2))
}

console.log('📄 Adding .editorconfig')
Expand All @@ -154,13 +157,13 @@ async function main(): Promise<void> {
)

console.log('📄 Adding .gitignore')
await writeFile('.gitignore', ['dist/', 'node_modules/', '.cache/', ''].join('\n'))
await writeFile('.gitignore', ['dist/', 'node_modules/', '.cache/', 'yarn.lock', ''].join('\n'))

if (await exists('package.json')) {
console.log('📄 package.json already exists, skipping creation')
} else {
console.log('📄 Adding package.json')
const packageJson: JsonSchemaForNpmPackageJsonFiles = {
const packageJson: JSONSchemaForNPMPackageJsonFiles = {
$schema: schema,
name,
description,
Expand All @@ -182,14 +185,14 @@ async function main(): Promise<void> {
license,
main: `dist/${name}.js`,
scripts: {
tslint: "tslint -p tsconfig.json './src/**/*.ts'",
eslint: "eslint 'src/**/*.ts'",
typecheck: 'tsc -p tsconfig.json',
build: `parcel build --out-file dist/${name}.js src/${name}.ts`,
'symlink-package': 'mkdirp dist && lnfs ./package.json ./dist/package.json',
serve: `npm run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
serve: `yarn run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
'watch:typecheck': 'tsc -p tsconfig.json -w',
'watch:build': 'tsc -p tsconfig.dist.json -w',
'sourcegraph:prepublish': 'npm run typecheck && npm run build',
'sourcegraph:prepublish': 'yarn run typecheck && yarn run build',
},
browserslist: [
'last 1 Chrome versions',
Expand Down Expand Up @@ -234,15 +237,15 @@ async function main(): Promise<void> {

console.log('📦 Installing dependencies')
await exec(
'npm',
'yarn',
[
'install',
'--save-dev',
'add',
'--dev',
'sourcegraph',
'typescript',
'parcel-bundler',
'tslint',
'@sourcegraph/tslint-config',
'@sourcegraph/eslint-config',
'@sourcegraph/tsconfig',
'lnfs-cli',
'mkdirp',
Expand Down
Loading

0 comments on commit 1eca224

Please sign in to comment.