Skip to content

Commit 6663632

Browse files
committed
Setup lerna and add textcomplete and textcomplete-core
1 parent c9943cc commit 6663632

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1263
-13346
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
root = true
22

33
[*]
4-
charset = utf-8
54
end_of_line = lf
65
insert_final_newline = true
7-
8-
[*.{js,jade,css}]
6+
charset = utf-8
97
indent_style = space
108
indent_size = 2

.eslintignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages/*
2+
!packages/textcomplete-core
3+
!packages/textcomplete
4+
packages/*/dist

.eslintrc.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
root: true
2+
parser: '@typescript-eslint/parser'
3+
parserOptions:
4+
sourceType: 'module'
5+
env:
6+
browser: true
7+
plugins:
8+
- '@typescript-eslint'
9+
extends:
10+
- 'plugin:@typescript-eslint/recommended'
11+
- 'plugin:prettier/recommended'
12+
- 'prettier/@typescript-eslint'
13+
rules:
14+
'@typescript-eslint/no-unused-vars':
15+
- 'error'
16+
- ignoreRestSiblings: true
17+
argsIgnorePattern: '^_'

.github/workflows/test.yaml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Test
2+
on: push
3+
jobs:
4+
test:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- uses: actions/checkout@v2
8+
- uses: actions/setup-node@v1
9+
with:
10+
node-version: 12.x
11+
- run: yarn install --no-lockfile && yarn lerna bootstrap
12+
- run: yarn lint
13+
- run: yarn test

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
node_modules
22
bower_components
3+
dist
4+
yarn.lock
5+
.vscode/*
6+
!.vscode/textcomplete.code-workspace

.prettierignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
packages/*
2+
!packages/textcomplete-core
3+
!packages/textcomplete
4+
packages/*/dist

.vscode/textcomplete.code-workspace

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"folders": [
3+
{
4+
"name": "root",
5+
"path": "../",
6+
},
7+
{
8+
"name": "core",
9+
"path": "../packages/textcomplete-core",
10+
},
11+
{
12+
"name": "textarea",
13+
"path": "../packages/textcomplete",
14+
}
15+
],
16+
"settings": {
17+
"editor.wordWrap": "on",
18+
"editor.formatOnSave": false,
19+
"[typescript]": {
20+
"editor.formatOnSave": true
21+
},
22+
"[typescriptreact]": {
23+
"editor.formatOnSave": true
24+
},
25+
"[javascript]": {
26+
"editor.formatOnSave": true
27+
},
28+
"[javascriptreact]": {
29+
"editor.formatOnSave": true
30+
}
31+
},
32+
"extensions": {
33+
"recommendations": [
34+
"dbaeumer.vscode-eslint",
35+
"editorconfig.editorconfig",
36+
"esbenp.prettier-vscode",
37+
]
38+
}
39+
}

jest.config.js

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// For a detailed explanation regarding each configuration property, visit:
2+
// https://jestjs.io/docs/en/configuration.html
3+
4+
module.exports = {
5+
// All imported modules in your tests should be mocked automatically
6+
// automock: false,
7+
8+
// Stop running tests after `n` failures
9+
// bail: 0,
10+
11+
// The directory where Jest should store its cached dependency information
12+
// cacheDirectory: "/private/var/folders/ff/rqfmxyk16xb365btr3hbdfw80000gn/T/jest_dx",
13+
14+
// Automatically clear mock calls and instances between every test
15+
clearMocks: true,
16+
17+
// Indicates whether the coverage information should be collected while executing the test
18+
// collectCoverage: false,
19+
20+
// An array of glob patterns indicating a set of files for which coverage information should be collected
21+
// collectCoverageFrom: undefined,
22+
23+
// The directory where Jest should output its coverage files
24+
coverageDirectory: "coverage",
25+
26+
// An array of regexp pattern strings used to skip coverage collection
27+
// coveragePathIgnorePatterns: [
28+
// "/node_modules/"
29+
// ],
30+
31+
// A list of reporter names that Jest uses when writing coverage reports
32+
// coverageReporters: [
33+
// "json",
34+
// "text",
35+
// "lcov",
36+
// "clover"
37+
// ],
38+
39+
// An object that configures minimum threshold enforcement for coverage results
40+
// coverageThreshold: undefined,
41+
42+
// A path to a custom dependency extractor
43+
// dependencyExtractor: undefined,
44+
45+
// Make calling deprecated APIs throw helpful error messages
46+
// errorOnDeprecated: false,
47+
48+
// Force coverage collection from ignored files using an array of glob patterns
49+
// forceCoverageMatch: [],
50+
51+
// A path to a module which exports an async function that is triggered once before all test suites
52+
// globalSetup: undefined,
53+
54+
// A path to a module which exports an async function that is triggered once after all test suites
55+
// globalTeardown: undefined,
56+
57+
// A set of global variables that need to be available in all test environments
58+
// globals: {},
59+
60+
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
61+
// maxWorkers: "50%",
62+
63+
// An array of directory names to be searched recursively up from the requiring module's location
64+
// moduleDirectories: [
65+
// "node_modules"
66+
// ],
67+
68+
// An array of file extensions your modules use
69+
// moduleFileExtensions: [
70+
// "js",
71+
// "json",
72+
// "jsx",
73+
// "ts",
74+
// "tsx",
75+
// "node"
76+
// ],
77+
78+
// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
79+
// moduleNameMapper: {},
80+
81+
// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
82+
// modulePathIgnorePatterns: [],
83+
84+
// Activates notifications for test results
85+
// notify: false,
86+
87+
// An enum that specifies notification mode. Requires { notify: true }
88+
// notifyMode: "failure-change",
89+
90+
// A preset that is used as a base for Jest's configuration
91+
preset: "ts-jest",
92+
93+
// Run tests from one or more projects
94+
// projects: undefined,
95+
96+
// Use this configuration option to add custom reporters to Jest
97+
// reporters: undefined,
98+
99+
// Automatically reset mock state between every test
100+
// resetMocks: false,
101+
102+
// Reset the module registry before running each individual test
103+
// resetModules: false,
104+
105+
// A path to a custom resolver
106+
// resolver: undefined,
107+
108+
// Automatically restore mock state between every test
109+
// restoreMocks: false,
110+
111+
// The root directory that Jest should scan for tests and modules within
112+
// rootDir: undefined,
113+
114+
// A list of paths to directories that Jest should use to search for files in
115+
// roots: [
116+
// "<rootDir>"
117+
// ],
118+
119+
// Allows you to use a custom runner instead of Jest's default test runner
120+
// runner: "jest-runner",
121+
122+
// The paths to modules that run some code to configure or set up the testing environment before each test
123+
// setupFiles: [],
124+
125+
// A list of paths to modules that run some code to configure or set up the testing framework before each test
126+
// setupFilesAfterEnv: [],
127+
128+
// A list of paths to snapshot serializer modules Jest should use for snapshot testing
129+
// snapshotSerializers: [],
130+
131+
// The test environment that will be used for testing
132+
// testEnvironment: "jest-environment-jsdom",
133+
134+
// Options that will be passed to the testEnvironment
135+
// testEnvironmentOptions: {},
136+
137+
// Adds a location field to test results
138+
// testLocationInResults: false,
139+
140+
// The glob patterns Jest uses to detect test files
141+
// testMatch: [
142+
// "**/__tests__/**/*.[jt]s?(x)",
143+
// "**/?(*.)+(spec|test).[tj]s?(x)"
144+
// ],
145+
146+
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
147+
// testPathIgnorePatterns: [
148+
// "/node_modules/"
149+
// ],
150+
151+
// The regexp pattern or array of patterns that Jest uses to detect test files
152+
// testRegex: [],
153+
154+
// This option allows the use of a custom results processor
155+
// testResultsProcessor: undefined,
156+
157+
// This option allows use of a custom test runner
158+
// testRunner: "jasmine2",
159+
160+
// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
161+
// testURL: "http://localhost",
162+
163+
// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
164+
// timers: "real",
165+
166+
// A map from regular expressions to paths to transformers
167+
// transform: undefined,
168+
169+
// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
170+
// transformIgnorePatterns: [
171+
// "/node_modules/"
172+
// ],
173+
174+
// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
175+
// unmockedModulePathPatterns: undefined,
176+
177+
// Indicates whether each individual test should be reported during the run
178+
// verbose: undefined,
179+
180+
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
181+
// watchPathIgnorePatterns: [],
182+
183+
// Whether to use watchman for file crawling
184+
// watchman: true,
185+
}

lerna.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"npmClient": "yarn",
3+
"useWorkspaces": true,
4+
"packages": [
5+
"packages/textcomplete-core",
6+
"packages/textcomplete"
7+
],
8+
"version": "independent"
9+
}

package.json

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "root",
3+
"private": true,
4+
"workspaces": [
5+
"packages/textcomplete-core",
6+
"packages/textcomplete"
7+
],
8+
"scripts": {
9+
"format:eslint": "eslint --fix 'packages/**/*.ts'",
10+
"format:prettier": "prettier --write 'packages/**/*.ts'",
11+
"format": "run-s format:eslint format:prettier",
12+
"lint": "eslint 'packages/**/*.ts'",
13+
"test": "jest"
14+
},
15+
"devDependencies": {
16+
"@types/jest": "^26.0.0",
17+
"@typescript-eslint/eslint-plugin": "^3.2.0",
18+
"@typescript-eslint/parser": "^3.2.0",
19+
"eslint-config-prettier": "^6.11.0",
20+
"eslint-plugin-prettier": "^3.1.3",
21+
"eslint": "^7.2.0",
22+
"jest": "^26.0.1",
23+
"lerna": "^3.22.1",
24+
"npm-run-all": "^4.1.5",
25+
"prettier": "^2.0.5",
26+
"ts-jest": "^26.1.0",
27+
"typescript": "^3.9.5"
28+
},
29+
"prettier": {
30+
"semi": false
31+
}
32+
}

packages/textcomplete-core/.npmignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tsconfig.json
2+
yarn.lock

packages/textcomplete-core/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @textcomplete/core
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "@textcomplete/core",
3+
"version": "0.0.0",
4+
"description": "Textcomplete core.",
5+
"main": "dist/index.js",
6+
"types": "dist/index.d.ts",
7+
"repository": "https://github.com/yuku/textcomplete",
8+
"homepage": "https://github.com/yuku/textcomplete",
9+
"author": "Yuku Takahashi",
10+
"license": "MIT",
11+
"scripts": {
12+
"build": "rm -fr dist && tsc"
13+
},
14+
"dependencies": {
15+
"eventemitter3": "^4.0.4"
16+
},
17+
"devDependencies": {
18+
"typescript": "^3.9.5"
19+
}
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { EventEmitter } from "eventemitter3"
2+
3+
import { Strategy, StrategyProps } from "./Strategy"
4+
import { Query } from "./Query"
5+
import { SearchResult } from "./SearchResult"
6+
7+
export class Completer extends EventEmitter {
8+
private readonly strategies: Strategy<unknown>[]
9+
10+
constructor(strategyPropsList: StrategyProps<unknown>[]) {
11+
super()
12+
this.strategies = strategyPropsList.map((p) => new Strategy(p))
13+
}
14+
15+
destroy(): this {
16+
this.strategies.forEach((s) => s.destroy())
17+
return this
18+
}
19+
20+
run(beforeCursor: string): void {
21+
const query = this.extractQuery(beforeCursor)
22+
if (query) {
23+
query.execute(this.handleQueryResult)
24+
} else {
25+
this.handleQueryResult([])
26+
}
27+
}
28+
29+
private extractQuery(beforeCursor: string): Query<unknown> | void {
30+
for (const strategy of this.strategies) {
31+
const query = Query.create(strategy, beforeCursor)
32+
if (query) return query
33+
}
34+
}
35+
36+
private handleQueryResult = <T>(searchResults: SearchResult<T>[]) => {
37+
this.emit("hit", { searchResults })
38+
}
39+
}

0 commit comments

Comments
 (0)