简体   繁体   中英

How to load an external file inside npm script?

PURPOSE: To test the linting of only some of the components in my source and not all the files.

I am trying to execute a command on all the folders inside a config file :

    //package.json
    "scripts": {
    "lint1": "eslint src/actions"
    "lint2": "eslint src/components/component1"
    "lint3": "eslint src/components/component2"
    ....
    }

Instead of having multiple commands for each folder, I want my npm script to load all the required folder paths from an external config file(something like below) and iteratively run the lint for each of those paths in one command.

//config.js
paths = [
'src/actions',
'src/components/component1',
'src/components/component2',
'src/components/component3',
]

How to do this ? or any better way to do it using npm?

PS: I dont want to do it the other way around by putting the unwanted paths in eslintignore.js file

It could be much easier if your config file could be a text file containing:

src/actions
src/components/component1
src/components/component2
src/components/component3

If it's paths.txt then you could have this in package.json:

"scripts": {
    "lint1": "eslint $(cat paths.txt)"
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM