#!/usr/bin/env python3
"""Compose skin.milionar.modern into a folder (docs/plan/skin-milionar/240-modern.md).

  compose_modern.py                 the installed development copy, addons/skin.milionar.modern (sync_dev.sh runs it)
  compose_modern.py --out DIR       a fresh tree anywhere (offline checks)

The installer composes the same files on the device (wcs/skin/compose.py); the installed copy keeps its manifest,
changelog and the runtime files the installer added (Estuary textures and fonts, logo).
"""
import argparse
import os
import sys

ROOT = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', '..'))
sys.path.insert(0, ROOT)
from wcs.skin import compose  # noqa: E402

CLASSIC = os.path.join(ROOT, 'resources', 'skin.milionar')
OVERLAY = os.path.join(ROOT, 'resources', 'skin.milionar.modern')
INSTALLED = os.path.join(os.path.dirname(ROOT), 'skin.milionar.modern')


def main():
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument('--out', help='target folder (default: the installed development copy)')
    args = parser.parse_args()
    target = args.out or INSTALLED
    if not args.out and not os.path.isdir(target):
        raise SystemExit('skin.milionar.modern is not installed (the service installs it on start)')
    keep = () if args.out else ('addon.xml', 'changelog.txt')
    written = compose.write(CLASSIC, OVERLAY, target, only=lambda relative: relative not in keep)
    print('composed {} -> {} ({} changed)'.format(OVERLAY, target, len(written)))
    for relative in written[:20]:
        print('  ' + relative)


if __name__ == '__main__':
    main()
