Skip to content

Commit 1eca224

Browse files
committed
feat: create starter package with modern tooling
Use ESLint instead of TSLint, use yarn instead of npm, use newer JSON Schemas for validation.
1 parent 6cbd1fd commit 1eca224

File tree

9 files changed

+3738
-1214
lines changed

9 files changed

+3738
-1214
lines changed

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"scripts": {
2626
"eslint": "eslint 'src/**/*.ts'",
2727
"build": "tsc -p .",
28-
"package-schema": "download http://json.schemastore.org/package | json2ts | prettier --parser typescript > src/package.ts",
29-
"travis-schema": "download http://json.schemastore.org/travis | json2ts | prettier --parser typescript > src/travis.ts",
30-
"tsconfig-schema": "download http://json.schemastore.org/tsconfig | json2ts | prettier --parser typescript > src/tsconfig.ts",
31-
"tslint-schema": "download http://json.schemastore.org/tslint | json2ts | prettier --parser typescript > src/tslint.ts",
28+
"package-schema": "download http://json.schemastore.org/package | json2ts | prettier --parser typescript > src/package-schema.ts",
29+
"travis-schema": "download http://json.schemastore.org/travis | json2ts | prettier --parser typescript > src/travis-schema.ts",
30+
"tsconfig-schema": "download http://json.schemastore.org/tsconfig | json2ts | prettier --parser typescript > src/tsconfig-schema.ts",
31+
"eslintrc-schema": "download http://json.schemastore.org/eslintrc | json2ts | prettier --parser typescript > src/eslintrc-schema.ts",
3232
"prettier": "prettier '**/*.{js?(on),ts}' --write --list-different",
3333
"semantic-release": "semantic-release",
3434
"pre-commit": "yarn run eslint && yarn run prettier"
@@ -61,9 +61,10 @@
6161
"@types/js-yaml": "3.12.3",
6262
"@types/mz": "0.0.32",
6363
"@types/request-promise": "4.1.42",
64+
"download-cli": "^1.1.1",
6465
"eslint": "^6.8.0",
6566
"husky": "1.2.0",
66-
"json-schema-to-typescript": "6.1.0",
67+
"json-schema-to-typescript": "8.2.0",
6768
"prettier": "2.0.3",
6869
"semantic-release": "15.12.5",
6970
"typescript": "3.8.3"

src/cli.ts

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import chalk from 'chalk'
55
import exec from 'execa'
66
import GitUrlParse from 'git-url-parse'
77
import { exists, mkdir, readFile, writeFile } from 'mz/fs'
8-
import { JsonSchemaForNpmPackageJsonFiles } from './package-schema'
8+
import { JSONSchemaForNPMPackageJsonFiles } from './package-schema'
99
import * as prompt from './prompt'
10-
import { JsonSchemaForTheTypeScriptCompilersConfigurationFile } from './tsconfig-schema'
11-
import { JsonSchemaForTheTsLintConfigurationFiles } from './tslint-schema'
10+
import { JSONSchemaForTheTypeScriptCompilerSConfigurationFile } from './tsconfig-schema'
11+
import { JSONSchemaForESLintConfigurationFiles } from './eslintrc-schema'
1212

1313
interface Repository {
1414
type: string
@@ -104,12 +104,12 @@ async function main(): Promise<void> {
104104
if (await exists('tsconfig.json')) {
105105
console.log('📄 tsconfig.json already exists, skipping creation')
106106
} else {
107-
const tsconfigJson: JsonSchemaForTheTypeScriptCompilersConfigurationFile = {
107+
const tsconfigJson: JSONSchemaForTheTypeScriptCompilerSConfigurationFile = {
108108
extends: './node_modules/@sourcegraph/tsconfig/tsconfig.json',
109109
compilerOptions: {
110-
target: 'es2016',
111-
module: 'esnext',
112-
moduleResolution: 'node',
110+
target: 'ES2019',
111+
module: 'ESNext',
112+
moduleResolution: 'Node',
113113
sourceMap: true,
114114
declaration: true,
115115
outDir: 'dist',
@@ -122,14 +122,17 @@ async function main(): Promise<void> {
122122
await writeFile('tsconfig.json', JSON.stringify(tsconfigJson, null, 2))
123123
}
124124

125-
if (await exists('tslint.json')) {
126-
console.log('📄 tslint.json already exists, skipping creation')
125+
if (await exists('eslint.json')) {
126+
console.log('📄 eslint.json already exists, skipping creation')
127127
} else {
128-
console.log('📄 Adding tslint.json')
129-
const tslintJson: JsonSchemaForTheTsLintConfigurationFiles = {
130-
extends: ['@sourcegraph/tslint-config'],
128+
console.log('📄 Adding .eslintrc.json')
129+
const eslintJson: JSONSchemaForESLintConfigurationFiles = {
130+
extends: ['@sourcegraph/eslint-config'],
131+
parserOptions: {
132+
project: 'tsconfig.json',
133+
},
131134
}
132-
await writeFile('tslint.json', JSON.stringify(tslintJson, null, 2))
135+
await writeFile('eslint.json', JSON.stringify(eslintJson, null, 2))
133136
}
134137

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

156159
console.log('📄 Adding .gitignore')
157-
await writeFile('.gitignore', ['dist/', 'node_modules/', '.cache/', ''].join('\n'))
160+
await writeFile('.gitignore', ['dist/', 'node_modules/', '.cache/', 'yarn.lock', ''].join('\n'))
158161

159162
if (await exists('package.json')) {
160163
console.log('📄 package.json already exists, skipping creation')
161164
} else {
162165
console.log('📄 Adding package.json')
163-
const packageJson: JsonSchemaForNpmPackageJsonFiles = {
166+
const packageJson: JSONSchemaForNPMPackageJsonFiles = {
164167
$schema: schema,
165168
name,
166169
description,
@@ -182,14 +185,14 @@ async function main(): Promise<void> {
182185
license,
183186
main: `dist/${name}.js`,
184187
scripts: {
185-
tslint: "tslint -p tsconfig.json './src/**/*.ts'",
188+
eslint: "eslint 'src/**/*.ts'",
186189
typecheck: 'tsc -p tsconfig.json',
187190
build: `parcel build --out-file dist/${name}.js src/${name}.ts`,
188191
'symlink-package': 'mkdirp dist && lnfs ./package.json ./dist/package.json',
189-
serve: `npm run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
192+
serve: `yarn run symlink-package && parcel serve --no-hmr --out-file dist/${name}.js src/${name}.ts`,
190193
'watch:typecheck': 'tsc -p tsconfig.json -w',
191194
'watch:build': 'tsc -p tsconfig.dist.json -w',
192-
'sourcegraph:prepublish': 'npm run typecheck && npm run build',
195+
'sourcegraph:prepublish': 'yarn run typecheck && yarn run build',
193196
},
194197
browserslist: [
195198
'last 1 Chrome versions',
@@ -234,15 +237,15 @@ async function main(): Promise<void> {
234237

235238
console.log('📦 Installing dependencies')
236239
await exec(
237-
'npm',
240+
'yarn',
238241
[
239-
'install',
240-
'--save-dev',
242+
'add',
243+
'--dev',
241244
'sourcegraph',
242245
'typescript',
243246
'parcel-bundler',
244247
'tslint',
245-
'@sourcegraph/tslint-config',
248+
'@sourcegraph/eslint-config',
246249
'@sourcegraph/tsconfig',
247250
'lnfs-cli',
248251
'mkdirp',

0 commit comments

Comments
 (0)