├── .editorconfig ├── .firebaserc ├── .gitignore ├── .storybook ├── config.js └── preview-head.html ├── .travis.yml ├── README.md ├── angular.json ├── e2e ├── protractor.conf.js ├── src │ ├── app.e2e-spec.ts │ └── app.po.ts └── tsconfig.e2e.json ├── firebase.json ├── functions ├── .gitignore ├── README.md ├── package.json ├── src │ ├── ast-query.ts │ ├── bigquery.d.ts │ ├── cors.ts │ ├── index.ts │ ├── search-utils.spec.ts │ ├── search-utils.ts │ ├── sql-query.spec.ts │ └── sql-query.ts ├── tsconfig.json ├── tslint.json ├── wallaby.js └── yarn.lock ├── package.json ├── prettier.config.js ├── queries ├── tscontents.sql ├── tscontents_fast.sql └── tsfiles.sql ├── src ├── app │ ├── app.component.css │ ├── app.component.html │ ├── app.component.ts │ ├── app.module.ts │ ├── ast-search.service.ts │ ├── error-message │ │ ├── error-message.component.html │ │ ├── error-message.component.scss │ │ ├── error-message.component.ts │ │ └── error-message.stories.ts │ ├── format-repo-link.pipe.spec.ts │ ├── format-repo-link.pipe.ts │ ├── highlight-match.pipe.spec.ts │ ├── highlight-match.pipe.ts │ ├── navbar │ │ ├── navbar.component.css │ │ ├── navbar.component.html │ │ └── navbar.component.ts │ ├── query-main │ │ ├── query-main.component.css │ │ ├── query-main.component.html │ │ └── query-main.component.ts │ ├── search-result │ │ ├── search-result.component.html │ │ ├── search-result.component.scss │ │ ├── search-result.component.ts │ │ └── search-result.stories.ts │ └── search-results │ │ ├── search-results.component.html │ │ ├── search-results.component.scss │ │ ├── search-results.component.ts │ │ ├── search-results.fixture.json │ │ └── search-results.stories.ts ├── assets │ ├── .gitkeep │ └── github-logo.svg ├── browserslist ├── environments │ ├── environment.prod.ts │ └── environment.ts ├── favicon.ico ├── index.html ├── karma.conf.js ├── main.ts ├── polyfills.ts ├── styles.css ├── test.ts ├── tsconfig.app.json ├── tsconfig.spec.json └── tslint.json ├── tsconfig.json ├── tslint.json └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | 7 | -------------------------------------------------------------------------------- /.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "bigtsquery" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | yarn-error.log 34 | testem.log 35 | /typings 36 | 37 | # System Files 38 | .DS_Store 39 | Thumbs.db 40 | 41 | firebase-debug.log 42 | -------------------------------------------------------------------------------- /.storybook/config.js: -------------------------------------------------------------------------------- 1 | import { configure } from '@storybook/angular'; 2 | 3 | function loadStories() { 4 | require('../src/app/error-message/error-message.stories'); 5 | require('../src/app/search-result/search-result.stories'); 6 | require('../src/app/search-results/search-results.stories'); 7 | } 8 | 9 | configure(loadStories, module); 10 | -------------------------------------------------------------------------------- /.storybook/preview-head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Source: https://github.com/angular/angular-cli/wiki/stories-continuous-integration 2 | dist: trusty 3 | sudo: false 4 | 5 | language: node_js 6 | node_js: 7 | - "stable" 8 | 9 | addons: 10 | apt: 11 | sources: 12 | - google-chrome 13 | packages: 14 | - google-chrome-stable 15 | 16 | cache: 17 | directories: 18 | - ./node_modules 19 | 20 | install: 21 | - yarn 22 | - cd functions && yarn && cd .. 23 | 24 | script: 25 | # Use Chromium instead of Chrome. 26 | - export CHROME_BIN=chromium-browser 27 | - xvfb-run -a yarn test --no-watch --no-progress --browsers=ChromeNoSandbox 28 | - cd functions && yarn test 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BigTSQuery 2 | 3 | Run TypeScript AST Queries across all public TypeScript code on GitHub. 4 | 5 | [![Build Status](https://travis-ci.org/urish/bigtsquery.svg?branch=master)](https://travis-ci.org/urish/bigtsquery) 6 | 7 | 🔍 Live Demo - No longer available 8 | 9 | 📖 [Read the blog post](https://medium.com/@urish/yes-i-compiled-1-000-000-typescript-files-in-under-40-seconds-this-is-how-6429a665999c) 10 | 11 | ## Development 12 | 13 | Starting dev server (http://localhost:4200/): 14 | 15 | yarn start 16 | 17 | Starting storybook (http://localhost:4201/) 18 | 19 | yarn storybook 20 | 21 | Running tests: 22 | 23 | yarn test 24 | 25 | ## License 26 | 27 | Copyright (C) 2018, Uri Shaked. The code in this repo is published under the MIT license. 28 | -------------------------------------------------------------------------------- /angular.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "version": 1, 4 | "newProjectRoot": "projects", 5 | "projects": { 6 | "bigtsquery": { 7 | "root": "", 8 | "sourceRoot": "src", 9 | "projectType": "application", 10 | "prefix": "app", 11 | "schematics": {}, 12 | "architect": { 13 | "build": { 14 | "builder": "@angular-devkit/build-angular:browser", 15 | "options": { 16 | "outputPath": "dist/bigtsquery", 17 | "index": "src/index.html", 18 | "main": "src/main.ts", 19 | "polyfills": "src/polyfills.ts", 20 | "tsConfig": "src/tsconfig.app.json", 21 | "assets": ["src/favicon.ico", "src/assets"], 22 | "styles": [ 23 | { 24 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 25 | }, 26 | "src/styles.css" 27 | ], 28 | "scripts": [] 29 | }, 30 | "configurations": { 31 | "production": { 32 | "fileReplacements": [ 33 | { 34 | "replace": "src/environments/environment.ts", 35 | "with": "src/environments/environment.prod.ts" 36 | } 37 | ], 38 | "optimization": true, 39 | "outputHashing": "all", 40 | "sourceMap": false, 41 | "extractCss": true, 42 | "namedChunks": false, 43 | "aot": true, 44 | "extractLicenses": true, 45 | "vendorChunk": false, 46 | "buildOptimizer": true 47 | } 48 | } 49 | }, 50 | "serve": { 51 | "builder": "@angular-devkit/build-angular:dev-server", 52 | "options": { 53 | "browserTarget": "bigtsquery:build" 54 | }, 55 | "configurations": { 56 | "production": { 57 | "browserTarget": "bigtsquery:build:production" 58 | } 59 | } 60 | }, 61 | "extract-i18n": { 62 | "builder": "@angular-devkit/build-angular:extract-i18n", 63 | "options": { 64 | "browserTarget": "bigtsquery:build" 65 | } 66 | }, 67 | "test": { 68 | "builder": "@angular-devkit/build-angular:karma", 69 | "options": { 70 | "main": "src/test.ts", 71 | "polyfills": "src/polyfills.ts", 72 | "tsConfig": "src/tsconfig.spec.json", 73 | "karmaConfig": "src/karma.conf.js", 74 | "styles": [ 75 | { 76 | "input": "node_modules/@angular/material/prebuilt-themes/indigo-pink.css" 77 | }, 78 | "src/styles.css" 79 | ], 80 | "scripts": [], 81 | "assets": ["src/favicon.ico", "src/assets"] 82 | } 83 | }, 84 | "lint": { 85 | "builder": "@angular-devkit/build-angular:tslint", 86 | "options": { 87 | "tsConfig": ["src/tsconfig.app.json", "src/tsconfig.spec.json"], 88 | "exclude": ["**/node_modules/**"] 89 | } 90 | } 91 | } 92 | }, 93 | "bigtsquery-e2e": { 94 | "root": "e2e/", 95 | "projectType": "application", 96 | "architect": { 97 | "e2e": { 98 | "builder": "@angular-devkit/build-angular:protractor", 99 | "options": { 100 | "protractorConfig": "e2e/protractor.conf.js", 101 | "devServerTarget": "bigtsquery:serve" 102 | } 103 | }, 104 | "lint": { 105 | "builder": "@angular-devkit/build-angular:tslint", 106 | "options": { 107 | "tsConfig": "e2e/tsconfig.e2e.json", 108 | "exclude": ["**/node_modules/**"] 109 | } 110 | } 111 | } 112 | } 113 | }, 114 | "defaultProject": "bigtsquery", 115 | "cli": { 116 | "packageManager": "yarn" 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /e2e/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './src/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | onPrepare() { 23 | require('ts-node').register({ 24 | project: require('path').join(__dirname, './tsconfig.e2e.json') 25 | }); 26 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 27 | } 28 | }; -------------------------------------------------------------------------------- /e2e/src/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { AppPage } from './app.po'; 2 | 3 | describe('workspace-project App', () => { 4 | let page: AppPage; 5 | 6 | beforeEach(() => { 7 | page = new AppPage(); 8 | }); 9 | 10 | it('should display welcome message', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('Welcome to app!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /e2e/src/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, by, element } from 'protractor'; 2 | 3 | export class AppPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types": [ 8 | "jasmine", 9 | "jasminewd2", 10 | "node" 11 | ] 12 | } 13 | } -------------------------------------------------------------------------------- /firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "functions": { 3 | "predeploy": [ 4 | "npm --prefix \"$RESOURCE_DIR\" run lint", 5 | "npm --prefix \"$RESOURCE_DIR\" run build" 6 | ] 7 | }, 8 | "hosting": { 9 | "public": "dist/bigtsquery", 10 | "ignore": ["firebase.json", "**/.*", "**/node_modules/**"], 11 | "rewrites": [ 12 | { 13 | "source": "**", 14 | "destination": "/index.html" 15 | } 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /functions/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bigquery-credentials.json 3 | lib 4 | -------------------------------------------------------------------------------- /functions/README.md: -------------------------------------------------------------------------------- 1 | Run the following query to generate `src/dataset.json`: 2 | 3 | ```sql 4 | SELECT 5 | contents.id, 6 | content, 7 | ARRAY_AGG(CONCAT(repo_name, REPLACE(ref, 'refs/heads/', '/blob/'), '/', path)) AS paths 8 | FROM 9 | typescript.tscontents AS contents 10 | JOIN 11 | typescript.tsfiles AS files 12 | ON 13 | contents.id = files.id 14 | WHERE 15 | size >= 1000 16 | GROUP BY 17 | contents.id, 18 | content, 19 | size 20 | ORDER BY 21 | size 22 | LIMIT 23 | 10000 24 | ``` -------------------------------------------------------------------------------- /functions/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "functions", 3 | "scripts": { 4 | "lint": "tslint --project tsconfig.json", 5 | "build": "tsc", 6 | "serve": "npm run build && firebase serve --only functions", 7 | "shell": "npm run build && firebase functions:shell", 8 | "start": "npm run shell", 9 | "test": "jest", 10 | "watch": "tsc --watch", 11 | "deploy": "firebase deploy --only functions", 12 | "logs": "firebase functions:log" 13 | }, 14 | "main": "lib/index.js", 15 | "dependencies": { 16 | "@google-cloud/bigquery": "^1.3.0", 17 | "@phenomnomnominal/tsquery": "^2.0.0-beta.4", 18 | "cors": "^2.8.4", 19 | "express": "^4.16.3", 20 | "firebase-admin": "~5.12.1", 21 | "firebase-functions": "^1.0.3", 22 | "typescript": "^2.8.3" 23 | }, 24 | "devDependencies": { 25 | "@types/jest": "^22.2.3", 26 | "jest": "^23.0.0", 27 | "ts-jest": "^22.4.6", 28 | "tslint": "^5.8.0" 29 | }, 30 | "engines": { 31 | "node": "8" 32 | }, 33 | "jest": { 34 | "transform": { 35 | "^.+\\.tsx?$": "ts-jest" 36 | }, 37 | "testRegex": "src/.+\\.spec\\.(jsx?|tsx?)$", 38 | "moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json"] 39 | }, 40 | "private": true 41 | } 42 | -------------------------------------------------------------------------------- /functions/src/ast-query.ts: -------------------------------------------------------------------------------- 1 | import * as Bigquery from '@google-cloud/bigquery'; 2 | import * as e from 'express'; 3 | import * as admin from 'firebase-admin'; 4 | import * as functions from 'firebase-functions'; 5 | import { IMatch } from './search-utils'; 6 | import { getSqlQuery } from './sql-query'; 7 | import { tsquery } from '@phenomnomnominal/tsquery'; 8 | 9 | const credentials = require('../bigquery-credentials.json'); 10 | 11 | const bigquery = Bigquery({ 12 | credentials, 13 | projectId: credentials.project_id, 14 | }); 15 | 16 | admin.initializeApp(functions.config().firebase); 17 | const firestore = admin.firestore(); 18 | const queriesCollection = firestore.collection('queries'); 19 | 20 | interface IQueryResult { 21 | id: string; 22 | paths: string[]; 23 | match: string; 24 | } 25 | 26 | interface ICacheEntry { 27 | query: string; 28 | time: Date; 29 | results: IQueryResult[]; 30 | } 31 | 32 | async function executeQuery(query: string) { 33 | const [result] = await bigquery.query({ 34 | query: getSqlQuery(), 35 | params: [query], 36 | maxResults: 10, 37 | }); 38 | return result; 39 | } 40 | 41 | export async function astQuery(request: e.Request, response: e.Response) { 42 | const { q } = request.query; 43 | const query = q.trim(); 44 | console.log(`[${request.ip}] Query: ${q}`); 45 | try { 46 | tsquery.parse(query); 47 | } catch (err) { 48 | console.error(`[${request.ip}] Invalid selector: `, err); 49 | response.json({ error: err.toString(), errorKind: 'queryError' }); 50 | return; 51 | } 52 | 53 | try { 54 | const snapshot = await queriesCollection.where('query', '==', query).get(); 55 | let results: IQueryResult[]; 56 | if (snapshot.docs.length) { 57 | const cacheEntry = snapshot.docs[0].data() as ICacheEntry; 58 | results = cacheEntry.results; 59 | } else { 60 | results = await executeQuery(query); 61 | await queriesCollection.add({ 62 | query, 63 | results, 64 | time: new Date(), 65 | } as ICacheEntry); 66 | } 67 | response.json({ 68 | results: results.map((entry) => ({ 69 | id: entry.id, 70 | paths: entry.paths, 71 | ...(JSON.parse(entry.match) as IMatch), 72 | })), 73 | }); 74 | } catch (err) { 75 | console.error(err); 76 | response.json({ error: 'Internal server error', errorKind: 'serverError' }); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /functions/src/bigquery.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@google-cloud/bigquery' { 2 | class Bigquery { 3 | public query(options: { 4 | query: string; 5 | params?: any[]; 6 | maxResults?: number; 7 | }): Promise<[T[]]>; 8 | } 9 | 10 | function create(options?: any): Bigquery; 11 | 12 | namespace create { 13 | 14 | } 15 | 16 | export = create; 17 | } 18 | -------------------------------------------------------------------------------- /functions/src/cors.ts: -------------------------------------------------------------------------------- 1 | import * as cors from 'cors'; 2 | import * as e from 'express'; 3 | 4 | const corsInstance = cors({ 5 | origin: ['https://bigtsquery.firebaseapp.com', 'http://localhost:4200'], 6 | }); 7 | 8 | type FirebaseHandler = (req: e.Request, res: e.Response) => void; 9 | 10 | export function corsHandler(callback: FirebaseHandler) { 11 | return (req: e.Request, res: e.Response) => corsInstance(req, res, () => callback(req, res)); 12 | } 13 | -------------------------------------------------------------------------------- /functions/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as functions from 'firebase-functions'; 2 | import { astQuery } from './ast-query'; 3 | import { corsHandler } from './cors'; 4 | 5 | export const query = functions.https.onRequest(corsHandler(astQuery)); 6 | -------------------------------------------------------------------------------- /functions/src/search-utils.spec.ts: -------------------------------------------------------------------------------- 1 | import { tsquery } from '@phenomnomnominal/tsquery'; 2 | import { getTextAround } from './search-utils'; 3 | 4 | // tslint:disable:no-floating-promises 5 | 6 | describe('getTextAround', () => { 7 | it('should return the lines around the given source code position', () => { 8 | const ast = tsquery.ast( 9 | ` 10 | function f() { 11 | return 5; 12 | }`.trim(), 13 | ); 14 | const [node] = tsquery.query(ast, 'NumericLiteral'); 15 | expect(getTextAround(node)).toEqual({ 16 | line: 0, 17 | matchChar: 9, 18 | matchLine: 1, 19 | matchLength: 1, 20 | text: 'function f() {\n return 5;\n}', 21 | }); 22 | }); 23 | 24 | it('should return correct result for code with comments', () => { 25 | const ast = tsquery.ast( 26 | ` 27 | // this is a comment 28 | function f() { 29 | return 5; 30 | }`.trim(), 31 | ); 32 | const [node] = tsquery.query(ast, 'NumericLiteral'); 33 | expect(getTextAround(node)).toEqual({ 34 | line: 0, 35 | matchChar: 9, 36 | matchLine: 2, 37 | matchLength: 1, 38 | text: '// this is a comment\nfunction f() {\n return 5;\n}', 39 | }); 40 | }); 41 | 42 | it('should only return 1 line around the code for long match (4+ lines)', () => { 43 | const ast = tsquery.ast( 44 | ` 45 | import { parse } from 'url'; 46 | let secureProtocols = ['https:', 'wss:']; 47 | function isSecureProtocol(url: string): boolean { 48 | const { protocol } = parse(url.toLowerCase()); 49 | return secureProtocols.indexOf(protocol) !== -1; 50 | } 51 | function g() { 52 | return 4; 53 | } 54 | `.trim(), 55 | ); 56 | const [node] = tsquery.query(ast, 'FunctionDeclaration'); 57 | expect(getTextAround(node)).toEqual({ 58 | line: 1, 59 | matchChar: 0, 60 | matchLine: 2, 61 | matchLength: 151, 62 | text: 63 | `let secureProtocols = ['https:', 'wss:'];\n` + 64 | `function isSecureProtocol(url: string): boolean {\n` + 65 | ` const { protocol } = parse(url.toLowerCase());\n` + 66 | ` return secureProtocols.indexOf(protocol) !== -1;\n` + 67 | `}\n` + 68 | `function g() {`, 69 | }); 70 | }); 71 | }); 72 | -------------------------------------------------------------------------------- /functions/src/search-utils.ts: -------------------------------------------------------------------------------- 1 | import * as ts from 'typescript'; 2 | 3 | export interface IMatch { 4 | text: string; 5 | line: number; 6 | matchLine: number; 7 | matchChar: number; 8 | matchLength: number; 9 | } 10 | 11 | export function getTextAround(node: ts.Node): IMatch { 12 | const getLinesAround = (numLines: number) => { 13 | if (numLines < 2) { 14 | return 3; 15 | } 16 | if (numLines < 4) { 17 | return 2; 18 | } 19 | return 1; 20 | }; 21 | 22 | const sourceFile = node.getSourceFile(); 23 | const sourceCode = sourceFile.getFullText(); 24 | const { line: startLine, character } = ts.getLineAndCharacterOfPosition( 25 | sourceFile, 26 | node.getStart(), 27 | ); 28 | const { line: endLine } = ts.getLineAndCharacterOfPosition(sourceFile, node.getEnd()); 29 | const totalLines = endLine - startLine + 1; 30 | const linesAround = getLinesAround(totalLines); 31 | const actualStart = Math.max(0, startLine - linesAround); 32 | const lines = sourceCode.split('\n'); 33 | return { 34 | text: lines.slice(actualStart, endLine + 1 + linesAround).join('\n'), 35 | line: actualStart, 36 | matchLine: startLine, 37 | matchChar: character, 38 | matchLength: node.getEnd() - node.getStart(), 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /functions/src/sql-query.spec.ts: -------------------------------------------------------------------------------- 1 | import { getSqlQuery, getUmlCode } from './sql-query'; 2 | import * as tsquery from '@phenomnomnominal/tsquery'; 3 | import * as ts from 'typescript'; 4 | 5 | describe('sql-query', () => { 6 | describe('getUmlCode', () => { 7 | const umlCode = getUmlCode(); 8 | const umlFunction = new Function('src', 'query', 'const { ts } = this; ' + umlCode); 9 | const sourceCode = ` 10 | interface MyInterface {} 11 | `.trim(); 12 | expect( 13 | umlFunction.call({ tsquery, ts }, sourceCode, 'InterfaceDeclaration>Identifier'), 14 | ).toEqual([ 15 | '{"text":"interface MyInterface {}","line":0,"matchLine":0,"matchChar":10,"matchLength":11}', 16 | ]); 17 | }); 18 | 19 | describe('getSqlQuery', () => { 20 | it('should return a string', () => { 21 | expect(getSqlQuery()).toEqual(expect.any(String)); 22 | }); 23 | }); 24 | }); 25 | -------------------------------------------------------------------------------- /functions/src/sql-query.ts: -------------------------------------------------------------------------------- 1 | import * as tsqueryModule from '@phenomnomnominal/tsquery'; 2 | import * as searchUtils from './search-utils'; 3 | 4 | declare const getTextAround: typeof searchUtils.getTextAround; 5 | 6 | function umlCode(this: { tsquery: typeof tsqueryModule }, src: string, query: string) { 7 | const { tsquery } = this.tsquery; 8 | try { 9 | const sourceFile = tsquery.ast(src); 10 | const results = tsquery(sourceFile, query); 11 | return results.map((item) => JSON.stringify(getTextAround(item))); 12 | } catch (err) { 13 | return []; 14 | } 15 | } 16 | 17 | export function getUmlCode() { 18 | const { tsquery } = tsqueryModule; 19 | const source = tsquery.ast(umlCode.toString()); 20 | return searchUtils.getTextAround.toString() + ' ' + tsquery(source, 'Block')[0].getFullText(); 21 | } 22 | 23 | export function getSqlQuery(limit = 100) { 24 | return ` 25 | CREATE TEMPORARY FUNCTION getResults(src STRING, query STRING) 26 | RETURNS ARRAY 27 | LANGUAGE js AS """ ${getUmlCode().replace(/\\/g, '\\\\')} """ 28 | OPTIONS ( 29 | library="gs://bigtsquery/tsquery-2.0.0-beta.4.umd.min.js" 30 | ); 31 | 32 | SELECT 33 | id, 34 | paths, 35 | match 36 | FROM 37 | typescript.tscontents_fast, 38 | UNNEST(getResults(content, ?)) AS match 39 | LIMIT 40 | ${limit} 41 | `; 42 | } 43 | -------------------------------------------------------------------------------- /functions/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "lib": ["es6"], 4 | "module": "commonjs", 5 | "noImplicitAny": true, 6 | "noImplicitReturns": true, 7 | "noFallthroughCasesInSwitch": true, 8 | "noImplicitThis": true, 9 | "strictNullChecks": true, 10 | "noUnusedLocals": true, 11 | "outDir": "lib", 12 | "sourceMap": true, 13 | "types": ["jest"], 14 | "target": "es6" 15 | }, 16 | "compileOnSave": true, 17 | "include": ["src"] 18 | } 19 | -------------------------------------------------------------------------------- /functions/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | // -- Strict errors -- 4 | // These lint rules are likely always a good idea. 5 | 6 | // Force function overloads to be declared together. This ensures readers understand APIs. 7 | "adjacent-overload-signatures": true, 8 | 9 | // Do not allow the subtle/obscure comma operator. 10 | "ban-comma-operator": true, 11 | 12 | // Do not allow internal modules or namespaces . These are deprecated in favor of ES6 modules. 13 | "no-namespace": true, 14 | 15 | // Do not allow parameters to be reassigned. To avoid bugs, developers should instead assign new values to new vars. 16 | "no-parameter-reassignment": true, 17 | 18 | // Force the use of ES6-style imports instead of /// imports. 19 | "no-reference": true, 20 | 21 | // Do not allow type assertions that do nothing. This is a big warning that the developer may not understand the 22 | // code currently being edited (they may be incorrectly handling a different type case that does not exist). 23 | "no-unnecessary-type-assertion": true, 24 | 25 | // Disallow nonsensical label usage. 26 | "label-position": true, 27 | 28 | // Disallows the (often typo) syntax if (var1 = var2). Replace with if (var2) { var1 = var2 }. 29 | "no-conditional-assignment": true, 30 | 31 | // Disallows constructors for primitive types (e.g. new Number('123'), though Number('123') is still allowed). 32 | "no-construct": true, 33 | 34 | // Do not allow super() to be called twice in a constructor. 35 | "no-duplicate-super": true, 36 | 37 | // Do not allow the same case to appear more than once in a switch block. 38 | "no-duplicate-switch-case": true, 39 | 40 | // Do not allow a variable to be declared more than once in the same block. Consider function parameters in this 41 | // rule. 42 | "no-duplicate-variable": [true, "check-parameters"], 43 | 44 | // Disallows a variable definition in an inner scope from shadowing a variable in an outer scope. Developers should 45 | // instead use a separate variable name. 46 | "no-shadowed-variable": true, 47 | 48 | // Empty blocks are almost never needed. Allow the one general exception: empty catch blocks. 49 | "no-empty": [true, "allow-empty-catch"], 50 | 51 | // Functions must either be handled directly (e.g. with a catch() handler) or returned to another function. 52 | // This is a major source of errors in Cloud Functions and the team strongly recommends leaving this rule on. 53 | "no-floating-promises": true, 54 | 55 | // Do not allow any imports for modules that are not in package.json. These will almost certainly fail when 56 | // deployed. 57 | "no-implicit-dependencies": true, 58 | 59 | // The 'this' keyword can only be used inside of classes. 60 | "no-invalid-this": true, 61 | 62 | // Do not allow strings to be thrown because they will not include stack traces. Throw Errors instead. 63 | "no-string-throw": true, 64 | 65 | // Disallow control flow statements, such as return, continue, break, and throw in finally blocks. 66 | "no-unsafe-finally": true, 67 | 68 | // Do not allow variables to be used before they are declared. 69 | "no-use-before-declare": true, 70 | 71 | // Expressions must always return a value. Avoids common errors like const myValue = functionReturningVoid(); 72 | "no-void-expression": [true, "ignore-arrow-function-shorthand"], 73 | 74 | // Disallow duplicate imports in the same file. 75 | "no-duplicate-imports": true, 76 | 77 | // -- Strong Warnings -- 78 | // These rules should almost never be needed, but may be included due to legacy code. 79 | // They are left as a warning to avoid frustration with blocked deploys when the developer 80 | // understand the warning and wants to deploy anyway. 81 | 82 | // Warn when an empty interface is defined. These are generally not useful. 83 | "no-empty-interface": { "severity": "warning" }, 84 | 85 | // Warn when an import will have side effects. 86 | "no-import-side-effect": { "severity": "warning" }, 87 | 88 | // Warn when variables are defined with var. Var has subtle meaning that can lead to bugs. Strongly prefer const for 89 | // most values and let for values that will change. 90 | "no-var-keyword": { "severity": "warning" }, 91 | 92 | // Prefer === and !== over == and !=. The latter operators support overloads that are often accidental. 93 | "triple-equals": { "severity": "warning" }, 94 | 95 | // Warn when using deprecated APIs. 96 | "deprecation": { "severity": "warning" }, 97 | 98 | // -- Light Warnigns -- 99 | // These rules are intended to help developers use better style. Simpler code has fewer bugs. These would be "info" 100 | // if TSLint supported such a level. 101 | 102 | // prefer for( ... of ... ) to an index loop when the index is only used to fetch an object from an array. 103 | // (Even better: check out utils like .map if transforming an array!) 104 | "prefer-for-of": { "severity": "warning" }, 105 | 106 | // Warns if function overloads could be unified into a single function with optional or rest parameters. 107 | "unified-signatures": { "severity": "warning" }, 108 | 109 | // Warns if code has an import or variable that is unused. 110 | "no-unused-variable": { "severity": "warning" }, 111 | 112 | // Prefer const for values that will not change. This better documents code. 113 | "prefer-const": { "severity": "warning" }, 114 | 115 | // Multi-line object liiterals and function calls should have a trailing comma. This helps avoid merge conflicts. 116 | "trailing-comma": { "severity": "warning" } 117 | }, 118 | 119 | "defaultSeverity": "error" 120 | } 121 | -------------------------------------------------------------------------------- /functions/wallaby.js: -------------------------------------------------------------------------------- 1 | module.exports = function() { 2 | return { 3 | files: ['src/**/*.ts', '!src/**/*.spec.ts'], 4 | 5 | tests: ['src/**/*.spec.ts'], 6 | 7 | env: { 8 | type: 'node', 9 | runner: 'node', 10 | }, 11 | 12 | testFramework: 'jest', 13 | }; 14 | }; 15 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "bigtsquery", 3 | "version": "0.0.0", 4 | "scripts": { 5 | "ng": "ng", 6 | "start": "ng serve", 7 | "start:functions": "firebase serve --only functions", 8 | "storybook": "start-storybook -p 4201 -c .storybook", 9 | "build": "ng build --prod", 10 | "deploy": "yarn build && firebase deploy", 11 | "serve:dist": "firebase serve --only hosting", 12 | "precommit": "lint-staged", 13 | "test": "ng test", 14 | "lint": "ng lint", 15 | "e2e": "ng e2e" 16 | }, 17 | "private": true, 18 | "dependencies": { 19 | "@angular/animations": "^6.0.2", 20 | "@angular/cdk": "^6.2.0", 21 | "@angular/common": "^6.0.2", 22 | "@angular/compiler": "^6.0.2", 23 | "@angular/core": "^6.0.2", 24 | "@angular/forms": "^6.0.2", 25 | "@angular/http": "^6.0.2", 26 | "@angular/material": "^6.2.0", 27 | "@angular/platform-browser": "^6.0.2", 28 | "@angular/platform-browser-dynamic": "^6.0.2", 29 | "@angular/router": "^6.0.2", 30 | "core-js": "^2.5.4", 31 | "escape-html": "^1.0.3", 32 | "prismjs": "^1.14.0", 33 | "rxjs": "^6.0.0", 34 | "zone.js": "^0.8.26" 35 | }, 36 | "devDependencies": { 37 | "@angular-devkit/build-angular": "~0.6.3", 38 | "@angular/cli": "~6.0.7", 39 | "@angular/compiler-cli": "^6.0.2", 40 | "@angular/language-service": "^6.0.2", 41 | "@storybook/addon-actions": "^4.0.0-alpha.8", 42 | "@storybook/angular": "^4.0.0-alpha.8", 43 | "@types/escape-html": "^0.0.20", 44 | "@types/jasmine": "~2.8.6", 45 | "@types/jasminewd2": "~2.0.3", 46 | "@types/node": "~8.9.4", 47 | "@types/prismjs": "^1.9.0", 48 | "babel-core": "^6.26.3", 49 | "codelyzer": "~4.2.1", 50 | "firebase-tools": "^3.18.5", 51 | "husky": "^0.14.3", 52 | "jasmine-core": "~2.99.1", 53 | "jasmine-spec-reporter": "~4.2.1", 54 | "karma": "~1.7.1", 55 | "karma-chrome-launcher": "~2.2.0", 56 | "karma-coverage-istanbul-reporter": "~1.4.2", 57 | "karma-jasmine": "~1.1.1", 58 | "karma-jasmine-html-reporter": "^0.2.2", 59 | "lint-staged": "^7.1.2", 60 | "prettier": "^1.12.1", 61 | "protractor": "~5.3.0", 62 | "react": "^16.4.0", 63 | "react-dom": "^16.4.0", 64 | "ts-node": "~5.0.1", 65 | "tslint": "~5.9.1", 66 | "typescript": "~2.7.2" 67 | }, 68 | "lint-staged": { 69 | "*.{js,json}": ["prettier --write", "git add"], 70 | "*.ts": ["prettier --write", "tslint --fix", "git add"] 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'always', 3 | printWidth: 100, 4 | singleQuote: true, 5 | tabWidth: 2, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /queries/tscontents.sql: -------------------------------------------------------------------------------- 1 | #standardSQL 2 | SELECT 3 | * 4 | FROM 5 | `bigquery-public-data.github_repos.contents` 6 | WHERE 7 | id IN ( 8 | SELECT 9 | id 10 | FROM 11 | `typescript.tsfiles`) 12 | AND binary = FALSE 13 | AND NOT STARTS_WITH(content, '<') 14 | -------------------------------------------------------------------------------- /queries/tscontents_fast.sql: -------------------------------------------------------------------------------- 1 | #standardSQL 2 | SELECT 3 | *, 4 | repeat(content, 5 | 40) AS _dummy 6 | FROM 7 | `typescript.tscontents` 8 | JOIN ( 9 | SELECT 10 | id AS files_id, 11 | ARRAY_AGG(CONCAT(repo_name, REPLACE(ref, 'refs/heads/', '/blob/'), '/', path)) AS paths 12 | FROM 13 | `typescript.tsfiles` 14 | GROUP BY 15 | id) AS files 16 | ON 17 | id = files_id 18 | WHERE 19 | size <= 10000 20 | -------------------------------------------------------------------------------- /queries/tsfiles.sql: -------------------------------------------------------------------------------- 1 | #standardSQL 2 | SELECT 3 | id, 4 | repo_name, 5 | path, 6 | ref 7 | FROM 8 | `bigquery-public-data.github_repos.files` 9 | WHERE 10 | path LIKE '%.ts' 11 | AND repo_name != 'georgringer/TYPO3.base' -- See https://github.com/urish/bigtsquery/issues/6 12 | -------------------------------------------------------------------------------- /src/app/app.component.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urish/bigtsquery/0c5ff6e6eb3d46e9ff835f41745059687cf1ead6/src/app/app.component.css -------------------------------------------------------------------------------- /src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'], 7 | }) 8 | export class AppComponent {} 9 | -------------------------------------------------------------------------------- /src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { LayoutModule } from '@angular/cdk/layout'; 2 | import { HttpClientModule } from '@angular/common/http'; 3 | import { NgModule } from '@angular/core'; 4 | import { RouterModule, Routes } from '@angular/router'; 5 | import { FormsModule } from '@angular/forms'; 6 | import { 7 | MatButtonModule, 8 | MatCardModule, 9 | MatFormFieldModule, 10 | MatIconModule, 11 | MatInputModule, 12 | MatProgressBarModule, 13 | MatToolbarModule, 14 | } from '@angular/material'; 15 | import { BrowserModule } from '@angular/platform-browser'; 16 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 17 | import { AppComponent } from './app.component'; 18 | import { HighlightMatchPipe } from './highlight-match.pipe'; 19 | import { NavbarComponent } from './navbar/navbar.component'; 20 | import { SearchResultComponent } from './search-result/search-result.component'; 21 | import { SearchResultsComponent } from './search-results/search-results.component'; 22 | import { FormatRepoLinkPipe } from './format-repo-link.pipe'; 23 | import { ErrorMessageComponent } from './error-message/error-message.component'; 24 | import { QueryMainComponent } from './query-main/query-main.component'; 25 | 26 | const routes: Routes = [ 27 | { path: 'query', component: QueryMainComponent }, 28 | { path: '', redirectTo: 'query', pathMatch: 'full' }, 29 | ]; 30 | 31 | @NgModule({ 32 | declarations: [ 33 | AppComponent, 34 | NavbarComponent, 35 | SearchResultsComponent, 36 | HighlightMatchPipe, 37 | SearchResultComponent, 38 | FormatRepoLinkPipe, 39 | ErrorMessageComponent, 40 | QueryMainComponent, 41 | ], 42 | imports: [ 43 | BrowserModule, 44 | BrowserAnimationsModule, 45 | FormsModule, 46 | RouterModule.forRoot(routes), 47 | HttpClientModule, 48 | LayoutModule, 49 | MatToolbarModule, 50 | MatCardModule, 51 | MatFormFieldModule, 52 | MatInputModule, 53 | MatButtonModule, 54 | MatIconModule, 55 | MatProgressBarModule, 56 | ], 57 | providers: [], 58 | bootstrap: [AppComponent], 59 | }) 60 | export class AppModule {} 61 | -------------------------------------------------------------------------------- /src/app/ast-search.service.ts: -------------------------------------------------------------------------------- 1 | import { HttpClient } from '@angular/common/http'; 2 | import { Injectable } from '@angular/core'; 3 | 4 | // for localhost: http://localhost:5000/bigtsquery/us-central1 5 | const serverUrl = `https://us-central1-bigtsquery.cloudfunctions.net`; 6 | 7 | export interface IASTQueryMatch { 8 | text: string; 9 | line: number; 10 | matchLine: number; 11 | matchChar: number; 12 | matchLength: number; 13 | } 14 | 15 | export interface IQueryResult extends IASTQueryMatch { 16 | id: string; 17 | paths: string[]; 18 | } 19 | 20 | export type IQueryErrorKind = 'queryError' | 'serverError' | 'requestFailed'; 21 | 22 | export interface IQueryResponse { 23 | results?: IQueryResponse[]; 24 | error?: string; 25 | errorKind?: IQueryErrorKind; 26 | } 27 | 28 | @Injectable({ 29 | providedIn: 'root', 30 | }) 31 | export class AstSearchService { 32 | constructor(private http: HttpClient) {} 33 | 34 | search(query: string) { 35 | const q = encodeURIComponent(query); 36 | return this.http.get(`${serverUrl}/query?q=${q}`); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/app/error-message/error-message.component.html: -------------------------------------------------------------------------------- 1 | 2 |
3 |
4 | error 5 |
6 | 7 | Invalid Query Selector 8 | 9 | 10 |

11 | {{message}} 12 |

13 | TSQuery Selector Reference 14 |
15 |
16 | 17 |
18 |
19 | error 20 |
21 | Internal Server Error 22 | 23 |

24 | Our server had error while processing your query.

25 |

26 | Please 27 | open an issue and include information about your query.

28 |
29 |
30 | 31 |
32 |
33 | error 34 |
35 | 36 | Request Failed 37 | 38 | 39 | {{message}} 40 | 41 |
42 |
-------------------------------------------------------------------------------- /src/app/error-message/error-message.component.scss: -------------------------------------------------------------------------------- 1 | .error-card { 2 | background: #cf432c; 3 | color: #fefdfc; 4 | max-width: 800px; 5 | margin: 0 auto; 6 | } 7 | 8 | mat-card-content { 9 | font-size: 18px; 10 | } 11 | 12 | .error-message { 13 | font-family: monospace; 14 | } 15 | 16 | .error-icon { 17 | text-align: center; 18 | margin-bottom: 16px; 19 | } 20 | 21 | .error-icon mat-icon { 22 | font-size: 48px; 23 | } 24 | 25 | a { 26 | color: rgb(180, 180, 255); 27 | } -------------------------------------------------------------------------------- /src/app/error-message/error-message.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, Input } from '@angular/core'; 2 | import { IQueryErrorKind } from '../ast-search.service'; 3 | 4 | @Component({ 5 | selector: 'app-error-message', 6 | templateUrl: './error-message.component.html', 7 | styleUrls: ['./error-message.component.scss'], 8 | }) 9 | export class ErrorMessageComponent implements OnInit { 10 | @Input() message: string; 11 | @Input() kind: IQueryErrorKind; 12 | 13 | constructor() {} 14 | 15 | ngOnInit() {} 16 | } 17 | -------------------------------------------------------------------------------- /src/app/error-message/error-message.stories.ts: -------------------------------------------------------------------------------- 1 | import { storiesOf } from '@storybook/angular'; 2 | import { ErrorMessageComponent } from './error-message.component'; 3 | import { HighlightMatchPipe } from '../highlight-match.pipe'; 4 | 5 | import '../../styles.css'; 6 | import { MatCardModule, MatIconModule } from '@angular/material'; 7 | 8 | const moduleMetadata = { 9 | imports: [MatCardModule, MatIconModule], 10 | }; 11 | 12 | storiesOf('ErrorMessage', module) 13 | .add('with invalid query error', () => ({ 14 | component: ErrorMessageComponent, 15 | moduleMetadata, 16 | props: { 17 | message: 18 | 'SyntaxError: Expected " ", "!", "#", "*", ".", ":", ":first-child", ":has(", ":last-child", ' + 19 | '":matches(", ":not(", ":nth-child(", ":nth-last-child(", "[" or [^ [\\],():#!=><~+.] but ">" found.', 20 | kind: 'queryError', 21 | }, 22 | })) 23 | .add('with internal server error', () => ({ 24 | component: ErrorMessageComponent, 25 | moduleMetadata, 26 | props: { 27 | message: 'Internal server error', 28 | kind: 'serverError', 29 | }, 30 | })) 31 | .add('with request failed', () => ({ 32 | component: ErrorMessageComponent, 33 | moduleMetadata, 34 | props: { 35 | message: 'Http failure response for (unknown url): 0 Unknown Error', 36 | kind: 'requestFailed', 37 | }, 38 | })); 39 | -------------------------------------------------------------------------------- /src/app/format-repo-link.pipe.spec.ts: -------------------------------------------------------------------------------- 1 | import { FormatRepoLinkPipe } from './format-repo-link.pipe'; 2 | 3 | describe('FormatRepoLinkPipe', () => { 4 | const pipe = new FormatRepoLinkPipe(); 5 | it('should format the given repo link', () => { 6 | expect(pipe.transform('foo/bar/blob/master/dir/name.ts')).toEqual('[foo/bar] dir/name.ts'); 7 | }); 8 | 9 | it('should return an empty string given undefined value', () => { 10 | expect(pipe.transform(undefined)).toEqual(''); 11 | }); 12 | }); 13 | -------------------------------------------------------------------------------- /src/app/format-repo-link.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | 3 | @Pipe({ 4 | name: 'formatRepoLink', 5 | pure: true, 6 | }) 7 | export class FormatRepoLinkPipe implements PipeTransform { 8 | transform(value: string | undefined): any { 9 | const parts = (value || '').split('/'); 10 | if (parts.length > 4) { 11 | return `[${parts[0]}/${parts[1]}] ${parts.slice(4).join('/')}`; 12 | } 13 | return ''; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/app/highlight-match.pipe.spec.ts: -------------------------------------------------------------------------------- 1 | import { HighlightMatchPipe } from './highlight-match.pipe'; 2 | 3 | describe('HighlightMatchPipe', () => { 4 | const pipe = new HighlightMatchPipe(); 5 | 6 | it('escape HTML in the given input', () => { 7 | const match = { 8 | id: '', 9 | text: 'hello("")', 10 | line: 0, 11 | matchLine: 0, 12 | matchChar: 0, 13 | matchLength: 0, 14 | }; 15 | expect(pipe.transform(match.text, match)).toBe('hello("<foo>")'); 16 | }); 17 | 18 | it('highlight the given match', () => { 19 | const match = { 20 | line: 0, 21 | matchChar: 9, 22 | matchLine: 1, 23 | matchLength: 1, 24 | text: 'function f() {\n return 5;\n}', 25 | }; 26 | expect(pipe.transform(match.text, match)).toBe('function f() {\n return 5;\n}'); 27 | }); 28 | 29 | it('should return empty text given undefined input parameter', () => { 30 | const match = { 31 | id: '', 32 | text: '', 33 | line: 0, 34 | matchLine: 0, 35 | matchChar: 0, 36 | matchLength: 0, 37 | }; 38 | expect(pipe.transform(undefined, match)).toBe(''); 39 | }); 40 | }); 41 | -------------------------------------------------------------------------------- /src/app/highlight-match.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | import { IASTQueryMatch } from './ast-search.service'; 3 | import * as escapeHtml from 'escape-html'; 4 | 5 | @Pipe({ 6 | name: 'highlightMatch', 7 | pure: true, 8 | }) 9 | export class HighlightMatchPipe implements PipeTransform { 10 | transform(value: string | undefined, result: IASTQueryMatch): any { 11 | if (!value) { 12 | return ''; 13 | } 14 | 15 | const lines = value.split('\n'); 16 | const matchLineNum = result.matchLine - result.line; 17 | const matchLine = lines[matchLineNum] || ''; 18 | const linesBefore = lines.slice(0, matchLineNum).join('\n'); 19 | const textBefore = 20 | (matchLineNum > 0 ? linesBefore + '\n' : '') + matchLine.substr(0, result.matchChar); 21 | return ( 22 | escapeHtml(textBefore) + 23 | (result.matchLength 24 | ? `${escapeHtml(value.substr(textBefore.length, result.matchLength))}` 25 | : '') + 26 | escapeHtml(value.substr(textBefore.length + result.matchLength)) 27 | ); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/app/navbar/navbar.component.css: -------------------------------------------------------------------------------- 1 | .flex-spacer { 2 | flex-grow: 1; 3 | } 4 | 5 | .github-logo { 6 | height: 26px; 7 | margin: 0 4px 3px 0; 8 | } -------------------------------------------------------------------------------- /src/app/navbar/navbar.component.html: -------------------------------------------------------------------------------- 1 | 2 | BigTSQuery 3 |
4 | 5 | GitHub 6 | 7 |
-------------------------------------------------------------------------------- /src/app/navbar/navbar.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-navbar', 5 | templateUrl: './navbar.component.html', 6 | styleUrls: ['./navbar.component.css'] 7 | }) 8 | export class NavbarComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/app/query-main/query-main.component.css: -------------------------------------------------------------------------------- 1 | .search-container { 2 | display: flex; 3 | max-width: 700px; 4 | } 5 | 6 | .search-field { 7 | flex-grow: 1; 8 | } 9 | 10 | .loading-container { 11 | margin-top: 12px; 12 | text-align: center; 13 | } 14 | 15 | .loading-container mat-spinner { 16 | display: inline-block; 17 | height: 32px; 18 | width: 32px; 19 | } 20 | 21 | .search-card { 22 | margin-bottom: 16px; 23 | } 24 | 25 | .loading-indicator { 26 | margin: 16px; 27 | } 28 | 29 | a { 30 | text-decoration: none; 31 | } 32 | 33 | a.preset { 34 | color: #0000EE; 35 | cursor: pointer; 36 | } 37 | 38 | .app-description { 39 | max-width: 700px; 40 | } 41 | 42 | .sample-queries a { 43 | display: inline-block; 44 | margin-right: 16px; 45 | } 46 | -------------------------------------------------------------------------------- /src/app/query-main/query-main.component.html: -------------------------------------------------------------------------------- 1 | 2 |

Query 1 Million TypeScript files

3 |

4 | BigTSQuery is a powerful source code search engine for TypeScript, built on top of 5 | TSQuery. It allows you to search using 6 | AST Selectors, and performs the search over nearly 1 million source files found on GitHub. 7 |

8 |

9 | Type your query below or use one of the following presets, and then click the search button: 10 |

11 |

12 | {{preset.name}} 13 |

14 |
15 | 16 | 17 | 18 | 21 |
22 |
23 | 24 |
25 |

26 | Searching in 1 million TypeScript files... this may take up to 30 seconds 27 |

28 | 29 |
30 | 31 | 32 | -------------------------------------------------------------------------------- /src/app/query-main/query-main.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit, OnDestroy } from '@angular/core'; 2 | import { ActivatedRoute, Router } from '@angular/router'; 3 | import { Subject } from 'rxjs'; 4 | import { takeUntil, first } from 'rxjs/operators'; 5 | import { AstSearchService, IQueryResponse } from '../ast-search.service'; 6 | 7 | interface IPreset { 8 | name: string; 9 | value: string; 10 | } 11 | 12 | @Component({ 13 | selector: 'app-query-main', 14 | templateUrl: './query-main.component.html', 15 | styleUrls: ['./query-main.component.css'], 16 | }) 17 | export class QueryMainComponent implements OnInit, OnDestroy { 18 | public astQuery = 'FunctionDeclaration:has(ExportKeyword)>Identifier'; 19 | public searching = false; 20 | public queryResponse: IQueryResponse = {}; 21 | 22 | private destroy$ = new Subject(); 23 | 24 | readonly presets: IPreset[] = [ 25 | { name: 'Exported Functions', value: 'FunctionDeclaration:has(ExportKeyword)>Identifier' }, 26 | { name: 'Exported Classes', value: 'ClassDeclaration:has(ExportKeyword)>Identifier' }, 27 | { name: 'Angular Components', value: 'Decorator>CallExpression[expression.name=Component]' }, 28 | { name: 'Vue Components', value: 'ClassDeclaration:has(HeritageClause Identifier[name=Vue])' }, 29 | { 30 | name: 'React Components', 31 | value: 32 | 'ClassDeclaration:has(HeritageClause PropertyAccessExpression[expression.name=React][name.name=Component])' + 33 | ':not(:has(DeclareKeyword))[members.length>0]', 34 | }, 35 | { 36 | name: 'BDD Tests', 37 | value: 'CallExpression[expression.name=describe] CallExpression[expression.name=it]', 38 | }, 39 | ]; 40 | 41 | constructor( 42 | private astSearch: AstSearchService, 43 | private router: Router, 44 | private route: ActivatedRoute, 45 | ) {} 46 | 47 | public ngOnInit() { 48 | this.route.queryParams.pipe(takeUntil(this.destroy$)).subscribe((params) => { 49 | const { selector } = params; 50 | if (selector && this.astQuery !== selector) { 51 | this.astQuery = selector; 52 | this.search(); 53 | } 54 | }); 55 | } 56 | 57 | public ngOnDestroy() { 58 | this.destroy$.next(); 59 | } 60 | 61 | public async search() { 62 | this.searching = true; 63 | this.queryResponse = {}; 64 | this.updateQueryParams(this.astQuery); 65 | try { 66 | this.queryResponse = await this.astSearch 67 | .search(this.astQuery) 68 | .pipe(first()) 69 | .toPromise(); 70 | } catch (err) { 71 | this.queryResponse = { 72 | error: err && err.message ? err.message : err.toString(), 73 | errorKind: 'requestFailed', 74 | }; 75 | } finally { 76 | this.searching = false; 77 | } 78 | } 79 | 80 | private updateQueryParams(selector: string) { 81 | this.router.navigate(['.'], { queryParams: { selector } }); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/app/search-result/search-result.component.html: -------------------------------------------------------------------------------- 1 |
-------------------------------------------------------------------------------- /src/app/search-result/search-result.component.scss: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urish/bigtsquery/0c5ff6e6eb3d46e9ff835f41745059687cf1ead6/src/app/search-result/search-result.component.scss -------------------------------------------------------------------------------- /src/app/search-result/search-result.component.ts: -------------------------------------------------------------------------------- 1 | import { AfterViewInit, Component, ElementRef, Input, ViewChild } from '@angular/core'; 2 | import * as Prism from 'prismjs'; 3 | import 'prismjs/components/prism-typescript'; 4 | import 'prismjs/plugins/keep-markup/prism-keep-markup'; 5 | import 'prismjs/plugins/line-numbers/prism-line-numbers'; 6 | import { IASTQueryMatch } from '../ast-search.service'; 7 | 8 | @Component({ 9 | selector: 'app-search-result', 10 | templateUrl: './search-result.component.html', 11 | styleUrls: ['./search-result.component.scss'], 12 | }) 13 | export class SearchResultComponent implements AfterViewInit { 14 | @Input() result: IASTQueryMatch; 15 | 16 | @ViewChild('codeEl', { read: ElementRef }) 17 | codeEl: ElementRef; 18 | 19 | constructor() {} 20 | 21 | ngAfterViewInit() { 22 | Prism.highlightElement(this.codeEl.nativeElement); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/app/search-result/search-result.stories.ts: -------------------------------------------------------------------------------- 1 | import { storiesOf } from '@storybook/angular'; 2 | import { SearchResultComponent } from './search-result.component'; 3 | import { HighlightMatchPipe } from '../highlight-match.pipe'; 4 | 5 | import '../../styles.css'; 6 | 7 | storiesOf('SearchResult', module) 8 | .add('with a single line of code', () => ({ 9 | component: SearchResultComponent, 10 | moduleMetadata: { 11 | declarations: [HighlightMatchPipe], 12 | }, 13 | props: { 14 | result: { 15 | text: 'interface MyInterface {}', 16 | line: 0, 17 | matchLine: 0, 18 | matchChar: 10, 19 | matchLength: 11, 20 | }, 21 | }, 22 | })) 23 | .add('with a multiple lines of code', () => ({ 24 | component: SearchResultComponent, 25 | moduleMetadata: { 26 | declarations: [HighlightMatchPipe], 27 | }, 28 | props: { 29 | result: { 30 | line: 1, 31 | matchChar: 0, 32 | matchLine: 2, 33 | matchLength: 151, 34 | text: 35 | `let secureProtocols = ['https:', 'wss:'];\n` + 36 | `function isSecureProtocol(url: string): boolean {\n` + 37 | ` const { protocol } = parse(url.toLowerCase());\n` + 38 | ` return secureProtocols.indexOf(protocol) !== -1;\n` + 39 | `}\n` + 40 | `function g() {`, 41 | }, 42 | }, 43 | })); 44 | -------------------------------------------------------------------------------- /src/app/search-results/search-results.component.html: -------------------------------------------------------------------------------- 1 |

Search results

2 |

3 | No results found. Please check your query and try again. 4 |

5 | 6 |

7 | 12 |

13 | 14 |
-------------------------------------------------------------------------------- /src/app/search-results/search-results.component.scss: -------------------------------------------------------------------------------- 1 | .github-link { 2 | text-decoration: none; 3 | } 4 | 5 | .search-results-title { 6 | padding: 0 24px; 7 | } 8 | -------------------------------------------------------------------------------- /src/app/search-results/search-results.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input } from '@angular/core'; 2 | import { IQueryResult } from '../ast-search.service'; 3 | 4 | @Component({ 5 | selector: 'app-search-results', 6 | templateUrl: './search-results.component.html', 7 | styleUrls: ['./search-results.component.scss'], 8 | }) 9 | export class SearchResultsComponent { 10 | @Input() results: IQueryResult[]; 11 | } 12 | -------------------------------------------------------------------------------- /src/app/search-results/search-results.fixture.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": "f4ad92f94615dd58b69f3508520307385725e556", 4 | "paths": ["mapperCoderZ/seekTheDuck17/blob/master/src/app/shared/map/map.component.ts"], 5 | "text": 6 | " //When using OnPush detectors, then the framework will check an OnPush \n //component when any of its input properties changes, when it fires \n //an event, or when an observable fires an event ~ Victor Savkin (Angular Team)\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class MapComponent implements OnInit, AfterContentInit {\n ", 7 | "line": 11, 8 | "matchLine": 14, 9 | "matchChar": 43, 10 | "matchLength": 6 11 | }, 12 | { 13 | "id": "d143e2d09d4eee4b1d66b40caf474046b4ec89e7", 14 | "paths": [ 15 | "TheOriginalJosh/TypeScript-Angular-Components/blob/master/source/components/cardContainer/selectableCardContainer.ts", 16 | "SamGraber/TypeScript-Angular-Components/blob/master/source/components/cardContainer/selectableCardContainer.ts", 17 | "RenovoSolutions/TypeScript-Angular-Components/blob/master/source/components/cardContainer/selectableCardContainer.ts" 18 | ], 19 | "text": 20 | "\t\t\tuseExisting: forwardRef(() => SelectableCardContainerComponent),\n\t\t},\n\t],\n\tchangeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class SelectableCardContainerComponent extends CardContainerComponent {\n\tprivate _selectionFilteredData: BehaviorSubject[]>;", 21 | "line": 44, 22 | "matchLine": 47, 23 | "matchChar": 42, 24 | "matchLength": 6 25 | }, 26 | { 27 | "id": "af2be413587dae89d8011a217399c04cf163cc1b", 28 | "paths": [ 29 | "andrewseguin/material2/blob/master/src/lib/table/table.ts", 30 | "amcdnl/material2/blob/master/src/lib/table/table.ts", 31 | "crisbeto/material2/blob/master/src/lib/table/table.ts", 32 | "angular/material2/blob/master/src/lib/table/table.ts", 33 | "josephperrott/material2/blob/master/src/lib/table/table.ts" 34 | ], 35 | "text": 36 | " 'class': 'mat-table',\n },\n encapsulation: ViewEncapsulation.None,\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class MatTable extends CdkTable {\n // TODO(andrewseguin): Remove this explicitly set constructor when the compiler knows how to", 37 | "line": 29, 38 | "matchLine": 32, 39 | "matchChar": 43, 40 | "matchLength": 6 41 | }, 42 | { 43 | "id": "90855e2b7e9334d58d2d8cebdf1920b4ebcbc247", 44 | "paths": [ 45 | "mzolkiewski/ng-courses/blob/master/src/app/courses/course-edit/course-edit.component.ts" 46 | ], 47 | "text": 48 | " selector: 'c-course-edit',\n styleUrls: [ './course-edit.component.scss' ],\n templateUrl: './course-edit.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush,\n})\nexport class CourseEditComponent implements OnInit, OnDestroy {\n public editMode = false;", 49 | "line": 29, 50 | "matchLine": 32, 51 | "matchChar": 43, 52 | "matchLength": 6 53 | }, 54 | { 55 | "id": "c13d933aaf9ce64d7d889245c7497b349fd776d3", 56 | "paths": ["BioWareRu/Admin/blob/master/src/app/news/list/newslist.component.ts"], 57 | "text": 58 | " moduleId: module.id,\n selector: 'app-newslist-cmp',\n templateUrl: './newslist.component.html',\n changeDetection: ChangeDetectionStrategy.OnPush\n})\nexport class NewsListComponent extends ListComponent {\n", 59 | "line": 13, 60 | "matchLine": 16, 61 | "matchChar": 43, 62 | "matchLength": 6 63 | } 64 | ] 65 | -------------------------------------------------------------------------------- /src/app/search-results/search-results.stories.ts: -------------------------------------------------------------------------------- 1 | import { MatCardModule } from '@angular/material'; 2 | import '@angular/material/prebuilt-themes/indigo-pink.css'; 3 | import { storiesOf } from '@storybook/angular'; 4 | import '../../styles.css'; 5 | import { FormatRepoLinkPipe } from '../format-repo-link.pipe'; 6 | import { HighlightMatchPipe } from '../highlight-match.pipe'; 7 | import { SearchResultComponent } from '../search-result/search-result.component'; 8 | import { SearchResultsComponent } from './search-results.component'; 9 | 10 | storiesOf('SearchResults', module) 11 | .add('5 search results', () => ({ 12 | component: SearchResultsComponent, 13 | moduleMetadata: { 14 | declarations: [HighlightMatchPipe, FormatRepoLinkPipe, SearchResultComponent], 15 | imports: [MatCardModule], 16 | }, 17 | props: { 18 | results: require('./search-results.fixture.json'), 19 | }, 20 | })) 21 | .add('no search results', () => ({ 22 | component: SearchResultsComponent, 23 | moduleMetadata: { 24 | declarations: [HighlightMatchPipe, FormatRepoLinkPipe, SearchResultComponent], 25 | imports: [MatCardModule], 26 | }, 27 | props: { 28 | results: [], 29 | }, 30 | })); 31 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urish/bigtsquery/0c5ff6e6eb3d46e9ff835f41745059687cf1ead6/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/github-logo.svg: -------------------------------------------------------------------------------- 1 | github-circle-white-transparent -------------------------------------------------------------------------------- /src/browserslist: -------------------------------------------------------------------------------- 1 | # This file is currently used by autoprefixer to adjust CSS to support the below specified browsers 2 | # For additional information regarding the format and rule options, please see: 3 | # https://github.com/browserslist/browserslist#queries 4 | # For IE 9-11 support, please uncomment the last line of the file and adjust as needed 5 | > 0.5% 6 | last 2 versions 7 | Firefox ESR 8 | not dead 9 | # IE 9-11 -------------------------------------------------------------------------------- /src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // This file can be replaced during build by using the `fileReplacements` array. 2 | // `ng build ---prod` replaces `environment.ts` with `environment.prod.ts`. 3 | // The list of file replacements can be found in `angular.json`. 4 | 5 | export const environment = { 6 | production: false 7 | }; 8 | 9 | /* 10 | * In development mode, to ignore zone related error stack frames such as 11 | * `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can 12 | * import the following file, but please comment it out in production mode 13 | * because it will have performance impact when throw error 14 | */ 15 | // import 'zone.js/dist/zone-error'; // Included with Angular CLI. 16 | -------------------------------------------------------------------------------- /src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urish/bigtsquery/0c5ff6e6eb3d46e9ff835f41745059687cf1ead6/src/favicon.ico -------------------------------------------------------------------------------- /src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BigTSQuery 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/1.0/config/configuration-file.html 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular-devkit/build-angular'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular-devkit/build-angular/plugins/karma'), 14 | ], 15 | client: { 16 | clearContext: false, // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | coverageIstanbulReporter: { 19 | dir: require('path').join(__dirname, '../coverage'), 20 | reports: ['html', 'lcovonly'], 21 | fixWebpackSourcePaths: true, 22 | }, 23 | reporters: ['progress', 'kjhtml'], 24 | port: 9876, 25 | colors: true, 26 | logLevel: config.LOG_INFO, 27 | autoWatch: true, 28 | browsers: ['Chrome'], 29 | customLaunchers: { 30 | ChromeNoSandbox: { 31 | base: 'Chrome', 32 | flags: ['--no-sandbox'], 33 | }, 34 | }, 35 | singleRun: false, 36 | }); 37 | }; 38 | -------------------------------------------------------------------------------- /src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule) 12 | .catch(err => console.log(err)); 13 | -------------------------------------------------------------------------------- /src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/weak-map'; 35 | // import 'core-js/es6/set'; 36 | 37 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 38 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 39 | 40 | /** IE10 and IE11 requires the following for the Reflect API. */ 41 | // import 'core-js/es6/reflect'; 42 | 43 | 44 | /** Evergreen browsers require these. **/ 45 | // Used for reflect-metadata in JIT. If you use AOT (and only Angular decorators), you can remove. 46 | import 'core-js/es7/reflect'; 47 | 48 | 49 | /** 50 | * Web Animations `@angular/platform-browser/animations` 51 | * Only required if AnimationBuilder is used within the application and using IE/Edge or Safari. 52 | * Standard animation support in Angular DOES NOT require any polyfills (as of Angular 6.0). 53 | **/ 54 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 55 | 56 | /** 57 | * By default, zone.js will patch all possible macroTask and DomEvents 58 | * user can disable parts of macroTask/DomEvents patch by setting following flags 59 | */ 60 | 61 | // (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame 62 | // (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick 63 | // (window as any).__zone_symbol__BLACK_LISTED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames 64 | 65 | /* 66 | * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js 67 | * with the following flag, it will bypass `zone.js` patch for IE/Edge 68 | */ 69 | // (window as any).__Zone_enable_cross_context_check = true; 70 | 71 | /*************************************************************************************************** 72 | * Zone JS is required by default for Angular itself. 73 | */ 74 | import 'zone.js/dist/zone'; // Included with Angular CLI. 75 | 76 | 77 | 78 | /*************************************************************************************************** 79 | * APPLICATION IMPORTS 80 | */ 81 | -------------------------------------------------------------------------------- /src/styles.css: -------------------------------------------------------------------------------- 1 | @import '~prismjs/themes/prism.css'; 2 | @import '~prismjs/plugins/line-numbers/prism-line-numbers.css'; 3 | 4 | body { 5 | margin: 0; 6 | } 7 | 8 | a { 9 | text-decoration: none; 10 | } 11 | -------------------------------------------------------------------------------- /src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/zone-testing'; 4 | import { getTestBed } from '@angular/core/testing'; 5 | import { 6 | BrowserDynamicTestingModule, 7 | platformBrowserDynamicTesting 8 | } from '@angular/platform-browser-dynamic/testing'; 9 | 10 | declare const require: any; 11 | 12 | // First, initialize the Angular testing environment. 13 | getTestBed().initTestEnvironment( 14 | BrowserDynamicTestingModule, 15 | platformBrowserDynamicTesting() 16 | ); 17 | // Then we find all the tests. 18 | const context = require.context('./', true, /\.spec\.ts$/); 19 | // And load the modules. 20 | context.keys().map(context); 21 | -------------------------------------------------------------------------------- /src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "types": [] 7 | }, 8 | "exclude": ["src/test.ts", "**/*.spec.ts", "**/*.stories.ts"] 9 | } 10 | -------------------------------------------------------------------------------- /src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "types": ["jasmine", "node"] 7 | }, 8 | "files": ["test.ts", "polyfills.ts"], 9 | "include": ["**/*.spec.ts", "**/*.d.ts"], 10 | "exclude": ["**/*.stories.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /src/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tslint.json", 3 | "rules": { 4 | "directive-selector": [ 5 | true, 6 | "attribute", 7 | "app", 8 | "camelCase" 9 | ], 10 | "component-selector": [ 11 | true, 12 | "element", 13 | "app", 14 | "kebab-case" 15 | ] 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "baseUrl": "./", 5 | "outDir": "./dist/out-tsc", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "noImplicitAny": true, 12 | "noImplicitReturns": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "noImplicitThis": true, 15 | "strictNullChecks": true, 16 | "noUnusedLocals": true, 17 | "target": "es5", 18 | "typeRoots": ["node_modules/@types"], 19 | "lib": ["es2017", "dom"] 20 | }, 21 | "include": ["src/**/*.ts"] 22 | } 23 | -------------------------------------------------------------------------------- /tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "arrow-return-shorthand": true, 7 | "callable-types": true, 8 | "class-name": true, 9 | "comment-format": [ 10 | true, 11 | "check-space" 12 | ], 13 | "curly": true, 14 | "deprecation": { 15 | "severity": "warn" 16 | }, 17 | "eofline": true, 18 | "forin": true, 19 | "import-blacklist": [ 20 | true, 21 | "rxjs/Rx" 22 | ], 23 | "import-spacing": true, 24 | "indent": [ 25 | true, 26 | "spaces" 27 | ], 28 | "interface-over-type-literal": true, 29 | "label-position": true, 30 | "max-line-length": [ 31 | true, 32 | 140 33 | ], 34 | "member-access": false, 35 | "member-ordering": [ 36 | true, 37 | { 38 | "order": [ 39 | "static-field", 40 | "instance-field", 41 | "static-method", 42 | "instance-method" 43 | ] 44 | } 45 | ], 46 | "no-arg": true, 47 | "no-bitwise": true, 48 | "no-console": [ 49 | true, 50 | "debug", 51 | "info", 52 | "time", 53 | "timeEnd", 54 | "trace" 55 | ], 56 | "no-construct": true, 57 | "no-debugger": true, 58 | "no-duplicate-super": true, 59 | "no-empty": false, 60 | "no-empty-interface": true, 61 | "no-eval": true, 62 | "no-inferrable-types": [ 63 | true, 64 | "ignore-params" 65 | ], 66 | "no-misused-new": true, 67 | "no-non-null-assertion": true, 68 | "no-shadowed-variable": true, 69 | "no-string-literal": false, 70 | "no-string-throw": true, 71 | "no-switch-case-fall-through": true, 72 | "no-trailing-whitespace": true, 73 | "no-unnecessary-initializer": true, 74 | "no-unused-expression": true, 75 | "no-use-before-declare": true, 76 | "no-var-keyword": true, 77 | "object-literal-sort-keys": false, 78 | "one-line": [ 79 | true, 80 | "check-open-brace", 81 | "check-catch", 82 | "check-else", 83 | "check-whitespace" 84 | ], 85 | "prefer-const": true, 86 | "quotemark": [ 87 | true, 88 | "single" 89 | ], 90 | "radix": true, 91 | "semicolon": [ 92 | true, 93 | "always" 94 | ], 95 | "triple-equals": [ 96 | true, 97 | "allow-null-check" 98 | ], 99 | "typedef-whitespace": [ 100 | true, 101 | { 102 | "call-signature": "nospace", 103 | "index-signature": "nospace", 104 | "parameter": "nospace", 105 | "property-declaration": "nospace", 106 | "variable-declaration": "nospace" 107 | } 108 | ], 109 | "unified-signatures": true, 110 | "variable-name": false, 111 | "whitespace": [ 112 | true, 113 | "check-branch", 114 | "check-decl", 115 | "check-operator", 116 | "check-separator", 117 | "check-type" 118 | ], 119 | "no-output-on-prefix": true, 120 | "use-input-property-decorator": true, 121 | "use-output-property-decorator": true, 122 | "use-host-property-decorator": true, 123 | "no-input-rename": true, 124 | "no-output-rename": true, 125 | "use-life-cycle-interface": true, 126 | "use-pipe-transform-interface": true, 127 | "component-class-suffix": true, 128 | "directive-class-suffix": true 129 | } 130 | } 131 | --------------------------------------------------------------------------------