@thalesrc/nx-utils
v1.10.0
Published
[](https://www.npmjs.com/package/@thalesrc/nx-utils) [](https://www.npmjs.com/package/@thalesrc/nx-utils) [: File glob pattern, input object, or array of patterns/objects- Simple string:
"src/assets/**/*" - Object with options:
path: File glob patternoutput: Custom output path for this inputreplace: Replace strings in file content (supports environment variables with#{ENV_VAR})resize: Resize images (number,[width, height], or object for multiple sizes)
- Simple string:
output: Base output directorywatch: Watch for file changes (default:false)
Example with advanced features:
{
"executor": "@thalesrc/nx-utils:copy",
"options": {
"input": [
{
"path": "src/config.json",
"output": "dist",
"replace": {
"VERSION": "1.0.0",
"BUILD_DATE": "#{BUILD_DATE_ENV}"
}
},
{
"path": "src/icon.png",
"output": "dist/icons",
"resize": {
"20x20": "{name}-20x20.{ext}",
"40x40": "{name}-40x40.{ext}",
"128x128": "{name}-128x128.{ext}"
}
}
],
"output": "dist"
}
}📝 Fill Package JSON
Generate and populate package.json files with automatic exports configuration.
Usage:
{
"targets": {
"fill-package": {
"executor": "@thalesrc/nx-utils:fill-package-json",
"options": {
"outputPath": "dist/libs/my-lib",
"packageVersion": "1.0.0"
}
}
}
}Options:
outputPath(required): Output path for thepackage.jsonfilepackageVersion: Version to set in thepackage.jsonpopulateExports: Configure automatic exports generationexports: Array of export types ('require','default','import','node','types')exportsTemplateProperty: Property name for export templates (default:'_exports')barrelFileName: Name of the barrel file (default:'index.js')templates: Custom templates for each export type
Example with exports:
{
"executor": "@thalesrc/nx-utils:fill-package-json",
"options": {
"outputPath": "dist/libs/my-lib",
"packageVersion": "1.0.0",
"populateExports": {
"exports": ["require", "import", "types"],
"barrelFileName": "index.js"
}
}
}🔄 Run Parallel
Execute multiple commands in parallel with sequential readiness control.
Usage:
{
"targets": {
"dev": {
"executor": "@thalesrc/nx-utils:run-parallel",
"options": {
"commands": [
{
"command": "nx serve api",
"readyWhen": "ready on",
"stopWhenReady": false
},
"nx serve web"
]
}
}
}
}Options:
commands(required): Array of commands (string or object)- Simple string:
"npm run build" - Object:
command: Command or array of commands to runcwd: Working directory for the commandreadyWhen: String(s) to look for in output to determine readinessstopWhenReady: Stop the process when ready signal is detected
- Simple string:
cwd: Default working directory for all commandsaliases: Key-value pairs to replace in commands (use<<key>>syntax)
Example with aliases:
{
"executor": "@thalesrc/nx-utils:run-parallel",
"options": {
"commands": [
"nx serve <<app>>",
"nx test <<app>> --watch"
],
"aliases": {
"app": "my-app"
}
}
}🔨 TypeScript Builder
Build TypeScript files with custom configurations and output paths.
Usage:
{
"targets": {
"build": {
"executor": "@thalesrc/nx-utils:ts-builder",
"options": {
"files": ["src/**/*.ts", "!src/**/*.spec.ts"],
"outputPath": "dist/libs/my-lib",
"tsConfigPath": "tsconfig.lib.json"
}
}
}
}Options:
files: List of files to compile (default:['src/**/*.ts', '!src/**/*.spec.ts'])outputPath: Destination path relative to workspace root (default:'dist')tsConfigPath: Path to tsconfig file (default:'tsconfig.json')- Use
./or../for relative paths, otherwise treated as workspace-relative
- Use
👀 Watch
Watch files and execute commands on changes with path placeholder support.
Usage:
{
"targets": {
"watch-assets": {
"executor": "@thalesrc/nx-utils:watch",
"options": {
"glob": "src/**/*.scss",
"command": "sass <path> dist/<fileName>.css"
}
}
}
}Options:
glob(required): Glob pattern(s) to watchcommand(required): Command(s) to run on file changes- Placeholders:
<path>: Full file path<fileName>: File name without extension<fileExt>: File extension
- Placeholders:
platformVariables: Platform-specific variable replacements (see Platform Runner)
💻 Platform Runner
Execute scripts with platform-specific variable substitution.
Usage:
{
"targets": {
"run-script": {
"executor": "@thalesrc/nx-utils:platform-runner",
"options": {
"script": "echo <<greeting>> world",
"default": {
"greeting": "Hello"
},
"win32": {
"greeting": "Hello from Windows"
},
"darwin": {
"greeting": "Hello from macOS"
},
"linux": {
"greeting": "Hello from Linux"
}
}
}
}
}Options:
script(required): Script to execute (use<<variableName>>for placeholders)default(required): Default variable valueswin32: Windows-specific variablesdarwin: macOS-specific variableslinux: Linux-specific variablesaix: AIX-specific variablesfreebsd: FreeBSD-specific variablesopenbsd: OpenBSD-specific variablessunos: SunOS-specific variablesandroid: Android-specific variables
🔁 Run For Each
Execute a command for each item in a list or glob pattern.
Usage:
{
"targets": {
"process-files": {
"executor": "@thalesrc/nx-utils:run-for-each",
"options": {
"command": "node process.js <item>",
"items": ["file1.txt", "file2.txt", "file3.txt"],
"parallel": true
}
}
}
}Usage with glob:
{
"executor": "@thalesrc/nx-utils:run-for-each",
"options": {
"command": "node lint.js <path>",
"glob": "src/**/*.ts",
"parallel": false
}
}Options:
command(required): Command to run (<item>will be replaced)items: Array of items to iterate overglob: Glob pattern to get items from- Placeholders:
<path>: Full file path<fileName>: File name without extension<fileExt>: File extension
- Placeholders:
parallel: Run commands in parallel (default:true)platformVariables: Platform-specific variable replacements (see Platform Runner)
Development
Building
nx build nx-utilsRunning Tests
nx test nx-utilsLicense
MIT © Thalesrc
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
