Skip to content

Commit efc1d57

Browse files
Jared KobosGitHub Enterprise
authored andcommitted
Merge pull request linode#266 from jkobos/build-scripts
Build scripts
2 parents 69284e4 + 2a7890b commit efc1d57

File tree

8 files changed

+211
-17383
lines changed

8 files changed

+211
-17383
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,6 @@ yarn-error.log
6969
.yarn-integrity
7070

7171
# Linode base theme
72-
linode-hugo-theme
72+
linode-hugo-theme
73+
74+
themes/

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ The developers.linode.com website built with Gatsby and including the API Docs
88

99
`yarn develop`
1010

11-
you may need to install the gastby CLI as well `npm install -g gatsby-cli`
11+
you may need to install the Gatsby CLI as well `npm install -g gatsby-cli`
1212

1313
Check out the site at http://localhost:8000/
14+
15+
### Build
16+
17+
The API documentation in this site is also indexed in Algolia, so that
18+
it can be searched across Linode's services. The scripts for this are
19+
located in the `/search` directory. In order to run them correctly,
20+
you will need to create a `.env` file in the root directory with the
21+
following values:
22+
23+
ALGOLIA_API_KEY=(your key here)
24+
ALGOLIA_API_SECRET=(your secret here)

index.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

package-lock.json

Lines changed: 0 additions & 17377 deletions
This file was deleted.

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
],
4242
"license": "MIT",
4343
"scripts": {
44-
"build": "./getBaseTheme.sh && gatsby build",
44+
"build": "./getBaseTheme.sh && gatsby build && node search/buildIndex.js",
4545
"develop": "./getBaseTheme.sh && gatsby develop",
4646
"start": "npm run develop",
4747
"serve": "gatsby serve",
@@ -53,5 +53,12 @@
5353
},
5454
"bugs": {
5555
"url": "https://github.com/gatsbyjs/gatsby/issues"
56+
},
57+
"devDependencies": {
58+
"algoliasearch": "^3.33.0",
59+
"dotenv": "^8.0.0",
60+
"lodash": "^4.17.11",
61+
"md5": "^2.2.1",
62+
"randomstring": "^1.1.5"
5663
}
5764
}

search/buildAlgolia.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
algoliasearch = require('algoliasearch'),
2+
randomstring = require('randomstring');
3+
4+
const updateAlgolia = (records) => {
5+
if (!process.env.ALGOLIA_API_KEY || !process.env.ALGOLIA_API_SECRET) {
6+
throw new Error('Algolia credentials not found. Please add them to your .env file.')
7+
}
8+
9+
console.log("Updating Algolia with API key: " + process.env.ALGOLIA_API_KEY);
10+
11+
const client = algoliasearch(process.env.ALGOLIA_API_KEY, process.env.ALGOLIA_API_SECRET);
12+
const index = client.initIndex('linode-api-spec');
13+
const indexName = 'linode-api-spec-tmp-'+randomstring.generate(5);
14+
console.log('Creating temporary index with name: ' + indexName);
15+
const tmp = client.initIndex(indexName);
16+
17+
// Copy settings to temporary index
18+
console.log('Copying settings from existing index to temporary index');
19+
client.copyIndex('linode-api-spec', indexName, ['settings', 'synonyms', 'rules'], (err, content) => {
20+
if (err) throw err;
21+
22+
// Browse the current index (as in the example docs, seems necessary
23+
// to activate the index since initIndex doesn't actually init the index)
24+
const oldRecords = [];
25+
index.browseAll((item) => {
26+
oldRecords.push(item);
27+
});
28+
29+
console.log('Found ' + String(records.length) + ' records.');
30+
console.log('Adding records to temporary index.');
31+
32+
tmp.addObjects(records, (err,content) => {
33+
if (err) { throw err;}
34+
35+
// Move temporary index to linode-api-spec (overwrites existing index)
36+
console.log('Moving temporary index to linode-api-spec.');
37+
client.moveIndex(indexName, 'linode-api-spec', (err, content) => {
38+
if (err) throw err;
39+
console.log('Index successfully updated.');
40+
});
41+
});
42+
});
43+
}
44+
45+
module.exports = updateAlgolia;

search/buildIndex.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
const fs = require('fs');
2+
const _ = require('lodash');
3+
const md5 = require('md5');
4+
const buildAlgolia = require('./buildAlgolia');
5+
require('dotenv').config();
6+
7+
// This assumes the version of the spec in data/ is the current version
8+
const spec = require('../src/data/spec.json');
9+
10+
const BASE_URL = 'https://developers.linode.com/api/v4/';
11+
12+
13+
const buildIndex = () => {
14+
const index = [];
15+
for (const [key, value] of Object.entries(spec.paths)) {
16+
const methodNames = Object.keys(value);
17+
18+
methodNames.forEach(methodName => {
19+
const entry = {}
20+
if (['get', 'put', 'post', 'delete'].includes(methodName)) {
21+
const thisMethod = value[methodName];
22+
entry.name = thisMethod.summary;
23+
entry.tags = thisMethod.tags;
24+
entry.description = thisMethod.description.trim();
25+
entry.href = getUrl(key);
26+
entry.objectID = md5(key);
27+
index.push(entry);
28+
}
29+
});
30+
};
31+
return index;
32+
}
33+
34+
const getUrl = (endpoint) => {
35+
const url = _.kebabCase(endpoint);
36+
return BASE_URL + url;
37+
}
38+
39+
// Generate an array of objects representing index entries
40+
const index = buildIndex();
41+
42+
// Replace the current Algolia index (linode-api-spec) with the current one
43+
buildAlgolia(index);
44+
45+
// Save a copy of the index to file for reference.
46+
fs.writeFile('index.json', JSON.stringify(index), (err) => {
47+
if (err) {
48+
console.error(err);
49+
}
50+
});

yarn.lock

Lines changed: 92 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,11 @@ [email protected]:
974974
version "0.8.2"
975975
resolved "https://registry.yarnpkg.com/after/-/after-0.8.2.tgz#fedb394f9f0e02aa9768e702bda23b505fae7e1f"
976976

977+
agentkeepalive@^2.2.0:
978+
version "2.2.0"
979+
resolved "https://registry.yarnpkg.com/agentkeepalive/-/agentkeepalive-2.2.0.tgz#c5d1bd4b129008f1163f236f86e5faea2026e2ef"
980+
integrity sha1-xdG9SxKQCPEWPyNvhuX66iAm4u8=
981+
977982
ajv-errors@^1.0.0:
978983
version "1.0.1"
979984
resolved "https://registry.yarnpkg.com/ajv-errors/-/ajv-errors-1.0.1.tgz#f35986aceb91afadec4102fbd85014950cefa64d"
@@ -1000,6 +1005,27 @@ ajv@^6.5.5:
10001005
json-schema-traverse "^0.4.1"
10011006
uri-js "^4.2.2"
10021007

1008+
algoliasearch@^3.33.0:
1009+
version "3.33.0"
1010+
resolved "https://registry.yarnpkg.com/algoliasearch/-/algoliasearch-3.33.0.tgz#83b541124ebb0db54643009d4e660866b3177cdf"
1011+
integrity sha512-9DaVmOd7cvcZeYyV0BWAeJHVWJmgOL2DNUEBY/DTR4MzD1wCWs4Djl7LAlfvkGwGBdRHZCG+l0HA1572w3T8zg==
1012+
dependencies:
1013+
agentkeepalive "^2.2.0"
1014+
debug "^2.6.9"
1015+
envify "^4.0.0"
1016+
es6-promise "^4.1.0"
1017+
events "^1.1.0"
1018+
foreach "^2.0.5"
1019+
global "^4.3.2"
1020+
inherits "^2.0.1"
1021+
isarray "^2.0.1"
1022+
load-script "^1.0.0"
1023+
object-keys "^1.0.11"
1024+
querystring-es3 "^0.2.1"
1025+
reduce "^1.0.1"
1026+
semver "^5.1.0"
1027+
tunnel-agent "^0.6.0"
1028+
10031029
alphanum-sort@^1.0.0:
10041030
version "1.0.2"
10051031
resolved "https://registry.yarnpkg.com/alphanum-sort/-/alphanum-sort-1.0.2.tgz#97a1119649b211ad33691d9f9f486a8ec9fbe0a3"
@@ -1168,6 +1194,11 @@ array-union@^1.0.1:
11681194
dependencies:
11691195
array-uniq "^1.0.1"
11701196

1197+
1198+
version "1.0.2"
1199+
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.2.tgz#5fcc373920775723cfd64d65c64bef53bf9eba6d"
1200+
integrity sha1-X8w3OSB3VyPP1k1lxkvvU7+eum0=
1201+
11711202
array-uniq@^1.0.1, array-uniq@^1.0.2:
11721203
version "1.0.3"
11731204
resolved "https://registry.yarnpkg.com/array-uniq/-/array-uniq-1.0.3.tgz#af6ac877a25cc7f74e058894753858dfdb24fdb6"
@@ -3185,6 +3216,11 @@ dotenv@^4.0.0:
31853216
version "4.0.0"
31863217
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-4.0.0.tgz#864ef1379aced55ce6f95debecdce179f7a0cd1d"
31873218

3219+
dotenv@^8.0.0:
3220+
version "8.0.0"
3221+
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-8.0.0.tgz#ed310c165b4e8a97bb745b0a9d99c31bda566440"
3222+
integrity sha512-30xVGqjLjiUOArT4+M5q9sYdvuR4riM6yK9wMcas9Vbp6zZa+ocC9dp6QoftuhTPhFAiLK/0C5Ni2nou/Bk8lg==
3223+
31883224
download@^6.2.2:
31893225
version "6.2.5"
31903226
resolved "https://registry.yarnpkg.com/download/-/download-6.2.5.tgz#acd6a542e4cd0bb42ca70cfc98c9e43b07039714"
@@ -3352,6 +3388,14 @@ entities@^1.1.1, entities@~1.1.1:
33523388
version "1.1.2"
33533389
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56"
33543390

3391+
envify@^4.0.0:
3392+
version "4.1.0"
3393+
resolved "https://registry.yarnpkg.com/envify/-/envify-4.1.0.tgz#f39ad3db9d6801b4e6b478b61028d3f0b6819f7e"
3394+
integrity sha512-IKRVVoAYr4pIx4yIWNsz9mOsboxlNXiu7TNBnem/K/uTHdkyzXWDzHCK7UTolqBbgaBz0tQHsD3YNls0uIIjiw==
3395+
dependencies:
3396+
esprima "^4.0.0"
3397+
through "~2.3.4"
3398+
33553399
envinfo@^5.8.1:
33563400
version "5.12.1"
33573401
resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-5.12.1.tgz#83068c33e0972eb657d6bc69a6df30badefb46ef"
@@ -3401,6 +3445,11 @@ es6-promise@^3.0.2:
34013445
version "3.3.1"
34023446
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-3.3.1.tgz#a08cdde84ccdbf34d027a1451bc91d4bcd28a613"
34033447

3448+
es6-promise@^4.1.0:
3449+
version "4.2.6"
3450+
resolved "https://registry.yarnpkg.com/es6-promise/-/es6-promise-4.2.6.tgz#b685edd8258886365ea62b57d30de28fadcd974f"
3451+
integrity sha512-aRVgGdnmW2OiySVPUC9e6m+plolMAJKjZnQlCwNSuK5yQ0JN61DZSO1X1Ufd1foqWRAlig0rhduTCHe7sVtK5Q==
3452+
34043453
es6-promisify@^6.0.0:
34053454
version "6.0.1"
34063455
resolved "https://registry.yarnpkg.com/es6-promisify/-/es6-promisify-6.0.1.tgz#6edaa45f3bd570ffe08febce66f7116be4b1cdb6"
@@ -3603,6 +3652,11 @@ eventemitter3@^3.0.0:
36033652
version "3.1.0"
36043653
resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-3.1.0.tgz#090b4d6cdbd645ed10bf750d4b5407942d7ba163"
36053654

3655+
events@^1.1.0:
3656+
version "1.1.1"
3657+
resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924"
3658+
integrity sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=
3659+
36063660
events@^3.0.0:
36073661
version "3.0.0"
36083662
resolved "https://registry.yarnpkg.com/events/-/events-3.0.0.tgz#9a0a0dfaf62893d92b875b8f2698ca4114973e88"
@@ -4144,6 +4198,11 @@ for-own@^0.1.4:
41444198
dependencies:
41454199
for-in "^1.0.1"
41464200

4201+
foreach@^2.0.5:
4202+
version "2.0.5"
4203+
resolved "https://registry.yarnpkg.com/foreach/-/foreach-2.0.5.tgz#0bee005018aeb260d0a3af3ae658dd0136ec1b99"
4204+
integrity sha1-C+4AUBiusmDQo6865ljdATbsG5k=
4205+
41474206
forever-agent@~0.6.1:
41484207
version "0.6.1"
41494208
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
@@ -4727,7 +4786,7 @@ global-prefix@^1.0.1:
47274786
is-windows "^1.0.1"
47284787
which "^1.2.14"
47294788

4730-
global@^4.3.0, global@~4.3.0:
4789+
global@^4.3.0, global@^4.3.2, global@~4.3.0:
47314790
version "4.3.2"
47324791
resolved "https://registry.yarnpkg.com/global/-/global-4.3.2.tgz#e76989268a6c74c38908b1305b10fc0e394e9d0f"
47334792
dependencies:
@@ -5915,6 +5974,11 @@ [email protected]:
59155974
version "2.0.1"
59165975
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.1.tgz#a37d94ed9cda2d59865c9f76fe596ee1f338741e"
59175976

5977+
isarray@^2.0.1:
5978+
version "2.0.4"
5979+
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.4.tgz#38e7bcbb0f3ba1b7933c86ba1894ddfc3781bbb7"
5980+
integrity sha512-GMxXOiUirWg1xTKRipM0Ek07rX+ubx4nNVElTJdNLYmNO/2YrDkgJGw9CljXn+r4EWiDQg/8lsRdHyg2PJuUaA==
5981+
59185982
59195983
version "3.2.0"
59205984
resolved "https://registry.yarnpkg.com/isemail/-/isemail-3.2.0.tgz#59310a021931a9fb06bbb51e155ce0b3f236832c"
@@ -6262,6 +6326,11 @@ load-json-file@^2.0.0:
62626326
pify "^2.0.0"
62636327
strip-bom "^3.0.0"
62646328

6329+
load-script@^1.0.0:
6330+
version "1.0.0"
6331+
resolved "https://registry.yarnpkg.com/load-script/-/load-script-1.0.0.tgz#0491939e0bee5643ee494a7e3da3d2bac70c6ca4"
6332+
integrity sha1-BJGTngvuVkPuSUp+PaPSuscMbKQ=
6333+
62656334
loader-fs-cache@^1.0.0:
62666335
version "1.0.1"
62676336
resolved "https://registry.yarnpkg.com/loader-fs-cache/-/loader-fs-cache-1.0.1.tgz#56e0bf08bd9708b26a765b68509840c8dec9fdbc"
@@ -6555,6 +6624,7 @@ md5.js@^1.3.4:
65556624
md5@^2.2.1:
65566625
version "2.2.1"
65576626
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
6627+
integrity sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=
65586628
dependencies:
65596629
charenc "~0.0.1"
65606630
crypt "~0.0.1"
@@ -7189,6 +7259,11 @@ object-hash@^1.1.4:
71897259
version "1.3.1"
71907260
resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df"
71917261

7262+
object-keys@^1.0.11, object-keys@^1.1.0:
7263+
version "1.1.1"
7264+
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.1.1.tgz#1c47f272df277f3b1daf061677d9c82e2322c60e"
7265+
integrity sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==
7266+
71927267
object-keys@^1.0.12:
71937268
version "1.0.12"
71947269
resolved "https://registry.yarnpkg.com/object-keys/-/object-keys-1.0.12.tgz#09c53855377575310cca62f55bb334abff7b3ed2"
@@ -8419,7 +8494,7 @@ query-string@^5.0.1:
84198494
object-assign "^4.1.0"
84208495
strict-uri-encode "^1.0.0"
84218496

8422-
querystring-es3@^0.2.0:
8497+
querystring-es3@^0.2.0, querystring-es3@^0.2.1:
84238498
version "0.2.1"
84248499
resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73"
84258500

@@ -8468,6 +8543,13 @@ randomfill@^1.0.3:
84688543
randombytes "^2.0.5"
84698544
safe-buffer "^5.1.0"
84708545

8546+
randomstring@^1.1.5:
8547+
version "1.1.5"
8548+
resolved "https://registry.yarnpkg.com/randomstring/-/randomstring-1.1.5.tgz#6df0628f75cbd5932930d9fe3ab4e956a18518c3"
8549+
integrity sha1-bfBij3XL1ZMpMNn+OrTpVqGFGMM=
8550+
dependencies:
8551+
array-uniq "1.0.2"
8552+
84718553
range-parser@^1.0.3, range-parser@~1.2.0:
84728554
version "1.2.0"
84738555
resolved "https://registry.yarnpkg.com/range-parser/-/range-parser-1.2.0.tgz#f49be6b487894ddc40dcc94a322f611092e00d5e"
@@ -8760,6 +8842,13 @@ redent@^1.0.0:
87608842
indent-string "^2.1.0"
87618843
strip-indent "^1.0.1"
87628844

8845+
reduce@^1.0.1:
8846+
version "1.0.2"
8847+
resolved "https://registry.yarnpkg.com/reduce/-/reduce-1.0.2.tgz#0cd680ad3ffe0b060e57a5c68bdfce37168d361b"
8848+
integrity sha512-xX7Fxke/oHO5IfZSk77lvPa/7bjMh9BuCk4OOoX5XTXrM7s0Z+MkPfSDfz0q7r91BhhGSs8gii/VEN/7zhCPpQ==
8849+
dependencies:
8850+
object-keys "^1.1.0"
8851+
87638852
redux@^4.0.0:
87648853
version "4.0.1"
87658854
resolved "https://registry.yarnpkg.com/redux/-/redux-4.0.1.tgz#436cae6cc40fbe4727689d7c8fae44808f1bfef5"
@@ -10123,7 +10212,7 @@ through2@^2.0.0, through2@^2.0.1:
1012310212
readable-stream "~2.3.6"
1012410213
xtend "~4.0.1"
1012510214

10126-
through@^2.3.6:
10215+
through@^2.3.6, through@~2.3.4:
1012710216
version "2.3.8"
1012810217
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
1012910218

0 commit comments

Comments
 (0)