algolia-uploader 0.0.13 → 0.0.15-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.mjs +2 -0
- package/package.json +22 -25
package/README.md
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
This is a command-line util to upload Algolia sources. This idea comes from [atomic-algolia](https://github.com/chrisdmacrae/atomic-algolia).
|
|
4
4
|
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> This package is currently supported as a CLI-only tool. Programmatic import as a library API is out of scope.
|
|
7
|
+
|
|
5
8
|
## Install
|
|
6
9
|
|
|
7
10
|
```
|
|
@@ -109,6 +112,12 @@ or
|
|
|
109
112
|
|
|
110
113
|
A `devcontainer` is included.
|
|
111
114
|
|
|
115
|
+
> [!IMPORTANT]
|
|
116
|
+
> Build tooling uses `tsdown`, which requires Node.js 22.22.1 or higher to run the build.
|
|
117
|
+
> Runtime support is Node.js 22.22.1 or higher.
|
|
118
|
+
|
|
119
|
+
### Toolchain setup
|
|
120
|
+
|
|
112
121
|
In this repository, `.env` and `.env.ci` are encrypted with [dotenvx](https://dotenvx.com/docs/quickstart).
|
|
113
122
|
|
|
114
123
|
- `.env` is for debugging and testing in your local environment
|
|
@@ -131,6 +140,12 @@ The tests attempt to read the local `.env` file, but the actual variables used i
|
|
|
131
140
|
|
|
132
141
|
Therefore, the tests do not access your real Algolia application.
|
|
133
142
|
|
|
143
|
+
### How to lint and format
|
|
144
|
+
|
|
145
|
+
Run `npm run lint`.
|
|
146
|
+
|
|
147
|
+
This repository uses Biome for linting and formatting.
|
|
148
|
+
|
|
134
149
|
### GitHub Actions
|
|
135
150
|
|
|
136
151
|
Testing with GitHub Actions uses `.env.ci`.
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import e from"node:fs";import t from"node:path";import{defineCommand as n,runMain as r}from"citty";import{algoliasearch as i}from"algoliasearch";import{isEqual as a}from"es-toolkit";var o=`algolia-uploader`,s=`0.0.15-beta.1`,c=`command-line util to upload Algolia source`;function l(e){return typeof e==`object`&&!!e&&`objectID`in e&&typeof e.objectID==`string`}function u(e){let t=Object.keys(e).sort(),n={objectID:e.objectID};for(let r of t)r!==`objectID`&&(n[r]=e[r]);return n}function d(e){return e.map(u).sort((e,t)=>e.objectID.localeCompare(t.objectID))}const f={ALGOLIA_APP_ID:`ALGOLIA_APP_ID`,ALGOLIA_ADMIN_API_KEY:`ALGOLIA_ADMIN_API_KEY`,ALGOLIA_INDEX_NAME:`ALGOLIA_INDEX_NAME`,DATA_DIR:`DATA_DIR`};var p=class e{constructor(){this.envVars={},Object.values(f).forEach(e=>{let t=process.env[e];if(t==null)throw Error(`Missing required environment variable: ${e}`);this.envVars[e]=t})}static getInstance(){return e.instance||=new e,e.instance}getConfig(e){return this.envVars[e]}},m=class e{constructor(e,t){this.client=t(e.getConfig(`ALGOLIA_APP_ID`),e.getConfig(`ALGOLIA_ADMIN_API_KEY`)),this.indexName=e.getConfig(`ALGOLIA_INDEX_NAME`)}static getInstance(){if(!this.instance){let t=p.getInstance();this.instance=new e(t,i)}return this.instance}getClient(){return this.client}getIndexName(){return this.indexName}};function h(n){return e.readdirSync(n).filter(e=>e.endsWith(`.json`)).map(r=>{let i=e.readFileSync(t.join(n,r),`utf8`);return JSON.parse(i)})}var g=class{constructor(e){this.client=e.getClient(),this.indexName=e.getIndexName()}async uploadObjects(e){if(e.length===0){console.error(`No items are included in the target JSON file. More than 1 item is necessary.`);return}let t=await this.getAllObjects();t=d(t);let n=d(e),r=this.determineOperations(t,n);if(r.update.length===0&&r.add.length===0&&r.delete.length===0){console.log(`No updates needed. All objects are up to date.`);return}if(r.update.length>0){let e=await this.client.partialUpdateObjects({indexName:this.indexName,objects:r.update,createIfNotExists:!0});console.log(`Updated ${e[0].objectIDs.length} objects`)}if(r.add.length>0){let e=await this.client.saveObjects({indexName:this.indexName,objects:r.add});console.log(`Added ${e[0].objectIDs.length} objects`)}if(r.delete.length>0){let e=r.delete.map(e=>e.objectID),t=await this.client.deleteObjects({indexName:this.indexName,objectIDs:e});console.log(`Deleted ${t[0].objectIDs.length} objects`)}}async getAllObjects(){let e=[];return await this.client.browseObjects({indexName:this.indexName,aggregator:t=>{Array.isArray(t.hits)&&t.hits.forEach(t=>{l(t)&&e.push(t)})}}),e}determineOperations(e,t){let n=new Map(e.map(e=>[e.objectID,e])),r=new Map(t.map(e=>[e.objectID,e])),i={update:[],add:[],delete:[]};for(let e of t){let t=n.get(e.objectID);t==null?i.add.push(e):a(t,e)||i.update.push(e)}for(let t of e)r.has(t.objectID)||i.delete.push(t);return i}};r(n({meta:{name:o,version:s,description:c},args:{},async run(){try{let n=p.getInstance().getConfig(`DATA_DIR`);n=t.join(process.cwd(),n),e.existsSync(n)&&e.statSync(n).isDirectory()||(console.error(`Error: provided directory does not exist - ${n}`),process.exit(1));let r=h(n);r.length===0&&(console.error(`Error: no .json files found in directory - ${n}`),process.exit(1));let i=r[0];Array.isArray(i)||(console.error(`The content of the provided json file is incompatible. Check the file: ${n}`),process.exit(1)),i.every(e=>l(e))||(console.error(`The content of the provided json file is incompatible. Check the file: ${n}`),process.exit(1)),await new g(m.getInstance()).uploadObjects(i)}catch(e){console.error(`Some errors occured: `,e),process.exit(1)}}}));export{};
|
package/package.json
CHANGED
|
@@ -1,46 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "algolia-uploader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.15-beta.1",
|
|
4
4
|
"description": "command-line util to upload Algolia source",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/htnabe/algolia-uploader.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"exports": {
|
|
11
|
-
".": {
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"main": "./dist/index.cjs",
|
|
17
|
-
"types": "./dist/index.d.ts",
|
|
18
10
|
"bin": "./dist/index.mjs",
|
|
19
11
|
"files": [
|
|
20
12
|
"dist"
|
|
21
13
|
],
|
|
14
|
+
"engines": {
|
|
15
|
+
"node": ">=22.22.1"
|
|
16
|
+
},
|
|
22
17
|
"dependencies": {
|
|
23
|
-
"algoliasearch": "^5.
|
|
18
|
+
"algoliasearch": "^5.52.1",
|
|
24
19
|
"citty": "^0.2.2",
|
|
25
|
-
"es-toolkit": "^1.
|
|
20
|
+
"es-toolkit": "^1.46.1"
|
|
26
21
|
},
|
|
27
22
|
"devDependencies": {
|
|
28
|
-
"@
|
|
29
|
-
"@
|
|
23
|
+
"@biomejs/biome": "^2.4.15",
|
|
24
|
+
"@dotenvx/dotenvx": "^1.66.0",
|
|
25
|
+
"@types/node": "^25.9.1",
|
|
30
26
|
"husky": "^9.1.7",
|
|
31
|
-
"jiti": "^2.
|
|
32
|
-
"lint-staged": "^
|
|
33
|
-
"npm-check-updates": "^
|
|
34
|
-
"
|
|
35
|
-
"typescript": "^
|
|
36
|
-
"
|
|
37
|
-
"vitest": "^4.1.
|
|
27
|
+
"jiti": "^2.7.0",
|
|
28
|
+
"lint-staged": "^17.0.5",
|
|
29
|
+
"npm-check-updates": "^22.2.0",
|
|
30
|
+
"tsdown": "^0.22.0",
|
|
31
|
+
"typescript": "^6.0.3",
|
|
32
|
+
"unrun": "^0.3.0",
|
|
33
|
+
"vitest": "^4.1.6"
|
|
38
34
|
},
|
|
39
35
|
"scripts": {
|
|
40
|
-
"build": "
|
|
41
|
-
"prepack": "
|
|
36
|
+
"build": "tsdown",
|
|
37
|
+
"prepack": "tsdown",
|
|
42
38
|
"prepare": "node .husky/install.mjs",
|
|
43
|
-
"lint": "
|
|
39
|
+
"lint": "biome check --write .",
|
|
40
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
44
41
|
"test": "vitest run",
|
|
45
42
|
"dev": "dotenvx run jiti ./src/index.ts",
|
|
46
43
|
"update": "ncu --upgrade && npm install"
|
|
@@ -52,10 +49,10 @@
|
|
|
52
49
|
"license": "ISC",
|
|
53
50
|
"lint-staged": {
|
|
54
51
|
"*.{js,ts}": [
|
|
55
|
-
"
|
|
52
|
+
"biome check --write"
|
|
56
53
|
],
|
|
57
54
|
"*.{json,md}": [
|
|
58
|
-
"
|
|
55
|
+
"biome check --write ."
|
|
59
56
|
]
|
|
60
57
|
}
|
|
61
58
|
}
|