process-dir

4.0.1 • Public • Published

Process-dir

Process-dir is a configuration-based task runner. Your project config file maps file patterns to commands to run when those files are modified.

Commands are just Linux commands with placeholders for path and config information.

root: "src"
out: "lib"
process:
	"*.ls": "lsc -o {{outDir}} {{path}}"

This compiles LiveScript files in ./src to ./lib.

A process-dir config file is a LiveScript-JSON file called process.json.ls.

Config options

All are optional. Paths are relative to the config file.

root

Path to the source dir. Defaults to the dir containing the config file.

out

Path to the output dir. The name of the source dir will be appended if it ends in /. Defaults to ../compiled/ so if unspecified, the output dir for ./projects/my-project/process.json.ls will be ./projects/compiled/my-project.

process

Map of path patterns to commands. When the commands are executed, placeholders delimited by double braces are replaced with details about the current file and the configuration:

  • out - full path of the out option
  • root - full path of the root option
  • path - full path of the current file
  • name - name of the current file
  • dir - full path of the containing directory of the current file
  • outPath - full path of the file within the output dir
  • outDir - full path of the equivalent directory within the output dir for the current file
  • copy - complete command to copy the source file to the output file

Example:

/projects/express-app/process.json.ls:

out: "../compiled/"
exclude: [
	".git"
	"**/.sass-cache"
]
process:
	"**/*.json.ls": "lsc -j -o {{outDir}} {{path}}"
	"**/*.ls": "lsc -o {{outDir}} {{path}}"
	"**/*.sass":
		update: "sass --cache-location /tmp --update assets/css:{{out}}/assets/css"
init: [
	"sass --cache-location /tmp --update assets/css:{{out}}/assets/css"
]

If we modify /projects/express-app/routes/home/index.ls, the command placeholder values will be:

  • out: /projects/compiled/express-app
  • root: /projects/express-app
  • path: /projects/express-app/routes/home/index.ls
  • name: index.ls
  • dir: /projects/express-app/routes/home
  • outPath: /projects/compiled/express-app/routes/home/index.ls
  • outDir: /projects/compiled/express-app/routes/home
  • copy:
     mkdir -p /projects/compiled/express-app/routes/home
     cp /projects/express-app/routes/home/index.ls /projects/compiled/express-app/routes/home/index.ls
    

Note that the outPath ends in index.ls, not index.js -- the fact that there is a command defined that means the .ls file will be "turned into" a .js file is not taken into account here.

init

An array of commands to run once at startup. The only placeholders available are out and root.

exclude

An array of patterns to ignore (don't copy, link, or look for matching commands).

Command objects

Commands can be defined as either strings or objects mapping stages to strings. Commands under init are run once at startup; commands under update are run on subsequent modifications to files.

In the above example, we want to update the SASS exactly once on init (not once for each .sass file encountered), and once any time a .sass file is modified thereafter.

Running it

Arguments: [/path/to/project] [-w|--watch]

If no project dir arg is passed, the current directory is used.

I recommend using PM2 or another good node process manager -- here's an example PM2 setup:

pm2 start \
	--name=process-express-app
	--interpreter=/usr/bin/lsc
	/path/to/process-dir/process.ls -- /projects/express-app -w

process-dir will exit if the config file (process.json.ls) is modified -- if you're using a process manager, it will be restarted and use the new config.

You can also just run it in a shell:

$ lsc /path/to/process-dir/process.ls /projects/express-app -w

process-dir will look up the directory tree until it hits / or finds a process.json.ls in the current directory.

Readme

Keywords

none

Package Sidebar

Install

npm i process-dir

Weekly Downloads

17

Version

4.0.1

License

none

Last publish

Collaborators

  • npm