🆙 Add cms i using 🆙

This commit is contained in:
Remco
2025-11-25 22:42:56 +01:00
parent 94704e0925
commit d44196149e
35591 changed files with 3601123 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true
[*.json]
indent_size = 2
indent_style = space
[*.md]
indent_style = space
+239
View File
@@ -0,0 +1,239 @@
{
"env": {
"amd": false,
"browser": false,
"es6": true,
"jasmine": false,
"jquery": false,
"meteor": false,
"mocha": false,
"node": true,
"prototypejs": false,
"shelljs": false
},
"ecmaFeatures": {
"arrowFunctions": true,
"binaryLiterals": false,
"blockBindings": false,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"generators": false,
"globalReturn": false,
"jsx": false,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralDuplicateProperties": false,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"octalLiterals": false,
"regexUFlag": false,
"regexYFlag": false,
"spread": true,
"superInFunctions": false,
"templateStrings": true,
"unicodeCodePointEscapes": true
},
"rules": {
// Possible Errors
"comma-dangle": [2, "never"], // disallow or enforce trailing commas
"no-cond-assign": "except-parens", // disallow assignment in conditional expressions
"no-console": 0, // disallow use of console (off by default in the node environment)
"no-constant-condition": 2, // disallow use of constant expressions in conditions
"no-control-regex": 2, // disallow control characters in regular expressions
"no-debugger": 2, // disallow use of debugger
"no-dupe-args": 2, // disallow duplicate arguments in functions
"no-dupe-keys": 2, // disallow duplicate keys when creating object literals
"no-duplicate-case": 2, // disallow a duplicate case label.
"no-empty": 0, // disallow empty statements
"no-empty-class": 2, // disallow the use of empty character classes in regular expressions
"no-ex-assign": 2, // disallow assigning to the exception in a catch block
"no-extra-boolean-cast": 2, // disallow double-negation boolean casts in a boolean context
"no-extra-parens": 2, // disallow unnecessary parentheses (off by default)
"no-extra-semi": 2, // disallow unnecessary semicolons
"no-func-assign": 2, // disallow overwriting functions written as function declarations
"no-inner-declarations": [2, "both"], // disallow function or variable declarations in nested blocks
"no-invalid-regexp": 2, // disallow invalid regular expression strings in the RegExp constructor
"no-irregular-whitespace": 2, // disallow irregular whitespace outside of strings and comments
"no-negated-in-lhs": 2, // disallow negation of the left operand of an in expression
"no-obj-calls": 2, // disallow the use of object properties of the global object (Math and JSON) as functions
"no-regex-spaces": 2, // disallow multiple spaces in a regular expression literal
"no-reserved-keys": 0, // disallow reserved words being used as object literal keys (off by default)
"no-sparse-arrays": 2, // disallow sparse arrays
"no-unreachable": 2, // disallow unreachable statements after a return, throw, continue, or break statement
"use-isnan": 2, // disallow comparisons with the value NaN
"value-jsdoc": 0,
// "valid-jsdoc": [2, { // Ensure JSDoc comments are valid (off by default)
// "prefer": {
// "returns": "return"
// },
// "requireParamDescription": true,
// "requireReturn": false,
// "requireReturnDescription": true
// }],
"valid-typeof": 2, // Ensure that the results of typeof are compared against a valid string
// Best Practices
"block-scoped-var": 0, // treat var statements as if they were block scoped (off by default)
"complexity": 0, // specify the maximum cyclomatic complexity allowed in a program (off by default)
"consistent-return": 2, // require return statements to either always or never specify values
"curly": [2, "multi-line"], // specify curly brace conventions for all control statements
"default-case": 2, // require default case in switch statements (off by default)
"dot-notation": [2, { // encourages use of dot notation whenever possible
"allowKeywords": true,
"allowPattern": "^[a-z]+([_-][a-z]+)+$"
}],
"eqeqeq": [2, "allow-null"], // require the use of === and !==
"guard-for-in": 2, // make sure for-in loops have an if statement (off by default)
"no-alert": 2, // disallow the use of alert, confirm, and prompt
"no-caller": 2, // disallow use of arguments.caller or arguments.callee
"no-div-regex": 2, // disallow division operators explicitly at beginning of regular expression (off by default)
"no-else-return": 2, // disallow else after a return in an if (off by default)
"no-empty-label": 2, // disallow use of labels for anything other then loops and switches
"no-eq-null": 0, // disallow comparisons to null without a type-checking operator (off by default)
"no-eval": 2, // disallow use of eval()
"no-extend-native": 2, // disallow adding to native types
"no-extra-bind": 2, // disallow unnecessary function binding
"no-fallthrough": 2, // disallow fallthrough of case statements
"no-floating-decimal": 2, // disallow the use of leading or trailing decimal points in numeric literals (off by default)
"no-implied-eval": 2, // disallow use of eval()-like methods
"no-iterator": 2, // disallow usage of __iterator__ property
"no-labels": 0, // disallow use of labeled statements
"no-lone-blocks": 2, // disallow unnecessary nested blocks
"no-loop-func": 2, // disallow creation of functions within loops
"no-multi-spaces": 2, // disallow use of multiple spaces
"no-multi-str": 2, // disallow use of multiline strings
"no-native-reassign": 2, // disallow reassignments of native objects
"no-new": 2, // disallow use of new operator when not part of the assignment or comparison
"no-new-func": 2, // disallow use of new operator for Function object
"no-new-wrappers": 2, // disallows creating new instances of String,Number, and Boolean
"no-octal": 2, // disallow use of octal literals
"no-octal-escape": 2, // disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
"no-param-reassign": 0, // disallow reassignment of function parameters (off by default)
"no-process-env": 2, // disallow use of process.env (off by default)
"no-proto": 2, // disallow usage of __proto__ property
"no-redeclare": 2, // disallow declaring the same variable more then once
"no-return-assign": 0, // disallow use of assignment in return statement
"no-script-url": 0, // disallow use of javascript: urls.
"no-self-compare": 2, // disallow comparisons where both sides are exactly the same (off by default)
"no-sequences": 2, // disallow use of comma operator
"no-throw-literal": 2, // restrict what can be thrown as an exception (off by default)
"no-unused-expressions": 2, // disallow usage of expressions in statement position
"no-void": 2, // disallow use of void operator (off by default)
"no-warning-comments": 1, // disallow usage of configurable warning terms in comments": 0, // e.g. TODO or FIXME (off by default)
"no-with": 2, // disallow use of the with statement
"radix": 0, // require use of the second argument for parseInt() (off by default)
"vars-on-top": 0, // requires to declare all vars on top of their containing scope (off by default)
"wrap-iife": [2, "inside"], // require immediate function invocation to be wrapped in parentheses (off by default)
"yoda": 0, // require or disallow Yoda conditions
// Strict mode
"strict": "global", // controls location of Use Strict Directives
// Variables
"no-catch-shadow": 2, // disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment)
"no-delete-var": 2, // disallow deletion of variables
"no-label-var": 2, // disallow labels that share a name with a variable
"no-shadow": 2, // disallow declaration of variables already declared in the outer scope
"no-shadow-restricted-names": 2, // disallow shadowing of names such as arguments
"no-undef": 2, // disallow use of undeclared variables unless mentioned in a /*global */ block
"no-undef-init": 2, // disallow use of undefined when initializing variables
"no-undefined": 0, // disallow use of undefined variable (off by default)
"no-unused-vars": [2, { // disallow declaration of variables that are not used in the code
"vars": "all",
"args": "after-used"
}],
"no-use-before-define": 2, // disallow use of variables before they are defined
// Node.js
"handle-callback-err": 2, // enforces error handling in callbacks (off by default) (on by default in the node environment)
"no-mixed-requires": 0, // disallow mixing regular variable and require declarations (off by default) (on by default in the node environment)
"no-new-require": 2, // disallow use of new operator with the require function (off by default) (on by default in the node environment)
"no-path-concat": 2, // disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment)
"no-process-exit": 2, // disallow process.exit() (on by default in the node environment)
"no-restricted-modules": 0, // restrict usage of specified node modules (off by default)
"no-sync": 0, // disallow use of synchronous methods (off by default)
// Style
"indent": [2, "tab", { // this option sets a specific tab width for your code (off by default)
"indentSwitchCase": true
}],
"brace-style": [0, "stroustrup"], // enforce one true brace style (off by default)
"camelcase": [2, { // require camel case names
"properties": "always"
}],
"comma-spacing": [2, { // enforce spacing before and after comma
"before": false,
"after": true
}],
"comma-style": [2, "last"], // enforce one true comma style (off by default)
"consistent-this": [0, "self"], // enforces consistent naming when capturing the current execution context (off by default)
"eol-last": 2, // enforce newline at the end of file, with no multiple empty lines
"func-names": 0, // require function expressions to have a name (off by default)
"func-style": [2, "declaration"], // enforces use of function declarations or expressions (off by default)
"key-spacing": [2, { // enforces spacing between keys and values in object literal properties
"beforeColon": false,
"afterColon": true
}],
"max-nested-callbacks": [2, 4], // specify the maximum depth callbacks can be nested (off by default)
"new-cap": 2, // require a capital letter for constructors
"new-parens": 2, // disallow the omission of parentheses when invoking a constructor with no arguments
"newline-after-var": [2, "always"], // allow/disallow an empty newline after var statement (off by default)
"no-array-constructor": 2, // disallow use of the Array constructor
"no-continue": 0, // disallow use of the continue statement (off by default)
"no-inline-comments": 0, // disallow comments inline after code (off by default)
"no-lonely-if": 2, // disallow if as the only statement in an else block (off by default)
"no-mixed-spaces-and-tabs": 2, // disallow mixed spaces and tabs for indentation
"no-multiple-empty-lines": [2, { // disallow multiple empty lines (off by default)
"max": 1
}],
"no-nested-ternary": 2, // disallow nested ternary expressions (off by default)
"no-new-object": 2, // disallow use of the Object constructor
"no-spaced-func": 2, // disallow space between function identifier and application
"no-ternary": 0, // disallow the use of ternary operators (off by default)
"no-trailing-spaces": 2, // disallow trailing whitespace at the end of lines
"no-underscore-dangle": 0, // disallow dangling underscores in identifiers
"no-wrap-func": 2, // disallow wrapping of non-IIFE statements in parens
"one-var": [2, "always"], // allow or disallow one variable declaration per function (off by default)
"operator-assignment": [2, "always"], // require assignment operator shorthand where possible or prohibit it entirely (off by default)
"operator-linebreak": [2, "before"], // enforce operators to be placed before or after line breaks (off by default)
"padded-blocks": [2, "never"], // enforce padding within blocks (off by default)
"quote-props": [2, "as-needed"], // require quotes around object literal property names (off by default)
"quotes": [2, "single", "avoid-escape"], // specify whether backticks, double or single quotes should be used
"semi": [2, "always"], // require or disallow use of semicolons instead of ASI
"semi-spacing": [2, { // enforce spacing before and after semicolons
"before": false,
"after": true
}],
"sort-vars": 0, // sort variables within the same declaration block (off by default)
"space-after-keywords": [2, "always"], // require a space after certain keywords (off by default)
"space-before-blocks": [2, "always"], // require or disallow space before blocks (off by default)
"space-before-function-paren": [2, { // require or disallow space before function opening parenthesis (off by default)
"anonymous": "always",
"named": "never"
}],
"space-in-brackets": 0, /* need v1.0 */ // require or disallow spaces inside brackets (off by default)
"space-in-parens": [2, "never"], // require or disallow spaces inside parentheses (off by default)
"space-infix-ops": [2, "always"], // require spaces around operators
"space-return-throw-case": 2, // require a space after return, throw, and case
"space-unary-ops": [1, { // Require or disallow spaces before/after unary operators (words on by default, nonwords off by default)
"words": true,
"nonwords": false
}],
"spaced-line-comment": [2, "always"], // require or disallow a space immediately following the // in a line comment (off by default)
"wrap-regex": 2, // require regex literals to be wrapped in parentheses (off by default)
// ES6
"no-var": 0, // require let or const instead of var (off by default)
"object-shorthand": [2, "methods"], // require method and property shorthand syntax for object literals (off by default)
// Complexity
"max-depth": [2, 7], // specify the maximum depth that blocks can be nested (off by default)
"max-len": [2, 120, 4], // specify the maximum length of a line in your program (off by default)
"max-params": [2, 5], // limits the number of parameters that can be used in the function declaration. (off by default)
"max-statements": [2, 50] // specify the maximum number of statement allowed in a function (off by default)
}
}
@@ -0,0 +1 @@
* text=auto
+7
View File
@@ -0,0 +1,7 @@
.nyc_output/
coverage/
node_modules/
*.log
.*.swp
.npmignore
+26
View File
@@ -0,0 +1,26 @@
sudo: false
language: node_js
node_js:
- node
- '5.5'
- '5.4'
- '5.3'
- '5.2'
- '5.1'
- '5.0'
- '4.2'
- '4.1'
- '4.0'
- '0.12'
after_script:
- npm run coveralls
# microtime requires c++
env:
- CXX=g++-4.8
addons:
apt:
sources:
- ubuntu-toolchain-r-test
packages:
- g++-4.8
+132
View File
@@ -0,0 +1,132 @@
# `find-config`
[![NPM version][npm-img]][npm-url] [![Downloads][downloads-img]][npm-url] [![Build Status][travis-img]][travis-url] [![Coverage Status][coveralls-img]][coveralls-url] [![Chat][gitter-img]][gitter-url] [![Tip][amazon-img]][amazon-url]
Finds the first matching config file, if any, in the current directory, nearest ancestor, or user's home directory. Supports finding files within a subdirectory of an ancestor directory. Configurable with defaults set to support the [XDG Base Directory Specification][xdg] for configuration files.
Because this module is intended to find consistently named configuration files, it is case-sensitive and does not support globs. If you need a more generic solution, see [findup-sync][fus] or [look-up][lku].
[fus]: https://www.npmjs.com/package/findup-sync
[lku]: https://www.npmjs.com/package/look-up
[xdg]: http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
## Algorithm
Where X is the current directory:
1. If X/file.ext exists, return it. STOP
2. If X/.dir/file.ext exists, return it. STOP
3. If X has a parent directory, change X to parent. GO TO 1
4. Return NULL.
## Install
With [Node.js](http://nodejs.org):
$ npm install find-config
## Usage
```js
var findConfig = require('find-config');
// Find the path to the nearest `package.json`
var pkg = findConfig('package.json');
// Find the path to the nearest `.foorc` or `.config/foorc`
var foo = findConfig('.foorc');
// Find the path to the nearest `.foorc` or `.config/.foorc`
var foo = findConfig('.foorc', { dot: true });
// Find the path to the nearest module using Node.js module resolution.
// Will look for `bar.js` or `bar/index.js`, etc.
var foo = findConfig('bar', { module: true });
// Find the path to the nearest `baz.json` or `some/path/baz.json`
var foo = findConfig('baz.json', { dir: 'some/path' });
// Find the path to the nearest `qux.json` or `some/path/qux.json` in
// some other directory or its nearest ancestor directory.
var foo = findConfig('qux.json', { cwd: '/other/dir', dir: 'some/path' });
// Find and require the nearest `package.json`
var pkg = findConfig.require('package.json');
// Find and read the nearest `.foorc` or `.config/foorc`
var foo = findConfig.read('.foorc');
```
## API
### `findConfig(filename, [options]) : String|Null`
- `filename` `String` - Name of the configuration file to find.
- `options` `{Object=}`
- `cwd` `{String=}` - Directory in which to start looking. (Default: `process.cwd()`)
- `dir` `{String=}` - An optional subdirectory to check at each level. (Default: `'.config'`)
- `dot` `{Boolean=}` - Whether to keep the leading dot in the filename in `dir`. (Default: `false`)
- `home` `{Boolean=}` - Whether to also check the user's home directory. (Default: `true`)
- `module` `{Boolean=}` - Whether to use Node.js [module resolution][modres]. (Default: `false`)
Synchronously find the first config file matching a given name in the current directory or the nearest ancestor directory.
[modres]: https://nodejs.org/api/modules.html#modules_all_together
### `findConfig.obj(filename, [options]) : Object|Null`
- `filename` `String` - Name of the configuration file to find.
- `options` `{Object=}` - Same as `findConfig()`.
Finds first matching config file, if any and returns the matched directories and config file path.
### `findConfig.read(filename, [options]) : String|Null`
- `filename` `String` - Name of the configuration file to find.
- `options` `{Object=}` - Same as `findConfig()` with two additions.
- `encoding` `{String}` - File encoding. (Default: `'utf8'`).
- `flag` `{String}` - Flag. (Default: `'r'`).
Finds and reads the first matching config file, if any.
```js
var yaml = require('js-yaml');
var travis = yaml.safeLoad(findConfig.read('.travis.yml'));
```
### `findConfig.require(filename, [options]) : *`
- `filename` `String` - Name of the configuration file to find.
- `options` `{Object=}` - Same as `findConfig()`.
Finds and requires the first matching config file, if any. Implies `module` is `true`.
```js
var version = findConfig.require('package.json').version;
```
## Contribute
Standards for this project, including tests, code coverage, and semantics are enforced with a build tool. Pull requests must include passing tests with 100% code coverage and no linting errors.
## Test
$ npm test
----
© Shannon Moeller <me@shannonmoeller.com> (shannonmoeller.com)
Licensed under [MIT](http://shannonmoeller.com/mit.txt)
[amazon-img]: https://img.shields.io/badge/amazon-tip_jar-yellow.svg?style=flat-square
[amazon-url]: https://www.amazon.com/gp/registry/wishlist/1VQM9ID04YPC5?sort=universal-price
[coveralls-img]: http://img.shields.io/coveralls/shannonmoeller/find-config/master.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/shannonmoeller/find-config
[downloads-img]: http://img.shields.io/npm/dm/find-config.svg?style=flat-square
[gitter-img]: http://img.shields.io/badge/gitter-join_chat-1dce73.svg?style=flat-square
[gitter-url]: https://gitter.im/shannonmoeller/shannonmoeller
[npm-img]: http://img.shields.io/npm/v/find-config.svg?style=flat-square
[npm-url]: https://npmjs.org/package/find-config
[travis-img]: http://img.shields.io/travis/shannonmoeller/find-config.svg?style=flat-square
[travis-url]: https://travis-ci.org/shannonmoeller/find-config
+56
View File
@@ -0,0 +1,56 @@
'use strict';
var gulp = require('gulp'),
paths = {
gulp: './gulpfile.js',
src: './index.js',
test: './test/**/*.{e2e,spec}.js'
};
gulp.task('default', ['test']);
gulp.task('bench', function (done) {
var Benchmark = require('benchmark'),
suite = new Benchmark.Suite();
suite
.add('find-config', require('./test/find-config.bench'))
.add('findup-sync', require('./test/findup-sync.bench'))
.add('look-up', require('./test/look-up.bench'))
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').pluck('name'));
done();
})
.run({ async: true });
});
gulp.task('lint', function () {
var eslint = require('gulp-eslint');
return gulp
.src([paths.gulp, paths.src, paths.test])
.pipe(eslint())
.pipe(eslint.format());
});
gulp.task('cover', function () {
var istanbul = require('gulp-istanbul');
return gulp
.src(paths.src)
.pipe(istanbul())
.pipe(istanbul.hookRequire());
});
gulp.task('test', ['lint', 'cover'], function () {
var istanbul = require('gulp-istanbul'),
mocha = require('gulp-mocha');
return gulp
.src(paths.test)
.pipe(mocha({ reporter: 'spec' }))
.pipe(istanbul.writeReports());
});
+50
View File
@@ -0,0 +1,50 @@
{
"name": "find-config",
"version": "1.0.0",
"description": "Find the first config file matching a given name in the current directory or the nearest ancestor directory.",
"main": "src/find-config.js",
"scripts": {
"bench": "node test/benchmark",
"coveralls": "nyc report -r text-lcov | coveralls",
"pretest": "xo src/*.js test/**/*.js",
"test": "nyc -r html -r text ava -v test/*.js",
"watch": "watch 'npm test' src test -du --wait=5"
},
"repository": {
"type": "git",
"url": "https://github.com/shannonmoeller/find-config.git"
},
"keywords": [
"config",
"dot",
"rc",
"file",
"find",
"glob",
"xdg"
],
"author": "Shannon Moeller <me@shannonmoeller.com> (http://shannonmoeller.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/shannonmoeller/find-config/issues"
},
"homepage": "https://github.com/shannonmoeller/find-config",
"dependencies": {
"user-home": "^2.0.0"
},
"devDependencies": {
"ava": "^0.11.0",
"benchmark": "^2.1.0",
"coveralls": "^2.11.6",
"expect": "^1.14.0",
"findup-sync": "^0.3.0",
"look-up": "^0.8.3",
"microtime": "^2.0.0",
"nyc": "^5.6.0",
"watch": "^0.17.1",
"xo": "^0.12.1"
},
"engines": {
"node": ">= 0.12"
}
}
@@ -0,0 +1,140 @@
'use strict';
var fs = require('fs');
var path = require('path');
var home = require('user-home');
var fsReadFileSync = fs.readFileSync;
var fsStatSync = fs.statSync;
var pathJoin = path.join;
var pathResolve = path.resolve;
var DEFAULT_DIR = '.config';
var DEFAULT_ENC = 'utf8';
var LEADING_DOT = /^\./;
var PATH_SEP = path.sep;
// Does X/file.ext exist?
// Else, throw
function resolveFile(cwd, dir, filename) {
dir = pathJoin(cwd, dir);
var filepath = pathJoin(dir, filename);
var stat = fsStatSync(filepath);
return stat && {
cwd: cwd,
dir: dir,
path: filepath
};
}
// Does X/file.ext exist?
// Does X/file.ext.js exist?
// Does X/file.ext/index.js exist?
// Else, throw
function resolveModule(cwd, dir, filename) {
dir = pathJoin(cwd, dir);
var filepath = pathJoin(dir, filename);
var resolved = require.resolve(filepath);
return resolved && {
cwd: cwd,
dir: dir,
path: resolved
};
}
function findConfig(filename, options) {
var config = findConfigObj(filename, options);
return config && config.path;
}
function findConfigObj(filename, options) {
if (!filename) {
return null;
}
options = options || {};
var fileObj;
var dir = options.dir !== null && options.dir !== undefined ? options.dir : DEFAULT_DIR;
var dotless = options.dot ? filename : filename.replace(LEADING_DOT, '');
var resolve = options.module ? resolveModule : resolveFile;
var cwd = pathResolve(options.cwd || '.').split(PATH_SEP);
var i = cwd.length;
function test(x) {
// Does X/file.ext exist?
try {
return resolve(x, '', filename);
} catch (e) {
}
// Does X/.dir/file.ext exist?
try {
return resolve(x, dir, dotless);
} catch (e) {
}
}
// Walk up path.
while (i--) {
fileObj = test(cwd.join(PATH_SEP));
// istanbul ignore next
if (fileObj) {
return fileObj;
}
// Change X to parent.
cwd.pop();
}
// Check in home.
if (options.home || options.home === null || options.home === undefined) {
fileObj = test(home);
// istanbul ignore next
if (fileObj) {
return fileObj;
}
}
return null;
}
function findConfigRead(filename, options) {
if (!filename) {
return null;
}
options = options || {};
var filepath = findConfig(filename, options);
return filepath && fsReadFileSync(filepath, {
encoding: options.encoding || DEFAULT_ENC,
flag: options.flag
});
}
function findConfigRequire(filename, options) {
if (!filename) {
return null;
}
options = options || {};
options.module = true;
var filepath = findConfig(filename, options);
return filepath && require(filepath);
}
module.exports = findConfig;
module.exports.obj = findConfigObj;
module.exports.read = findConfigRead;
module.exports.require = findConfigRequire;
@@ -0,0 +1,16 @@
var findConfig = require('../../src/find-config');
var path = require('path');
var cwd = path.resolve(__dirname, '../fixtures/a/b');
function test() {
return [
findConfig('.waldo', {cwd: cwd}),
findConfig('foo.txt', {cwd: cwd}),
findConfig('baz.txt', {cwd: cwd}),
findConfig('find-config-3da35411-9d24-4dec-a7cb-3cb9416db670', {cwd: cwd})
];
}
console.log('find-config', test());
module.exports = test;
@@ -0,0 +1,16 @@
var findup = require('findup-sync');
var path = require('path');
var cwd = path.resolve(__dirname, '../fixtures/a/b');
function test() {
return [
findup('.{,config/}waldo', {cwd: cwd}),
findup('{,.config/}foo.txt', {cwd: cwd}),
findup('{,.config/}baz.txt', {cwd: cwd}),
findup('{,.config/}find-config-3da35411-9d24-4dec-a7cb-3cb9416db670', {cwd: cwd})
];
}
console.log('findup-sync', test());
module.exports = test;
@@ -0,0 +1,13 @@
var Benchmark = require('benchmark');
new Benchmark.Suite()
.add('find-config', require('./find-config.bench'))
.add('findup-sync', require('./findup-sync.bench'))
.add('look-up', require('./look-up.bench'))
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function () {
console.log('Fastest:', this.filter('fastest').map('name').join(', '));
})
.run({async: true});
@@ -0,0 +1,21 @@
var lookup = require('look-up');
var path = require('path');
var cwd = path.resolve(__dirname, '../fixtures/a/b');
function test() {
return [
lookup(['.waldo', '.config/waldo'], {cwd: cwd}),
lookup(['foo.txt', '.config/foo.txt'], {cwd: cwd}),
lookup(['baz.txt', '.config/baz.txt'], {cwd: cwd}),
lookup([
'find-config-3da35411-9d24-4dec-a7cb-3cb9416db670',
'.config/find-config-3da35411-9d24-4dec-a7cb-3cb9416db670'
], {
cwd: cwd
})
];
}
console.log('look-up', test());
module.exports = test;
@@ -0,0 +1,147 @@
import findConfig from '../src/find-config';
import path from 'path';
import test from 'ava';
const pathResolve = path.resolve;
const nofile = 'find-config-3da35411-9d24-4dec-a7cb-3cb9416db670';
function setup() {
process.chdir(__dirname);
}
test('should find files', async assert => {
setup();
const options = {cwd: 'fixtures/a/b'};
assert.is(findConfig('foo.txt', options), pathResolve('fixtures/a/foo.txt'));
assert.is(findConfig('bar.txt', options), pathResolve('fixtures/a/b/bar.txt'));
assert.is(findConfig('a.txt', options), pathResolve('fixtures/a.txt'));
process.chdir('fixtures/a/b');
assert.is(findConfig('foo.txt'), pathResolve('../foo.txt'));
assert.is(findConfig('bar.txt'), pathResolve('./bar.txt'));
assert.is(findConfig('a.txt'), pathResolve('../../a.txt'));
});
test('should find files in a directory', async assert => {
setup();
let options = {cwd: 'fixtures/a/b'};
assert.is(findConfig('baz.txt', options), pathResolve('fixtures/a/.config/baz.txt'));
assert.is(findConfig('qux.txt', options), pathResolve('fixtures/a/b/.config/qux.txt'));
process.chdir('fixtures/a/b');
assert.is(findConfig('baz.txt', options), pathResolve('../.config/baz.txt'));
assert.is(findConfig('qux.txt', options), pathResolve('./.config/qux.txt'));
});
test('should find files in a directory', async assert => {
setup();
let options = {cwd: 'fixtures/a/b', dir: false};
assert.is(findConfig('baz.txt', options), null);
assert.is(findConfig('a.txt', options), pathResolve('fixtures/a.txt'));
process.chdir('fixtures/a/b');
options = {dir: false};
assert.is(findConfig('baz.txt', options), null);
assert.is(findConfig('a.txt', options), pathResolve('../../a.txt'));
});
test('should drop leading dots in .dir', async assert => {
setup();
let options = {cwd: 'fixtures/a/b'};
assert.is(findConfig('.fred', options), null);
assert.is(findConfig('.waldo', options), pathResolve('fixtures/.config/waldo'));
process.chdir('fixtures/a/b');
assert.is(findConfig('.fred'), null);
assert.is(findConfig('.waldo'), pathResolve('../../.config/waldo'));
});
test('should keep leading dots in .dir', async assert => {
setup();
let options = {cwd: 'fixtures/a/b', dot: true};
assert.is(findConfig('.fred', options), pathResolve('fixtures/.config/.fred'));
assert.is(findConfig('.waldo', options), null);
process.chdir('fixtures/a/b');
options = {dot: true};
assert.is(findConfig('.fred', options), pathResolve('../../.config/.fred'));
assert.is(findConfig('.waldo', options), null);
});
test('should resolve modules', async assert => {
setup();
let options = {cwd: 'fixtures/a/b', module: true};
assert.is(findConfig('b', options), pathResolve('fixtures/b.js'));
assert.is(findConfig('baz', options), pathResolve('fixtures/a/.config/baz.js'));
process.chdir('fixtures/a/b');
options = {module: true};
assert.is(findConfig('b', options), pathResolve('../../b.js'));
assert.is(findConfig('baz', options), pathResolve('../.config/baz.js'));
});
test('should not find non-existant files', async assert => {
setup();
assert.is(findConfig(), null);
assert.is(findConfig(null), null);
assert.is(findConfig(nofile, {home: false}), null);
});
test('should read files', async assert => {
setup();
let options = {cwd: 'fixtures/a/b'};
assert.is(findConfig.read('foo.txt', options), 'foo\n');
assert.is(findConfig.read('baz.txt', options), 'baz\n');
});
test('should not read non-existant files', async assert => {
setup();
assert.is(findConfig.read(), null);
assert.is(findConfig.read(null), null);
assert.is(findConfig.read(nofile), null);
assert.is(findConfig.read(nofile, {home: false}), null);
assert.throws(() => {
findConfig.read('b', {cwd: 'fixtures/a/b'});
});
});
test('should require files', async assert => {
setup();
let options = {cwd: 'fixtures/a/b'};
assert.same(findConfig.require('b', options), {a: 1});
assert.same(findConfig.require('baz', options), {b: 2});
});
test('should not require non-existant files', async assert => {
setup();
assert.is(findConfig.require(), null);
assert.is(findConfig.require(null), null);
assert.is(findConfig.require(nofile), null);
assert.is(findConfig.require(nofile, {home: false}), null);
});
@@ -0,0 +1 @@
module.exports = { b: 2 };
@@ -0,0 +1 @@
baz
@@ -0,0 +1 @@
foo
@@ -0,0 +1 @@
module.exports = { a: 1 };