liferay-npm-scripts v32.7.0
liferay-npm-scripts
Usage
npm install --save-dev liferay-npm-scriptspackage.json
{
"scripts": {
"build": "liferay-npm-scripts build"
}
}Scripts Available
build
Build script that compiles all necessary javascript, soy, and bundles it together using liferay-npm-bundler.
liferay-npm-scripts buildDo you have soy dependencies? build should automatically detect them.
Do you need to use liferay-npm-bridge-generator? Just add a .npmbridgerc file and follow the configuration options here.
check
liferay-npm-scripts checkcheck runs ESLint to catch semantic problems in JS (equivalent to running eslint without the --fix option), stylelint to catch problems in SCSS files, and Prettier to catch formatting issues (equivalent to running prettier with the --check flag), for the globs specified in your npmscripts.config.js configuration (or, in the absence of explicit configuration, in the default preset).
This is the task that runs in liferay-portal projects when you run yarn checkFormat.
fix
liferay-npm-scripts fixfix runs ESLint and stylelint to identify and fix autofixable issues in JS and SCSS, and Prettier to enforce formatting (equivalent to calling prettier with the --write flag) for the globs specified in your npmscripts.config.js configuration (or, in the absence of explicit configuration, in the default preset).
This is the task that runs in liferay-portal projects when you run yarn format (or gradlew formatSource -a, or ant format-source).
prettier
liferay-npm-scripts prettierWhen liferay-npm-scripts uses Prettier, it additionally applies some tweaks in a post-processing step to match liferay-portal coding conventions. Normally, you will want to run liferay-npm-scripts check or liferay-npm-scripts fix as described above rather than interacting with the prettier executable directly.
However, in order to facilitate integration with editors and editor plugins, this subcommand exposes the augmented version of prettier, providing this "Prettier plus post-processing" functionality, using an interface that is similar to that of the prettier executable. Example usage:
liferay-npm-scripts prettier --write src/someFileToFormat.js 'test/**/*.js'Supported flags:
--stdin-filepath=FILEPATH--stdin--write
All other prettier flags are ignored.
Editor integrations
Vim
One way to run prettier from Vim is with the vim-prettier plugin. It comes with a setting, g:prettier#exec_cmd_path, that you can use to configure a custom prettier executable. For example, you could take this sample shell script and copy it somewhere such as ~/bin/:
curl https://raw.githubusercontent.com/liferay/liferay-npm-tools/master/packages/liferay-npm-scripts/contrib/prettier/prettier.sh > ~/bin/prettier.sh
chmod +x !$Then, add a line like this to your ~/.vim/vimrc:
let g:prettier#exec_cmd_path = "~/bin/prettier.sh"Now you can use the :Prettier command and others provided by the vim-prettier plugin in Vim, and it will use your script instead of the upstream version of Prettier. The script tries first to find the liferay-npm-scripts version, then prettier, and ultimately will fall back to npx prettier as a last resort. When working outside of a liferay-portal clone, it doesn't try to use the version provided by liferay-npm-scripts.
If you don't want to install vim-prettier, you can of course run the script directly using the ! command:
!~/bin/prettier.sh --write %Or, if the script is in your path:
!prettier.sh --write %And you can always call directly into liferay-npm-scripts if you prefer:
!path/to/liferay-npm-scripts prettier --write %Visual Studio Code
A popular choice for running prettier from VSCode is the "Prettier - Code Formatter" extension.
You can take this sample wrapper module and configure the extension to use it instead of the standard prettier one. For example, to install a copy of the wrapper to ~/bin/prettier.js, you could run the following:
curl https://raw.githubusercontent.com/liferay/liferay-npm-tools/master/packages/liferay-npm-scripts/contrib/prettier/prettier.js > ~/bin/prettier.jsIf you have the script at ~/bin/prettier.js, in the UI you would go to Preferences → Settings → User → Extensions → Prettier → Prettier Path and set it to ~/bin/prettier.js. Alternatively, if you prefer to manipulate the VSCode settings.json file directly, you would set prettier.prettierPath to ~/bin/prettier.js.
Note: You will have to restart VSCode for this change to actually take effect.
The wrapper script attempts to detect when you are working in a liferay-portal checkout and uses the customized Prettier formatting in that case; otherwise, it falls back to the standard behavior.
test
liferay-npm-scripts testRuns jest with a default configuration specified in jest.json. You can override or add any additional configuration by following jest documentaion.
Additionally if you want to use any flags for jest, such as --watch you can do so.
For example
liferay-npm-scripts test --watchtheme
liferay-npm-scripts theme TASKInside a theme directory, runs one of the available Gulp tasks, TASK, from liferay-theme-tasks, automatically passing settings for use inside liferay-portal.
For example:
liferay-npm-scripts theme buildRuns the "build" task, providing it with the configuration it needs to find core dependencies such as the liferay-frontend-theme-styled base theme files.
Config
Note: as of v2.x the config file was renamed from
.liferaynpmscriptsrctonpmscripts.config.js
If you need to add additional configuration you can do so by creating a npmscripts.config.js file at the root of your project. The default configuration of this file can be seen here.
preset
npmscripts.config.js allows for a preset option which is a pre-defined configuration. By default liferay-npm-scripts uses liferay-npm-scripts-preset-standard. If you want to create your own preset, you need to create an npm package or a local dependency. You can also extend from a preset by creating a npmscripts.config.js that looks something like...
module.exports = {
preset: 'path/to/some/dependency',
};
// or npm package (this needs to also be specified in your package.json)
module.exports = {
preset: 'my-cool-preset',
};If you want to extend from the standard preset and then add an additional dependency, you will have to do something like...
const standardPreset = require('liferay-npm-scripts/src/presets/standard/index');
module.exports = {
preset: 'liferay-npm-scripts/src/presets/standard/index',
build: {
dependencies: [...standardPreset.build.dependencies, 'asset-taglib'],
},
};If you just set dependencies to be ['my-new-dependency'], it will override the existing dependencies from the standard preset.
Other Config
If you need more flexibility over Babel or the bundler. You can still add a .babelrc.js or .npmbundlerrc which will be merged with the default settings this tool provides. Default Babel Config, Default Bundler Config
Want to use a different NODE_ENV? Try doing something like
NODE_ENV=development liferay-npm-scripts buildAppendix: stylelint rules
The shared stylelint configuration lists the rules that are activated from among the bundled rules in addition to the following custom rules that we've developed:
liferay/no-block-comments: Disallows block-style comments (/* ... */).liferay/no-import-extension: Disallows the use of an explicit ".scss" extension in Sass@importstatements.liferay/single-imports: Requires one@importstatement per imported resource.liferay/sort-imports: Requires@importstatements to be alphabetically sorted (separate groups of imports with a blank line to force manual ordering).liferay/trim-comments: Trims leading and trailing blank lines from comments.
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago