Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 1dc0d03

Browse files
feat(templates): Add JavaScript Client template (#77)
1 parent fe9a51c commit 1dc0d03

File tree

18 files changed

+590
-4
lines changed

18 files changed

+590
-4
lines changed
3.6 KB
Loading

scripts/__snapshots__/e2e-templates.test.js.snap

Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2999,6 +2999,320 @@ Array [
29992999
]
30003000
`;
30013001
3002+
exports[`Templates JavaScript Client File content: .editorconfig 1`] = `
3003+
"root = true
3004+
3005+
[*]
3006+
charset = utf-8
3007+
indent_style = space
3008+
indent_size = 2
3009+
end_of_line = lf
3010+
insert_final_newline = true
3011+
trim_trailing_whitespace = true"
3012+
`;
3013+
3014+
exports[`Templates JavaScript Client File content: .eslintignore 1`] = `
3015+
"/node_modules
3016+
/dist
3017+
/.cache"
3018+
`;
3019+
3020+
exports[`Templates JavaScript Client File content: .eslintrc.js 1`] = `
3021+
"module.exports = {
3022+
extends: 'algolia',
3023+
};"
3024+
`;
3025+
3026+
exports[`Templates JavaScript Client File content: .gitignore 1`] = `
3027+
"# See https://help.github.com/ignore-files/ for more about ignoring files.
3028+
3029+
# dependencies
3030+
/node_modules
3031+
3032+
# testing
3033+
/coverage
3034+
3035+
# production
3036+
/dist
3037+
/.cache
3038+
3039+
# misc
3040+
.DS_Store
3041+
.env.local
3042+
.env.development.local
3043+
.env.test.local
3044+
.env.production.local
3045+
3046+
npm-debug.log*
3047+
yarn-debug.log*
3048+
yarn-error.log*"
3049+
`;
3050+
3051+
exports[`Templates JavaScript Client File content: .prettierrc 1`] = `
3052+
"{
3053+
\\"singleQuote\\": true,
3054+
\\"proseWrap\\": \\"never\\",
3055+
\\"trailingComma\\": \\"es5\\"
3056+
}"
3057+
`;
3058+
3059+
exports[`Templates JavaScript Client File content: README.md 1`] = `
3060+
"# javascript-client-app
3061+
3062+
_This project was generated with [create-instantsearch-app](https://github.com/algolia/create-instantsearch-app) by [Algolia](https://algolia.com)._
3063+
3064+
## Get started
3065+
3066+
To run this project locally, install the dependencies and run the local server:
3067+
3068+
\`\`\`sh
3069+
npm install
3070+
npm start
3071+
\`\`\`
3072+
3073+
Alternatively, you may use [Yarn](https://http://yarnpkg.com/):
3074+
3075+
\`\`\`sh
3076+
yarn
3077+
yarn start
3078+
\`\`\`"
3079+
`;
3080+
3081+
exports[`Templates JavaScript Client File content: index.html 1`] = `
3082+
"<!DOCTYPE html>
3083+
<html lang=\\"en\\">
3084+
3085+
<head>
3086+
<meta charset=\\"utf-8\\">
3087+
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1, shrink-to-fit=no\\">
3088+
<meta name=\\"theme-color\\" content=\\"#000000\\">
3089+
3090+
<link rel=\\"manifest\\" href=\\"./manifest.webmanifest\\">
3091+
<link rel=\\"shortcut icon\\" href=\\"./favicon.png\\">
3092+
3093+
<link rel=\\"stylesheet\\" href=\\"./src/index.css\\">
3094+
<link rel=\\"stylesheet\\" href=\\"./src/app.css\\">
3095+
3096+
<title>javascript-client-app</title>
3097+
</head>
3098+
3099+
<body>
3100+
<header class=\\"header\\">
3101+
<h1 class=\\"header-title\\">
3102+
<a href=\\"/\\">javascript-client-app</a>
3103+
</h1>
3104+
<p class=\\"header-subtitle\\">using the
3105+
<a href=\\"https://github.com/algolia/algoliasearch-client-javascript\\">Algolia Search API Client for JavaScript</a>
3106+
</p>
3107+
</header>
3108+
3109+
<div class=\\"container\\">
3110+
<div class=\\"container-app\\">
3111+
<div class=\\"filters\\"></div>
3112+
3113+
<div class=\\"search-container\\">
3114+
<div id=\\"searchBox\\">
3115+
<form role=\\"search\\">
3116+
<input type=\\"search\\" placeholder=\\"Search placeholder\\" />
3117+
</form>
3118+
</div>
3119+
<div id=\\"hits\\"></div>
3120+
</div>
3121+
</div>
3122+
</div>
3123+
3124+
<script src=\\"./src/app.js\\"></script>
3125+
</body>
3126+
3127+
</html>"
3128+
`;
3129+
3130+
exports[`Templates JavaScript Client File content: manifest.webmanifest 1`] = `
3131+
"{
3132+
\\"short_name\\": \\"javascript-client-app\\",
3133+
\\"name\\": \\"javascript-client-app Sample\\",
3134+
\\"icons\\": [
3135+
{
3136+
\\"src\\": \\"favicon.png\\",
3137+
\\"sizes\\": \\"64x64 32x32 24x24 16x16\\",
3138+
\\"type\\": \\"image/x-icon\\"
3139+
}
3140+
],
3141+
\\"start_url\\": \\"./index.html\\",
3142+
\\"display\\": \\"standalone\\",
3143+
\\"theme_color\\": \\"#000000\\",
3144+
\\"background_color\\": \\"#ffffff\\"
3145+
}"
3146+
`;
3147+
3148+
exports[`Templates JavaScript Client File content: package.json 1`] = `
3149+
"{
3150+
\\"name\\": \\"javascript-client-app\\",
3151+
\\"version\\": \\"1.0.0\\",
3152+
\\"private\\": true,
3153+
\\"scripts\\": {
3154+
\\"start\\": \\"parcel index.html --port 3000\\",
3155+
\\"build\\": \\"parcel build index.html\\",
3156+
\\"lint\\": \\"eslint .\\",
3157+
\\"lint:fix\\": \\"npm run lint -- --fix\\"
3158+
},
3159+
\\"dependencies\\": {
3160+
\\"algoliasearch\\": \\"1.0.0\\"
3161+
},
3162+
\\"devDependencies\\": {
3163+
\\"babel-eslint\\": \\"8.2.5\\",
3164+
\\"eslint\\": \\"4.19.1\\",
3165+
\\"eslint-config-algolia\\": \\"13.1.0\\",
3166+
\\"eslint-config-prettier\\": \\"2.9.0\\",
3167+
\\"eslint-plugin-import\\": \\"2.13.0\\",
3168+
\\"eslint-plugin-prettier\\": \\"2.6.1\\",
3169+
\\"parcel-bundler\\": \\"1.9.4\\",
3170+
\\"prettier\\": \\"1.13.7\\"
3171+
}
3172+
}"
3173+
`;
3174+
3175+
exports[`Templates JavaScript Client File content: src/app.css 1`] = `
3176+
"em {
3177+
background: cyan;
3178+
font-style: normal;
3179+
}
3180+
3181+
.header {
3182+
display: flex;
3183+
align-items: center;
3184+
min-height: 50px;
3185+
padding: 0.5rem 1rem;
3186+
background-image: linear-gradient(73deg, #3369e7, #1cc7d0);
3187+
color: #fff;
3188+
margin-bottom: 1rem;
3189+
}
3190+
3191+
.header a {
3192+
color: #fff;
3193+
text-decoration: none;
3194+
}
3195+
3196+
.header-title {
3197+
font-size: 1.2rem;
3198+
font-weight: normal;
3199+
}
3200+
3201+
.header-title::after {
3202+
content: ' ▸ ';
3203+
padding: 0 0.5rem;
3204+
}
3205+
3206+
.header-subtitle {
3207+
font-size: 1.2rem;
3208+
}
3209+
3210+
.container {
3211+
max-width: 1200px;
3212+
margin: 0 auto;
3213+
padding: 1rem;
3214+
}
3215+
3216+
.container-app {
3217+
display: grid;
3218+
}
3219+
3220+
#searchBox input[type=\\"search\\"] {
3221+
width: 100%;
3222+
padding: 12px;
3223+
font: inherit;
3224+
border-radius: 2px;
3225+
border: 1px solid rgba(150, 150, 150, 0.16);
3226+
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.16);
3227+
}
3228+
3229+
.ais-hits {
3230+
display: grid;
3231+
grid-template-columns: 49% 49%;
3232+
grid-gap: 2%;
3233+
list-style: none;
3234+
padding: 0;
3235+
margin: 0;
3236+
}
3237+
3238+
.ais-hits--item {
3239+
min-height: 100px;
3240+
padding: 1rem;
3241+
background: #fff;
3242+
border-radius: 4px;
3243+
border: 1px solid rgba(150, 150, 150, 0.16);
3244+
box-shadow: 0 1px 1px 0 rgba(0, 0, 0, 0.16);
3245+
margin-bottom: 1rem;
3246+
}
3247+
3248+
#searchBox {
3249+
margin-bottom: 2rem;
3250+
}"
3251+
`;
3252+
3253+
exports[`Templates JavaScript Client File content: src/app.js 1`] = `
3254+
"import algoliasearch from 'algoliasearch';
3255+
3256+
const client = algoliasearch('appId', 'apiKey');
3257+
const index = client.initIndex('indexName');
3258+
3259+
const $searchBox = document.querySelector('#searchBox input[type=search]');
3260+
const $hits = document.querySelector('#hits');
3261+
3262+
function renderHits(query) {
3263+
index.search(query).then(result => {
3264+
// Please sanitize user-provided data when using \`innerHTML\` to avoid XSS
3265+
$hits.innerHTML = \`
3266+
<ul class=\\"ais-hits\\">
3267+
\${result.hits
3268+
.map(hit => \`<li class=\\"ais-hits--item\\">\${hit._highlightResult.mainAttribute.value}</li>\`)
3269+
.join('')}
3270+
</ul>\`;
3271+
});
3272+
}
3273+
3274+
$searchBox.addEventListener('input', event => {
3275+
const query = event.target.value;
3276+
3277+
renderHits(query);
3278+
});
3279+
3280+
document.addEventListener('DOMContentLoaded', () => {
3281+
renderHits('');
3282+
});"
3283+
`;
3284+
3285+
exports[`Templates JavaScript Client File content: src/index.css 1`] = `
3286+
"body,
3287+
h1 {
3288+
margin: 0;
3289+
padding: 0;
3290+
}
3291+
3292+
body {
3293+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica,
3294+
Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
3295+
}"
3296+
`;
3297+
3298+
exports[`Templates JavaScript Client Folder structure: contains the right files 1`] = `
3299+
Array [
3300+
".editorconfig",
3301+
".eslintignore",
3302+
".eslintrc.js",
3303+
".gitignore",
3304+
".prettierrc",
3305+
"README.md",
3306+
"favicon.png",
3307+
"index.html",
3308+
"manifest.webmanifest",
3309+
"package.json",
3310+
"src/app.css",
3311+
"src/app.js",
3312+
"src/index.css",
3313+
]
3314+
`;
3315+
30023316
exports[`Templates React InstantSearch File content: .editorconfig 1`] = `
30033317
"root = true
30043318
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
3+
exports[`Options with unknown template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, JavaScript Client, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
44

55
exports[`Options with unvalid name throws 1`] = `
66
"Could not create a project called \\"./WrongNpmName\\" because of npm naming restrictions.
77
- name cannot start with a period
88
- name can only contain URL-friendly characters"
99
`;
1010

11-
exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
11+
exports[`Options with wrong template path throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, JavaScript Client, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
1212

1313
exports[`Options without path throws 1`] = `"The option \`path\` is required."`;
1414

15-
exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;
15+
exports[`Options without template throws 1`] = `"The template directory must contain a configuration file \`.template.js\` or must be one of those: Angular InstantSearch, Autocomplete.js, InstantSearch Android, InstantSearch iOS, InstantSearch.js, JavaScript Client, React InstantSearch, React InstantSearch Native, Vue InstantSearch"`;

src/cli/index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const {
1212
checkAppName,
1313
getAppTemplateConfig,
1414
fetchLibraryVersions,
15-
getAllTemplates,
1615
getTemplatesByCategory,
1716
getTemplatePath,
1817
} = require('../utils');
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
/dist
3+
/.cache
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: 'algolia',
3+
};
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# See https://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
6+
# testing
7+
/coverage
8+
9+
# production
10+
/dist
11+
/.cache
12+
13+
# misc
14+
.DS_Store
15+
.env.local
16+
.env.development.local
17+
.env.test.local
18+
.env.production.local
19+
20+
npm-debug.log*
21+
yarn-debug.log*
22+
yarn-error.log*
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"singleQuote": true,
3+
"proseWrap": "never",
4+
"trailingComma": "es5"
5+
}

0 commit comments

Comments
 (0)