Skip to content

Commit f1fc1d3

Browse files
committed
build: add lokidb as meta package to install all packages at once
1 parent baa6311 commit f1fc1d3

File tree

14 files changed

+359
-44
lines changed

14 files changed

+359
-44
lines changed

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![npm status][npm]][npm-url]
1+
[![npm status][npm]][lokidb-npm-url]
22
[![build status][build]][build-url]
33
[![coverage status][coverage]][coverage-url]
44

@@ -12,23 +12,27 @@ LokiDB is the official successor of [LokiJS][lokijs-url].
1212

1313
## Install
1414

15-
Install with npm:
15+
Install all packages at once with:
1616

17-
```bash
18-
npm install @lokidb/loki
17+
```
18+
npm install lokidb
1919
```
2020

2121
## Documentation
2222

2323
Check out our interactive [documentation](https://LokiJS-Forge.github.io/LokiDB/).
2424

25-
## Plugins
25+
## Packages
26+
27+
|Name|Description|
28+
|:---|:----------|
29+
|[@lokidb/lokidb][loki-npm-url] | A fast and feature-rich document oriented in-memory database. |
2630

2731
### Storage and Adapter
2832

2933
|Name|Description|
3034
|:---|:----------|
31-
|[@lokidb/fs-storage][fs-storage-npm-url] | A persistence adapter which persists to node fs module storage. |
35+
|[@lokidb/fs-storage][fs-storage-npm-url] | A persistence adapter which persists to node's filesystem storage. |
3236
|[@lokidb/local-storage][local-storage-npm-url] | A persistence adapter which persists to web browser's local storage. |
3337
|[@lokidb/indexed-storage][indexed-storage-npm-url] | A persistence adapter which persists to web browser's indexed db storage. |
3438
|[@lokidb/memory-storage][memory-storage-npm-url] | A persistence adapter which persists to memory. |
@@ -48,10 +52,13 @@ Check out our interactive [documentation](https://LokiJS-Forge.github.io/LokiDB/
4852
[coverage]: https://codecov.io/gh/LokiJS-Forge/LokiDB/branch/master/graph/badge.svg
4953
[coverage-url]: https://codecov.io/gh/LokiJS-Forge/LokiDB/branch/master
5054

55+
[npm]: https://img.shields.io/npm/v/lokidb.svg
56+
[lokidb-npm-url]: https://www.npmjs.com/package/lokidb
57+
5158
[lokijs-url]: https://github.com/techfort/LokiJS
5259

53-
[npm]: https://img.shields.io/npm/v/@lokidb/loki.svg
54-
[npm-url]: https://www.npmjs.com/package/@lokidb/loki
60+
[loki]: https://github.com/LokiJS-Forge/LokiDB
61+
[loki-npm-url]: https://www.npmjs.com/package/@lokidb/loki
5562

5663
[fs-storage]: https://github.com/LokiJS-Forge/LokiDB
5764
[fs-storage-npm-url]: https://www.npmjs.com/package/@lokidb/fs-storage

dist/packages/lokidb/common.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const {spawn} = require("child_process");
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
const PACKAGES = [
6+
"fs-storage",
7+
"full-text-search",
8+
"full-text-search-language",
9+
"full-text-search-language-de",
10+
"full-text-search-language-en",
11+
"indexed-storage",
12+
"local-storage",
13+
"loki",
14+
"memory-storage",
15+
"partitioning-adapter",
16+
];
17+
18+
/// MIT © Sindre Sorhus
19+
function pathExistsSync(fp) {
20+
try {
21+
fs.accessSync(fp);
22+
return true;
23+
} catch (err) {
24+
return false;
25+
}
26+
}
27+
28+
/// MIT © Sindre Sorhus
29+
function locatePathSync(iterable, options) {
30+
options = Object.assign({
31+
cwd: process.cwd()
32+
}, options);
33+
34+
for (const el of iterable) {
35+
if (pathExistsSync(path.resolve(options.cwd, el))) {
36+
return el;
37+
}
38+
}
39+
}
40+
41+
/// MIT © Sindre Sorhus
42+
function findUpSync(filename, opts = {}) {
43+
let dir = path.resolve(opts.cwd || "");
44+
const {root} = path.parse(dir);
45+
46+
const filenames = [].concat(filename);
47+
48+
// eslint-disable-next-line no-constant-condition
49+
while (true) {
50+
const file = locatePathSync(filenames, {cwd: dir});
51+
52+
if (file) {
53+
return path.join(dir, file);
54+
}
55+
56+
if (dir === root) {
57+
return null;
58+
}
59+
60+
dir = path.dirname(dir);
61+
}
62+
}
63+
64+
function getRootDirectory() {
65+
return process.env.INIT_CWD || path.dirname(findUpSync("package.json"));
66+
}
67+
68+
function getRootPackageJSON() {
69+
return require(path.join(getRootDirectory(), "package.json"));
70+
}
71+
72+
function getPackageDependencyType(packageJson, packageName) {
73+
if (packageJson.dependencies && Object.keys(packageJson.dependencies).includes(packageName)) {
74+
return "production";
75+
} else if (packageJson.devDependencies && Object.keys(packageJson.devDependencies).includes(packageName)) {
76+
return "development";
77+
}
78+
return null;
79+
}
80+
81+
function run(command, args = []) {
82+
const child = spawn(command, args);
83+
child.stdout.on("data", (data) => {
84+
console.log(data.toString("utf8"));
85+
});
86+
child.stderr.on("data", (data) => {
87+
console.error(data.toString("utf8"));
88+
});
89+
}
90+
91+
function print(txt, lb = "\n") {
92+
process.stdout.write(txt + lb);
93+
}
94+
95+
module.exports = {
96+
PACKAGES,
97+
getRootDirectory,
98+
getRootPackageJSON,
99+
getPackageDependencyType,
100+
run,
101+
print
102+
};

dist/packages/lokidb/install.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const common = require("./common");
2+
3+
const ROOT_DIRECTORY = common.getRootDirectory();
4+
const PACKAGE_JSON = common.getRootPackageJSON();
5+
6+
let DEPENDENCY_ARGUMENT = "";
7+
const DEPENDENCY_TYPE = common.getPackageDependencyType(PACKAGE_JSON, "lokidb");
8+
if (DEPENDENCY_TYPE === "production") {
9+
DEPENDENCY_ARGUMENT = "--save-prod";
10+
} else if (DEPENDENCY_TYPE === "development") {
11+
DEPENDENCY_ARGUMENT = "--save-dev";
12+
}
13+
14+
// Bundle all packages.
15+
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);
16+
17+
common.print("Install all @lokidb packages.");
18+
19+
// Install packages.
20+
common.run("npm", ["install", "--prefix", ROOT_DIRECTORY, DEPENDENCY_ARGUMENT, ...packages]);

dist/packages/lokidb/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "lokidb",
3+
"version": "0.0.1-beta.27",
4+
"description": "Metapackage for LokiDB.",
5+
"author": "Various authors",
6+
"license": "MIT",
7+
"repository": {
8+
"type": "git",
9+
"url": "https://github.com/LokiJS-Forge/LokiDB.git"
10+
},
11+
"scripts": {
12+
"postinstall": "node install.js",
13+
"preuninstall": "node uninstall.js"
14+
}
15+
}

dist/packages/lokidb/uninstall.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const common = require("./common");
2+
3+
const ROOT_DIRECTORY = common.getRootDirectory();
4+
5+
// Bundle all packages.
6+
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);
7+
8+
common.print("Uninstall all @lokidb packages.");
9+
10+
// Uninstall packages.
11+
common.run("npm", ["uninstall", "--prefix", ROOT_DIRECTORY, ...packages]);

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"name": "@lokidb/lokidb-src",
2+
"name": "@lokidb/sources",
33
"version": "2.0.0-beta.6",
4-
"description": "Fast document oriented javascript in-memory database",
4+
"description": "Top-level scripts and dependencies for the LokiDB monorepo. Not meant to be published to npm.",
55
"author": "Various authors",
66
"license": "(MIT OR Apache-2.0)",
77
"scripts": {
@@ -26,12 +26,14 @@
2626
},
2727
"keywords": [
2828
"javascript",
29+
"typescript",
2930
"document-oriented",
3031
"mmdb",
3132
"database",
33+
"in-memory",
3234
"json",
3335
"lokidb",
34-
"in-memory"
36+
"lokijs"
3537
],
3638
"bugs": {
3739
"url": "https://github.com/LokiJS-Forge/LokiDB/issues"

packages/fs-storage/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lokidb/fs-storage",
3-
"description": "A persistence adapter which persists to node fs module storage.",
3+
"description": "A persistence adapter which persists to node's filesystem storage.",
44
"author": "Various authors",
55
"license": "MIT",
66
"repository": {

packages/loki/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lokidb/loki",
3-
"description": "Fast document oriented javascript in-memory database",
3+
"description": "A fast and feature-rich document oriented in-memory database.",
44
"author": "Various authors",
55
"license": "MIT",
66
"repository": {

packages/lokidb/common.js

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
const {spawn} = require("child_process");
2+
const fs = require("fs");
3+
const path = require("path");
4+
5+
const PACKAGES = [
6+
"fs-storage",
7+
"full-text-search",
8+
"full-text-search-language",
9+
"full-text-search-language-de",
10+
"full-text-search-language-en",
11+
"indexed-storage",
12+
"local-storage",
13+
"loki",
14+
"memory-storage",
15+
"partitioning-adapter",
16+
];
17+
18+
/// MIT © Sindre Sorhus
19+
function pathExistsSync(fp) {
20+
try {
21+
fs.accessSync(fp);
22+
return true;
23+
} catch (err) {
24+
return false;
25+
}
26+
}
27+
28+
/// MIT © Sindre Sorhus
29+
function locatePathSync(iterable, options) {
30+
options = Object.assign({
31+
cwd: process.cwd()
32+
}, options);
33+
34+
for (const el of iterable) {
35+
if (pathExistsSync(path.resolve(options.cwd, el))) {
36+
return el;
37+
}
38+
}
39+
}
40+
41+
/// MIT © Sindre Sorhus
42+
function findUpSync(filename, opts = {}) {
43+
let dir = path.resolve(opts.cwd || "");
44+
const {root} = path.parse(dir);
45+
46+
const filenames = [].concat(filename);
47+
48+
// eslint-disable-next-line no-constant-condition
49+
while (true) {
50+
const file = locatePathSync(filenames, {cwd: dir});
51+
52+
if (file) {
53+
return path.join(dir, file);
54+
}
55+
56+
if (dir === root) {
57+
return null;
58+
}
59+
60+
dir = path.dirname(dir);
61+
}
62+
}
63+
64+
function getRootDirectory() {
65+
return process.env.INIT_CWD || path.dirname(findUpSync("package.json"));
66+
}
67+
68+
function getRootPackageJSON() {
69+
return require(path.join(getRootDirectory(), "package.json"));
70+
}
71+
72+
function getPackageDependencyType(packageJson, packageName) {
73+
if (packageJson.dependencies && Object.keys(packageJson.dependencies).includes(packageName)) {
74+
return "production";
75+
} else if (packageJson.devDependencies && Object.keys(packageJson.devDependencies).includes(packageName)) {
76+
return "development";
77+
}
78+
return null;
79+
}
80+
81+
function run(command, args = []) {
82+
const child = spawn(command, args);
83+
child.stdout.on("data", (data) => {
84+
console.log(data.toString("utf8"));
85+
});
86+
child.stderr.on("data", (data) => {
87+
console.error(data.toString("utf8"));
88+
});
89+
}
90+
91+
function print(txt, lb = "\n") {
92+
process.stdout.write(txt + lb);
93+
}
94+
95+
module.exports = {
96+
PACKAGES,
97+
getRootDirectory,
98+
getRootPackageJSON,
99+
getPackageDependencyType,
100+
run,
101+
print
102+
};

packages/lokidb/install.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const common = require("./common");
2+
3+
const ROOT_DIRECTORY = common.getRootDirectory();
4+
const PACKAGE_JSON = common.getRootPackageJSON();
5+
6+
let DEPENDENCY_ARGUMENT = "";
7+
const DEPENDENCY_TYPE = common.getPackageDependencyType(PACKAGE_JSON, "lokidb");
8+
if (DEPENDENCY_TYPE === "production") {
9+
DEPENDENCY_ARGUMENT = "--save-prod";
10+
} else if (DEPENDENCY_TYPE === "development") {
11+
DEPENDENCY_ARGUMENT = "--save-dev";
12+
}
13+
14+
// Bundle all packages.
15+
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);
16+
17+
common.print("Install all @lokidb packages...");
18+
19+
// Install packages.
20+
common.run("npm", ["install", "--prefix", ROOT_DIRECTORY, DEPENDENCY_ARGUMENT, ...packages]);

0 commit comments

Comments
 (0)