Skip to content

Commit

Permalink
build: add lokidb as meta package to install all packages at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Viatorus committed Jun 20, 2018
1 parent eb32e76 commit c021187
Show file tree
Hide file tree
Showing 14 changed files with 359 additions and 44 deletions.
23 changes: 15 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![npm status][npm]][npm-url]
[![npm status][npm]][lokidb-npm-url]
[![build status][build]][build-url]
[![coverage status][coverage]][coverage-url]

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

## Install

Install with npm:
Install all packages at once with:

```bash
npm install @lokidb/loki
```
npm install lokidb
```

## Documentation

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

## Plugins
## Packages

|Name|Description|
|:---|:----------|
|[@lokidb/lokidb][loki-npm-url] | A fast and feature-rich document oriented in-memory database. |

### Storage and Adapter

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

[npm]: https://img.shields.io/npm/v/lokidb.svg
[lokidb-npm-url]: https://www.npmjs.com/package/lokidb

[lokijs-url]: https://github.com/techfort/LokiJS

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

[fs-storage]: https://github.com/LokiJS-Forge/LokiDB
[fs-storage-npm-url]: https://www.npmjs.com/package/@lokidb/fs-storage
Expand Down
102 changes: 102 additions & 0 deletions dist/packages/lokidb/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const {spawn} = require("child_process");
const fs = require("fs");
const path = require("path");

const PACKAGES = [
"fs-storage",
"full-text-search",
"full-text-search-language",
"full-text-search-language-de",
"full-text-search-language-en",
"indexed-storage",
"local-storage",
"loki",
"memory-storage",
"partitioning-adapter",
];

/// MIT © Sindre Sorhus
function pathExistsSync(fp) {
try {
fs.accessSync(fp);
return true;
} catch (err) {
return false;
}
}

/// MIT © Sindre Sorhus
function locatePathSync(iterable, options) {
options = Object.assign({
cwd: process.cwd()
}, options);

for (const el of iterable) {
if (pathExistsSync(path.resolve(options.cwd, el))) {
return el;
}
}
}

/// MIT © Sindre Sorhus
function findUpSync(filename, opts = {}) {
let dir = path.resolve(opts.cwd || "");
const {root} = path.parse(dir);

const filenames = [].concat(filename);

// eslint-disable-next-line no-constant-condition
while (true) {
const file = locatePathSync(filenames, {cwd: dir});

if (file) {
return path.join(dir, file);
}

if (dir === root) {
return null;
}

dir = path.dirname(dir);
}
}

function getRootDirectory() {
return process.env.INIT_CWD || path.dirname(findUpSync("package.json"));
}

function getRootPackageJSON() {
return require(path.join(getRootDirectory(), "package.json"));
}

function getPackageDependencyType(packageJson, packageName) {
if (packageJson.dependencies && Object.keys(packageJson.dependencies).includes(packageName)) {
return "production";
} else if (packageJson.devDependencies && Object.keys(packageJson.devDependencies).includes(packageName)) {
return "development";
}
return null;
}

function run(command, args = []) {
const child = spawn(command, args);
child.stdout.on("data", (data) => {
console.log(data.toString("utf8"));
});
child.stderr.on("data", (data) => {
console.error(data.toString("utf8"));
});
}

function print(txt, lb = "\n") {
process.stdout.write(txt + lb);
}

module.exports = {
PACKAGES,
getRootDirectory,
getRootPackageJSON,
getPackageDependencyType,
run,
print
};
20 changes: 20 additions & 0 deletions dist/packages/lokidb/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const common = require("./common");

const ROOT_DIRECTORY = common.getRootDirectory();
const PACKAGE_JSON = common.getRootPackageJSON();

let DEPENDENCY_ARGUMENT = "";
const DEPENDENCY_TYPE = common.getPackageDependencyType(PACKAGE_JSON, "lokidb");
if (DEPENDENCY_TYPE === "production") {
DEPENDENCY_ARGUMENT = "--save-prod";
} else if (DEPENDENCY_TYPE === "development") {
DEPENDENCY_ARGUMENT = "--save-dev";
}

// Bundle all packages.
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);

common.print("Install all @lokidb packages.");

// Install packages.
common.run("npm", ["install", "--prefix", ROOT_DIRECTORY, DEPENDENCY_ARGUMENT, ...packages]);
15 changes: 15 additions & 0 deletions dist/packages/lokidb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "lokidb",
"version": "0.0.1-beta.27",
"description": "Metapackage for LokiDB.",
"author": "Various authors",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/LokiJS-Forge/LokiDB.git"
},
"scripts": {
"postinstall": "node install.js",
"preuninstall": "node uninstall.js"
}
}
11 changes: 11 additions & 0 deletions dist/packages/lokidb/uninstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const common = require("./common");

const ROOT_DIRECTORY = common.getRootDirectory();

// Bundle all packages.
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);

common.print("Uninstall all @lokidb packages.");

// Uninstall packages.
common.run("npm", ["uninstall", "--prefix", ROOT_DIRECTORY, ...packages]);
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@lokidb/lokidb-src",
"name": "@lokidb/sources",
"version": "2.0.0-beta.6",
"description": "Fast document oriented javascript in-memory database",
"description": "Top-level scripts and dependencies for the LokiDB monorepo. Not meant to be published to npm.",
"author": "Various authors",
"license": "(MIT OR Apache-2.0)",
"scripts": {
Expand All @@ -26,12 +26,14 @@
},
"keywords": [
"javascript",
"typescript",
"document-oriented",
"mmdb",
"database",
"in-memory",
"json",
"lokidb",
"in-memory"
"lokijs"
],
"bugs": {
"url": "https://github.com/LokiJS-Forge/LokiDB/issues"
Expand Down
2 changes: 1 addition & 1 deletion packages/fs-storage/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lokidb/fs-storage",
"description": "A persistence adapter which persists to node fs module storage.",
"description": "A persistence adapter which persists to node's filesystem storage.",
"author": "Various authors",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/loki/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@lokidb/loki",
"description": "Fast document oriented javascript in-memory database",
"description": "A fast and feature-rich document oriented in-memory database.",
"author": "Various authors",
"license": "MIT",
"repository": {
Expand Down
102 changes: 102 additions & 0 deletions packages/lokidb/common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
const {spawn} = require("child_process");
const fs = require("fs");
const path = require("path");

const PACKAGES = [
"fs-storage",
"full-text-search",
"full-text-search-language",
"full-text-search-language-de",
"full-text-search-language-en",
"indexed-storage",
"local-storage",
"loki",
"memory-storage",
"partitioning-adapter",
];

/// MIT © Sindre Sorhus
function pathExistsSync(fp) {
try {
fs.accessSync(fp);
return true;
} catch (err) {
return false;
}
}

/// MIT © Sindre Sorhus
function locatePathSync(iterable, options) {
options = Object.assign({
cwd: process.cwd()
}, options);

for (const el of iterable) {
if (pathExistsSync(path.resolve(options.cwd, el))) {
return el;
}
}
}

/// MIT © Sindre Sorhus
function findUpSync(filename, opts = {}) {
let dir = path.resolve(opts.cwd || "");
const {root} = path.parse(dir);

const filenames = [].concat(filename);

// eslint-disable-next-line no-constant-condition
while (true) {
const file = locatePathSync(filenames, {cwd: dir});

if (file) {
return path.join(dir, file);
}

if (dir === root) {
return null;
}

dir = path.dirname(dir);
}
}

function getRootDirectory() {
return process.env.INIT_CWD || path.dirname(findUpSync("package.json"));
}

function getRootPackageJSON() {
return require(path.join(getRootDirectory(), "package.json"));
}

function getPackageDependencyType(packageJson, packageName) {
if (packageJson.dependencies && Object.keys(packageJson.dependencies).includes(packageName)) {
return "production";
} else if (packageJson.devDependencies && Object.keys(packageJson.devDependencies).includes(packageName)) {
return "development";
}
return null;
}

function run(command, args = []) {
const child = spawn(command, args);
child.stdout.on("data", (data) => {
console.log(data.toString("utf8"));
});
child.stderr.on("data", (data) => {
console.error(data.toString("utf8"));
});
}

function print(txt, lb = "\n") {
process.stdout.write(txt + lb);
}

module.exports = {
PACKAGES,
getRootDirectory,
getRootPackageJSON,
getPackageDependencyType,
run,
print
};
20 changes: 20 additions & 0 deletions packages/lokidb/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const common = require("./common");

const ROOT_DIRECTORY = common.getRootDirectory();
const PACKAGE_JSON = common.getRootPackageJSON();

let DEPENDENCY_ARGUMENT = "";
const DEPENDENCY_TYPE = common.getPackageDependencyType(PACKAGE_JSON, "lokidb");
if (DEPENDENCY_TYPE === "production") {
DEPENDENCY_ARGUMENT = "--save-prod";
} else if (DEPENDENCY_TYPE === "development") {
DEPENDENCY_ARGUMENT = "--save-dev";
}

// Bundle all packages.
const packages = common.PACKAGES.map((packageName) => `@lokidb/${packageName}`);

common.print("Install all @lokidb packages...");

// Install packages.
common.run("npm", ["install", "--prefix", ROOT_DIRECTORY, DEPENDENCY_ARGUMENT, ...packages]);
15 changes: 15 additions & 0 deletions packages/lokidb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "lokidb",
"version": "0.0.1-beta.26",
"description": "Metapackage for LokiDB.",
"author": "Various authors",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/LokiJS-Forge/LokiDB.git"
},
"scripts": {
"postinstall": "node install.js",
"preuninstall": "node uninstall.js"
}
}
Loading

0 comments on commit c021187

Please sign in to comment.