Preview

Merge Source Files from Directories in Chain

Concept

Import source files from a chain of application modules.

Synposis

Sync/Import from other modules

Suppose your local application is dulcinea and you want a file lab.lua from directory separate_module, suppose directory dulcinea and separate_module are located in the same location, then create a file dulcinea/.app_stack.yml like:

sync:
  - separate_module: { lab.lua: '' }

and run

$ stackup 

under the dulcinea directory, lab.lua will copied from separate_module.

If the file lab.lua in separate_module changed, run stackup again in dulcinea will get a warning with colored diff message (you need diff command installed in your system). If you want to over-writtern dulcinea/lab.lua, run

$ stackup -f

If you want copy outside file only if local file not exists, use

sync:
  - separate_module: { lab.lua: '' }
  - other_module: { copymeto.inc: 'copymeto.php' }
import:
  - separate_module: { copyme: '' }

Note other_module/copymeto.inc will be copied as dulcinea/copymeto.php, as explicitly defined in the above example.

Export groups

If the remote module, like separate_module in the last example also appstack aware, it may have a file .app_stack.yml or app_stack.yml in their root folder like:

export:
  - some.lua
  - lib/**/*.lua
  - config:
    - config/*.lua

In this example setting, separate_module defined two export groups: default and config, default group contains some.lua and all lua files under lib/ folder and all it’s sub-folders. config group (which defined as a Hash with an Array value, in YAML format) conains all lua files under config/ folder. You can import config files while sync default files from separate_module by setting in dulcinea/.app_stack.yml like:

import:
  - separate_module
sync:
  - separate_module: [ config ]

Or you want to sync both:

sync:
  - separate_module: [ config, default ]

You can still request for files that not explicitly exported by the remote configuration:

sync:
  - separate_module: [ config, default, { config.lua: config.sample.lua } ]

will sync separate_module/config.lua as dulcinea/config.sample.lua, as expected.

Render a template file

Suppose you have a template file separate_module/main.lua.erb like:

...

local app_name = '<%= app_name %>'
local version = <%= version_code %>

...

And in separate_module/.app_stack.yml:

...
attrs:
  app_name: Separated Module
  version_code: 1.0

And in dulcinea/.app_stack.yml:

render:
  - separate_module: { main.lua.erb: '' }
attrs:
  app_name: Main App
  version_code: 1.0

You will get a file dulcinea/main.lua with contents

...

local app_name = 'Main App'
local version = 1.0

...

i.e., attrs are merged up from ALL stacked modules.

Parking list for new version (1.4)

  • [OK] Optional .app_stack.yml for stacked modules
  • [OK] Better detection for yaml file error
  • [OK] Better message with short file name
  • [OK] Render files only if contents really changed
  • new file only mode
  • Better simulate, new file only, force mode
  • Recursive stackup (?)
  • [OK] Separate sync/import group instead of one single stackapps