tml-build

TML basic build tool

npm install tml-build
8 downloads in the last week
32 downloads in the last month

tml-build(3) -- TML build tools

SYNOPSIS

tml-build TML build tools.

OPTIONS

SYNTAX

ENVIRONMENT

RETURN VALUES

STANDARDS

SECURITY CONSIDERATIONS

BUGS

HISTORY

AUTHOR

SEE ALSO

IMPLEMENTATION


Build

    @purpose TML build tools;
    @author Erin Phillips;
    @version 0.0.1-13;
    @history 2013-04-29 EMP Initial Version;
    @history 2013-04-30 EMP [0.0.1-1] add-version-build;
    @history 2013-04-30 EMP [0.0.1-2] removing-makefile-tests;
    @history 2013-04-30 EMP [0.0.1-3] adding-bin;
    @history 2013-04-30 EMP [0.0.1-4] fixing-package-json;
    @history 2013-04-30 EMP [0.0.1-5] remove-debug-log;
    @history 2013-04-30 EMP [0.0.1-6] call-global-tml-build;
    @history 2013-04-30 EMP [0.0.1-7] fix-bin-exec;
    @history 2013-04-30 EMP [0.0.1-8] fix-pkg-json-path;
    @history 2013-04-30 EMP [0.0.1-9] text-using-cwd;
    @history 2013-04-30 EMP [0.0.1-10] fix-errant-version-changes;
    @history 2013-04-30 EMP [0.0.1-11] fix-errant-version-changes;
    @history 2013-04-30 EMP [0.0.1-12] fix-errant-version-changes;
    @history 2013-04-30 EMP [0.0.1-13] fix-description;

resources

    CON = console
    TMLR = tml-runtime
    CORE = tml-core
    IO = tml-io
    EXEC = child_process

locals

tags

notes

    @usecase

    read package.json file
    increment version
    update package.json file

    read module source file
    increment version
    update source file

    build Makefile
    save Makefile
    ;

messages

    ERR-VER.100 {*} Part must be <=3, not {1};
    INF-HIST {1} {2} [{3}] {4};

code


-- PATTERNS --;


-- STATICS --;

var makefileBody = """

    |# SHARED VARS
    |
    |export TML_HOME=$(shell pwd)
    |TML_MANUAL="%MANUAL%"
    |TML_ORGANIZATION="%ORGANIZATION%"
    |RONN=ronn --roff --manual=$(TML_MANUAL) --organization=$(TML_ORGANIZATION)
    |MOCHA=mocha 
    |TARGETS=$(patsubst src/%.tml,lib/%.js,$(wildcard src/*.tml))
    |TESTS=test/*.js
    |MAKELIST=
    |COPY=cp
    |WEB_DEPS=%WEB_DEPS%
    |
    |# LOCAL VARS
    |
    |MOD=%MODULE%
    |CLS=%CLASS%
    |
    |# RECIPES
    |
    |all: man/$(MOD).3 $(TARGETS) $(WEB_DEPS)
    |\ttmlc $(MAKELIST)
    |\t@$(MOCHA)
    |
    |%MAKE_WEB_DEPS%
    |man/$(MOD).3: README.md ; @echo $@
    |\t@$(RONN) < $< > $@
    |
    |README.md: src/$(CLS).tml; @echo $@
    |\t@$(COPY) $< $@
    |
    |lib/%.js: src/%.tml; @echo $@
    |\t$(eval MAKELIST += $(basename $(notdir $@)))
    |"""

var copyDepText = """

    |public/j/%CLASS%.js: $(CODE_ROOT)/%MODULE%/lib/%CLASS%.js; @echo $@
    |\t@cp $(CODE_ROOT)/%MODULE%/lib/%CLASS%.js public/j/%CLASS%.js
    |"""

var listDepText = "public/j/%CLASS%.js"

sender help

    CON::log('tml-build {compile|test} comment')
    ;

-- TYPES --;

type Module

    vars parts;
    @pkg = require(con process.cwd() '/package.json')
    @prevVer = @pkg.version
    @ver = scan @prevVer /^(\d+)[.](\d+)[.](\d+)(?:[-](\d+))?/
    shift @ver
    coalesce= @ver[3] 0;
    @moduleName = @pkg.name
    @className = @pkg.tml.className
    each @ver as part
        @ver[part_i] = as-numeric part;
    ;

method increment part# -> this

    enforce le part 3 ERR-VER.100(part)
    inc @ver[part]
    inc part
    count part to 3 as i
        @ver[i]=0;
    ;

method incrementBuild cb& -> this

    @increment(3) cb();

method incrementPatch cb& -> this

    @increment(2) cb();

method incrementMinor cb& -> this

    @increment(1) cb();

method incrementMajor cb& -> this

    @increment(0) cb();

method getVersion -> $

    =(con @ver[0] '.' @ver[1] '.' @ver[2] '-' @ver[3]);

method updateMakefile cb& -> this

    vars body=makefileBody
        make_web_deps=''
        webDepList=[]
        depCopy
        depParts
        depModule
        depClass
        f = new IO::FilePath('Makefile');

    replace= body /%MANUAL%/g @getManual()
    replace= body /%ORGANIZATION%/g @getOrganization()
    replace= body /%MODULE%/g @getModule()
    replace= body /%CLASS%/g @getClass()

    each @getWebDependencies() as dep
        depParts = split dep /[\&slash;]/
        if eq item-count depParts 1
            depClass = depParts[0]
            depModule = con 'tml-' lower-case depClass;
        else
            (depModule,depClass)=depParts;

        depCopy = copyDepText
        replace= depCopy /%MODULE%/g depModule
        replace= depCopy /%CLASS%/g depClass
        con= make_web_deps depCopy;

        depCopy = listDepText
        replace= depCopy /%CLASS%/g depClass
        push webDepList depCopy;

        ;

    replace= body /%WEB_DEPS%/ (join webDepList ' ')
    replace= body /%MAKE_WEB_DEPS%/ make_web_deps

    f.setText(body).write(cb)
    ;

method update cmt$ cb& -> this

    @updatePackageJson(
        func @updateSource(cmt,
            func @updateMakefile(func cb(););
            );
        );

method updateSource cmt$ cb& -> this

    vars f = new IO::FilePath(con './src/' @getClass() '.tml')
         histLine="\n        @history ";
    con= histLine
         INF-HIST(CORE::getDate(),'EMP',@getVersion(),cmt)
         ";\n\n#resources"
         ;
    f.read(
        func e? opt t$
            enforce nullval e (con 'Unable to read source file (' f.asString() ')')
            replace= t /{con 'version ' @prevVer}/ (con 'version ' @getVersion())
            replace= t /[\n]{2}[#]resources/ histLine
            f.setText(t)
            f.write(cb)
        ;)
    ;

method updatePackageJson cb& -> this

    vars f = new IO::FilePath('package.json');
    f.read(
        func e? opt t$
            enforce nullval e (con 'Unable to read package.json (' e ')')
            f.setText(replace t /{con '"version": "' @prevVer '"'}/g 
                (con '"version": "' @getVersion() '"'))
            f.write(cb)
        ;);

method getManual -> $ = @pkg.tml.manual;

method getOrganization -> $ = @pkg.tml.organization;

method getModule -> $ = @moduleName;

method getClass -> $ = @className;

method getWebDependencies -> * = @pkg.tml.webDependencies;


-- TESTS --;


-- ACTIONS --;

action Main

    vars node=shift args
         op=shift args
         changeComment=shift args
         module = new Module()
         update = func module.update(changeComment,
            func EXEC.spawn('make',
                [],{ stdio: 'inherit', detached: true }););
         ;
    CON::log(con node ' ' op)
    when op
        "build" then
            module.incrementBuild(update);
        "patch" then
            module.incrementPatch(update);
        "minor" then
            module.incrementMinor(update);
        "major" then
            module.incrementMajor(update);
        else
            help()
    ;;
npm loves you