config redirect

This commit is contained in:
Nuno Coração
2023-01-29 22:30:24 +00:00
parent 17557c7d73
commit 5fb4bd8083
9905 changed files with 1258996 additions and 36355 deletions
+21
View File
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Brandwatch Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+73
View File
@@ -0,0 +1,73 @@
# vendor-copy
A utility to copy client-side dependencies into a folder. It looks for a
`vendorCopy` field in your `package.json`, which contains an array of objects,
each with a `to` and `from` field, which are paths relative to the
`package.json` file.
## npm script Usage
The CLI looks for configuration in a package.json file. It assumes that it's
being run from the same directory as the package file. This makes it ideal to
use as an npm script in the package file. For example (note in particular the
`postinstall` script):
```javascript
{
"scripts": {
"preinstall": "rimraf public/vendor"
"postinstall": "vendor-copy"
},
"dependencies": {
"someDependency": "1.0.0",
"someOtherDependency": "0.1.2",
"vendorCopy": "1",
"rimraf": "2"
},
"devDependencies": {
"someDevelopmentDependency": "4.3.2"
},
"vendorCopy": [
{
"from": "node_modules/someDependency/someDependency.js",
"to": "public/vendor/someDependency.js"
},
{
"from": "node_modules/someOtherDependency/someOtherDependency.js",
"to": "public/vendor/someOtherDependency.js"
}
],
"devVendorCopy": [
{
"from": "node_modules/someDevelopmentDependency/someDevelopmentDependency.js",
"to": "public/vendor/someDevelopmentDependency.js"
}
]
}
```
When `npm install` is used and has completed the installation of both
dependencies and development dependencies, it will copy items listed in
`"vendorCopy"` and `"devVendorCopy"`. When run in production mode, i.e. when
the `NODE_ENV` environment variable is `production` or when npm in invoked with
the `--production` flag, only items in `vendorCopy` are copied. In both cases
`rimraf` has been used to delete the `public/vendor` to ensure a clean copy.
## JS API
```javascript
const vendorCopy = require('vendor-copy');
```
### `const promise = vendorCopy(root, copyItems)`;
- `root` is an absolute base path.
- `copyItems` is an array of objects with `from` and `to` file paths.
`root` is prepended to all `from` and `to` paths. Each `from` resolves to a file
or directory, and will be copied to the `to` location. Intermediate directories
will be created as required.
The returned promise resolves when copying is complete. The resolution value is
an array like `copyItems`, but each `from` and `to` field is an absolute path.
Generated Vendored Executable
+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env node
'use strict';
const vendorCopy = require('.');
const path = require('path');
const root = process.cwd();
const pkg = require(path.join(root, 'package.json'));
const isProduction = process.env.npm_config_production === 'true' || process.env.NODE_ENV === 'production';
function logDone(items) {
items.forEach(item => {
console.log(`${item.from} => ${item.to}`); // eslint-disable-line no-console
});
}
function logError(error) {
console.error('Failed to install vendor modules:', error); // eslint-disable-line no-console
process.exit(1);
}
const toCopy = pkg.vendorCopy;
if (!isProduction) {
toCopy.push(...(pkg.devVendorCopy || []));
}
vendorCopy(root, toCopy).then(logDone, logError);
+32
View File
@@ -0,0 +1,32 @@
'use strict';
const path = require('path');
const fs = require('fs').promises;
const util = require('util');
const ncp = util.promisify(require('ncp'));
async function ensureDir(fromTo) {
const toPath = path.dirname(fromTo.to);
await fs.mkdir(toPath, { recursive: true });
}
async function copyFile(fromTo) {
await ncp(fromTo.from, fromTo.to, { dereference: true });
}
async function ensureDirAndCopy(root, relativeFromTo) {
const fromTo = {
from: path.join(root, relativeFromTo.from),
to: path.join(root, relativeFromTo.to)
};
await ensureDir(fromTo);
await copyFile(fromTo);
return fromTo;
}
module.exports = function (root, copyItems) {
return Promise.all(copyItems.map(relativeFromTo => ensureDirAndCopy(root, relativeFromTo)));
};
+39
View File
@@ -0,0 +1,39 @@
{
"name": "vendor-copy",
"version": "3.0.1",
"description": "A utility to copy client-side dependencies into a folder.",
"main": "index.js",
"bin": {
"vendor-copy": "./cli.js"
},
"files": [
"index.js",
"cli.js"
],
"engines": {
"node": ">=12"
},
"dependencies": {
"ncp": "^2.0.0"
},
"devDependencies": {
"es2015-deferred": "^3.0.0",
"eslint": "^7.24.0",
"eslint-config-qubyte": "^4.1.0",
"mocha": "^8.3.2",
"sandboxed-module": "^2.0.4",
"sinon": "^10.0.0"
},
"scripts": {
"test": "mocha tests",
"posttest": "rm -rf test-copy-space",
"lint": "eslint ."
},
"repository": "github:qubyte/vendor-copy",
"author": "Mark S. Everitt",
"license": "MIT",
"bugs": {
"url": "https://github.com/qubyte/vendor-copy/issues"
},
"homepage": "https://github.com/qubyte/vendor-copy#readme"
}