Skip to content

Commit

Permalink
feat(js): add typescript to the js template (algolia/create-instantse…
Browse files Browse the repository at this point in the history
…arch-app#464)

* feat(js): add typescript to the js template

based on the (for now) not exported as TS https://github.com/algolia/instantsearch.js/blob/master/src/index.ts

* update import method

* correct file
  • Loading branch information
Haroenv authored Aug 24, 2021
1 parent 23d5d3e commit a4fd90a
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
41 changes: 39 additions & 2 deletions e2e/__snapshots__/templates.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3130,7 +3130,7 @@ exports[`Templates InstantSearch.js File content: index.html 1`] = `
<div id=\\"pagination\\"></div>
</div>
<script src=\\"https://cdn.jsdelivr.net/algoliasearch/3.32.0/algoliasearchLite.min.js\\"></script>
<script src=\\"https://cdn.jsdelivr.net/algoliasearch/4.10.4/algoliasearchLite.min.js\\"></script>
<script src=\\"https://cdn.jsdelivr.net/npm/[email protected]\\"></script>
<script src=\\"./src/app.js\\"></script>
</body>
Expand Down Expand Up @@ -3168,7 +3168,9 @@ exports[`Templates InstantSearch.js File content: package.json 1`] = `
\\"lint\\": \\"eslint .\\",
\\"lint:fix\\": \\"npm run lint -- --fix\\"
},
\\"partialDependencies\\": {}
\\"partialDependencies\\": {
\\"instantsearch.js\\": \\"3.0.0\\"
}
}"
`;
Expand Down Expand Up @@ -3277,6 +3279,18 @@ search.addWidgets([
search.start();"
`;
exports[`Templates InstantSearch.js File content: src/global.d.ts 1`] = `
"import algoliasearch from 'algoliasearch/lite';
import instantsearch from 'instantsearch.js/dist/instantsearch.production.min';
declare global {
interface Window {
algoliasearch: typeof algoliasearch;
instantsearch: typeof instantsearch;
}
}"
`;
exports[`Templates InstantSearch.js File content: src/index.css 1`] = `
"body,
h1 {
Expand All @@ -3290,6 +3304,27 @@ body {
}"
`;
exports[`Templates InstantSearch.js File content: tsconfig.json 1`] = `
"{
\\"compilerOptions\\": {
\\"module\\": \\"commonjs\\",
\\"esModuleInterop\\": true,
\\"sourceMap\\": true,
\\"allowJs\\": true,
\\"lib\\": [
\\"es6\\",
\\"dom\\"
],
\\"rootDir\\": \\"src\\",
\\"moduleResolution\\": \\"node\\"
},
\\"include\\": [
\\"src\\",
\\"src/global.d.ts\\"
]
}"
`;
exports[`Templates InstantSearch.js Folder structure: contains the right files 1`] = `
Array [
".editorconfig",
Expand All @@ -3304,7 +3339,9 @@ Array [
"package.json",
"src/app.css",
"src/app.js",
"src/global.d.ts",
"src/index.css",
"tsconfig.json",
]
`;
Expand Down
2 changes: 1 addition & 1 deletion src/templates/InstantSearch.js/index.html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<div id="pagination"></div>
</div>

<script src="https://cdn.jsdelivr.net/algoliasearch/3.32.0/algoliasearchLite.min.js"></script>
<script src="https://cdn.jsdelivr.net/algoliasearch/4.10.4/algoliasearchLite.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/instantsearch.js@{{libraryVersion}}"></script>
<script src="./src/app.js"></script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions src/templates/InstantSearch.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@
"eslint-plugin-prettier": "3.1.2",
"parcel-bundler": "1.12.5",
"prettier": "1.19.1"
},
"dependencies": {
"algoliasearch": "4.10.4",
"instantsearch.js": "{{libraryVersion}}"
}
}
9 changes: 9 additions & 0 deletions src/templates/InstantSearch.js/src/global.d.ts.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import algoliasearch from 'algoliasearch/lite';
import instantsearch from 'instantsearch.js/dist/instantsearch.production.min';

declare global {
interface Window {
algoliasearch: typeof algoliasearch;
instantsearch: typeof instantsearch;
}
}
18 changes: 18 additions & 0 deletions src/templates/InstantSearch.js/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"esModuleInterop": true,
"sourceMap": true,
"allowJs": true,
"lib": [
"es6",
"dom"
],
"rootDir": "src",
"moduleResolution": "node"
},
"include": [
"src",
"src/global.d.ts"
]
}

0 comments on commit a4fd90a

Please sign in to comment.