Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
feather
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
feather
Commits
179b482c
Commit
179b482c
authored
May 18, 2018
by
Cole Bemis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
build: Use promises in algolia script
parent
a23698d5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
14 deletions
+44
-14
sync-algolia.js
bin/sync-algolia.js
+44
-14
No files found.
bin/sync-algolia.js
View file @
179b482c
...
...
@@ -21,23 +21,53 @@ function syncAlgolia() {
const
index
=
client
.
initIndex
(
'
icons
'
);
const
indexTmp
=
client
.
initIndex
(
'
icons_tmp
'
);
indexTmp
.
setSettings
({
searchableAttributes
:
[
'
unordered(name)
'
,
'
unordered(tags)
'
],
customRanking
:
[
'
asc(name)
'
],
});
console
.
log
(
"
Copying target index's settings, synonyms and rules into temporary index...
"
,
);
scopedCopyIndex
(
client
,
index
.
indexName
,
indexTmp
.
indexName
)
.
then
(()
=>
{
const
objects
=
Object
.
keys
(
icons
).
map
(
name
=>
({
name
,
tags
:
tags
[
name
]
||
[],
}));
const
records
=
Object
.
keys
(
icons
).
map
(
name
=>
({
name
,
tags
:
tags
[
name
]
||
[],
}));
console
.
log
(
'
Adding objects to the temporary index...
'
);
return
addObjects
(
indexTmp
,
objects
);
})
.
then
(()
=>
{
console
.
log
(
'
Moving temporary index to target index...
'
);
return
moveIndex
(
client
,
indexTmp
.
indexName
,
index
.
indexName
);
});
}
console
.
log
(
'
Pushing data to the temporary index...
'
);
indexTmp
.
addObjects
(
records
,
err
=>
{
if
(
err
)
throw
err
;
function
scopedCopyIndex
(
client
,
indexNameSrc
,
indexNameDest
,
scope
=
[
'
settings
'
,
'
synonyms
'
,
'
rules
'
],
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
client
.
copyIndex
(
indexNameSrc
,
indexNameDest
,
scope
,
(
error
,
contents
)
=>
{
if
(
error
)
reject
(
error
);
resolve
(
contents
);
});
});
}
function
addObjects
(
index
,
objects
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
index
.
addObjects
(
objects
,
(
error
,
contents
)
=>
{
if
(
error
)
reject
(
error
);
resolve
(
contents
);
});
});
}
console
.
log
(
'
Moving temporary index to target index...
'
);
client
.
moveIndex
(
indexTmp
.
indexName
,
index
.
indexName
,
err
=>
{
if
(
err
)
throw
err
;
function
moveIndex
(
client
,
indexNameSrc
,
indexNameDest
)
{
return
new
Promise
((
resolve
,
reject
)
=>
{
client
.
moveIndex
(
indexNameSrc
,
indexNameDest
,
(
error
,
contents
)
=>
{
if
(
error
)
reject
(
error
);
resolve
(
contents
);
});
});
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment