Coder Social home page Coder Social logo

williamvinogradov / node-filing-cabinet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from dependents/node-filing-cabinet

0.0 0.0 0.0 483 KB

Get the file location associated with a dependency/partial's path

JavaScript 98.38% TypeScript 1.62% Sass 0.01%

node-filing-cabinet's Introduction

filing-cabinet npm npm

Get the file associated with a dependency/partial's path

npm install --save filing-cabinet

Usage

var cabinet = require("filing-cabinet");

var result = cabinet({
  partial: "somePartialPath",
  directory: "path/to/all/files",
  filename: "path/to/parent/file",
  ast: {}, // an optional AST representation of `filename`
  // Only for JavaScript files
  config: "path/to/requirejs/config",
  webpackConfig: "path/to/webpack/config",
  nodeModulesConfig: {
    entry: "module",
  },
  tsConfig: "path/to/tsconfig.json" // or an object
  tsConfigPath: "path/to/tsconfig.json",
});

console.log(result); // /absolute/path/to/somePartialPath
  • partial: the dependency path
  • This could be in any of the registered languages
  • directory: the path to all files
  • filename: the path to the file containing the partial
  • ast: (optional) the parsed AST for filename.
  • Useful optimization for avoiding a parse of filename
  • config: (optional) requirejs config for resolving aliased JavaScript modules
  • webpackConfig: (optional) webpack config for resolving aliased JavaScript modules. If exporting multiple configurations, the first configuration is used.
  • nodeModulesConfig: (optional) config for resolving entry file for node_modules. This value overrides the main attribute in the package.json file; used in conjunction with the packageFilter of the resolve package.
  • tsConfig: (optional) path to a typescript configuration. Could also be an object representing a pre-parsed typescript config.
  • tsConfigPath: (optional) A (virtual) Path to typescript config file when tsConfig option is given as an object, not a string. Needed to calculate Path Mapping. If not given when tsConfig is an object, Path Mapping is ignored. This is not need when tsConfig is given as string (path to the tsconfig file).
  • noTypeDefinitions: (optional) For typescript files, whether to prefer *.js over *.d.ts.

Registered languages

By default, filing-cabinet provides support for the following languages:

  • JavaScript: CommonJS, AMD, ES6
  • TypeScript
  • CSS Preprocessors: Sass (.scss and .sass), Stylus (.styl), and Less (.less)

You can register resolvers for new languages via cabinet.register(extension, resolver).

  • extension: the extension of the file that should use the custom resolver (ex: '.py', '.php')
  • resolver: a function that accepts the following (ordered) arguments that were given to cabinet:
    • partial
    • filename
    • directory
    • config

For examples of resolver implementations, take a look at the default language resolvers:

If a given extension does not have a registered resolver, cabinet will use a generic file resolver which is basically require('path').join with a bit of extension defaulting logic.

Shell script

  • Requires a global install npm install -g filing-cabinet

filing-cabinet [options] <dependencyPath>

  • See filing-cabinet --help for details on the options

node-filing-cabinet's People

Contributors

mrjoelkemp avatar realityking avatar pahen avatar dependabot[bot] avatar jstevans avatar jjangga0214 avatar bpscott avatar vansosnin avatar digitalkaoz avatar simenb avatar pcardune avatar igrayson avatar igmdvc avatar jkemp-spotify avatar dazinator avatar h7kayama avatar pastak avatar re-fort avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.