This code imports modules and exports a listInProject
function that searches for files in a specified directory using glob patterns.
npm run import -- "list project files"
var path = require('path');
var {ignores} = importer.import("common ignore paths");
var {glob} = importer.import("glob files")
// TODO: pull all from gitignore library and add to ignore list
// https://github.com/github/gitignore
// TODO: submit script to github project for fame and fortune!
// But we also want to automatically load projects?
function listInProject(root, match = '{,*,*/,*/*/*,*/*/*/*,*/*/*/*/*}package.json') {
return glob(match, path.resolve(root))
}
module.exports = {
listInProject
}
const path = require('path');
const { ignores } = require('gitignore-webpack-plugin');
const glob = require('glob');
/**
* Lists files in a project directory based on a glob pattern.
*
* @param {string} root - The project root directory.
* @param {string} [match='{,*,*/,*/*/*,*/*/*/*,*/*/*/*/*}package.json'] - Glob pattern to match files.
* @returns {string[]} - An array of file paths that match the glob pattern.
*/
function listInProject(root, match = '{,*,*/,*/*/*,*/*/*/*,*/*/*/*/*}package.json') {
return glob.sync(match, { cwd: path.resolve(root) });
}
module.exports = {
/**
* Lists files in a project directory based on a glob pattern.
*
* @param {string} root - The project root directory.
* @param {string} [match='{,*,*/,*/*/*,*/*/*/*,*/*/*/*/*}package.json'] - Glob pattern to match files.
* @returns {string[]} - An array of file paths that match the glob pattern.
*/
listInProject,
};
var path = require('path');
var {ignores} = importer.import('common ignore paths');
var {glob} = importer.import('glob files')
This code imports two modules:
path
: a built-in Node.js module for working with file paths.common ignore paths
and glob files
from an importer
module:
ignores
is expected to contain common ignore paths.glob
is a function for finding files using glob patterns.listInProject
function listInProject(root, match = '{,*,*/,*/*/*,*/*/*/*,*/*/*/*/*}package.json') {
return glob(match, path.resolve(root))
}
This function takes two parameters:
root
: the root directory to search for files.match
(optional, defaults to a glob pattern matching certain files): a glob pattern to use for finding files.The function uses the glob
function to find files matching the provided glob pattern, in the specified root
directory. It then resolves the root
path using path.resolve()
.
module.exports = {
listInProject
}
This code exports the listInProject
function as a module, making it available for use in other parts of the application.