-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add lokidb as meta package to install all packages at once
- Loading branch information
Showing
14 changed files
with
359 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
Oops, something went wrong.