Exemplo n.º 1
0
        function _defaultvalues(validateItems) {

            var idx= 0, size=validateItems.length,
                item;

            if (!defaultValue || (defaultValue && _typedas.isArray(defaultValue) && defaultValue.length === 0)) {
                return;
            }

            for (; idx<size; idx++) {
                item = validateItems[idx];
                if (_typedas.isArray(defaultValue)) {
                    if (_jsutils.Object.contains(defaultValue, item)) {
                        defaultValue.splice(defaultValue.indexOf(item), 1);
                    }
                } else {
                    if (item === defaultValue) {
                        return undefined;
                    }
                }
            };

            if (_typedas.isArray(defaultValue)) {
                if (defaultValue.length > 0) {
                    values = values.concat(defaultValue);
                }
            } else {
                values.push(defaultValue);
            }
        }
Exemplo n.º 2
0
        copyObjProps: function (srcObj, destObj, override) {

            var name, obj,
                me = this,
                idx = 0, size = 0, item;

            override = (override || false);

            if (srcObj && destObj) {
                for (name in srcObj) {

                    if (srcObj.hasOwnProperty(name)) {

                        obj = destObj[name];

                        if (_typedas.isObject(srcObj[name])) {
                            if (!destObj[name]) {
                                destObj[name] = {};
                            }
                            arguments.callee.call(me, srcObj[name], destObj[name], override);

                        } else if (_typedas.isArray(srcObj[name])) {

                            if (!obj) {
                                destObj[name] = srcObj[name];

                            } else if (_typedas.isArray(obj)) {

                                me.cleanupArray(srcObj[name]);
                                if (override) {
                                    destObj[name] = srcObj[name];

                                } else {
                                    size = destObj[name].length;
                                    for (idx = 0; idx < size; idx++) {
                                        item = obj[idx];
                                        srcObj[name] = me.removeArrayItemByValue(srcObj[name], item);
                                    }
                                    destObj[name] = destObj[name].concat(srcObj[name]);
                                }
                            } else {
                                _log.warning(_props.get("cat.utils.copy.object.array.warn").format("[utils copy object]", name, typeof(obj)));
                            }

                        } else {
                            if (override || obj === undefined) {
                                if (!destObj[name] || (destObj[name] && override)) {
                                    destObj[name] = srcObj[name];
                                }
                            }
                        }

                    }
                }
            }
        },
Exemplo n.º 3
0
        spawn: function(config, init, callback) {

            var me = this;

            // first initialize
            if (init) {
                this.init(init);
            }

            logger.log2file("\n\n************ Package Script  ************************************* process id: " + process.pid);

            if (config && typedas.isArray(config)) {
                commands = commands.concat(config);
                size = commands.length;
                if (size > 0) {
                    install(commands, function() {
                        logger.logall("[package-script] process completed, see pkgscript.log for more information");
                        if (callback) {
                            callback.call(me);
                        }
                    });
                }

            } else {
                logger.logall("[package-script] No valid configuration for 'install' function, see the docs for more information ");
            }
        },
Exemplo n.º 4
0
        globmatch: function(config) {

            var lsrc, match,
                src = config.src,
                opt = ("opt" in config ? config.opt : {});

            function __match(item, opt) {
                var match = _globmatch.sync(item, opt);
                if (!match) {
                    console.warn("[CAT libraries install] Failed match path: ", item, " , skip");
                }

                return match;
            }

            if (src) {
                if (_typedas.isArray(src)) {
                    lsrc = [];
                    src.forEach(function (item) {
                        var match;

                        if (item) {
                            try {
                                match = __match(item, opt);
                                if (match  && match.length > 0) {
                                    lsrc = lsrc.concat(match);
                                } else {
                                    lsrc.push(item);
                                }

                            } catch (e) {
                                console.warn("[CAT libraries install] Failed to resolve path: ", item, "with errors: ", e);
                                lsrc.push(item);
                            }
                        }
                    });

                } else if (_typedas.isString(src)) {

                    try {
                        match = __match(src, opt);
                        if (match && match.length > 0) {
                            lsrc = match;
                        } else {
                            lsrc = [src];
                        }

                    } catch (e) {
                        console.warn(" Failed to resolve path: ", src, "with errors: ", e);
                        lsrc = src;
                    }
                }
            }

            return lsrc;


        },
Exemplo n.º 5
0
_clazz.prototype.print = function (line) {
    if (line) {
        if (_typedas.isArray(line)) {
            this.output = this.output.concat(line);
        } else {
            this.output.push(line);
        }
    }
};
Exemplo n.º 6
0
    function _init(name, defaultValue) {
        var items,
            value,
            values=[];

        function _defaultvalues(validateItems) {

            var idx= 0, size=validateItems.length,
                item;

            if (!defaultValue || (defaultValue && _typedas.isArray(defaultValue) && defaultValue.length === 0)) {
                return;
            }

            for (; idx<size; idx++) {
                item = validateItems[idx];
                if (_typedas.isArray(defaultValue)) {
                    if (_jsutils.Object.contains(defaultValue, item)) {
                        defaultValue.splice(defaultValue.indexOf(item), 1);
                    }
                } else {
                    if (item === defaultValue) {
                        return undefined;
                    }
                }
            };

            if (_typedas.isArray(defaultValue)) {
                if (defaultValue.length > 0) {
                    values = values.concat(defaultValue);
                }
            } else {
                values.push(defaultValue);
            }
        }


        // set default values
        if (me.config[name] === undefined) {
            me.set(name, defaultValue);

        } else {
            items = me.config[name];
            if (_typedas.isArray(items)) {
                if (_ScrapConfigItem.instanceOf(items[0])) {
                    value = items[0].getValue();
                    _defaultvalues([value]);
                    values.push(value);
                } else {
                    _defaultvalues(items);
                    values = values.concat(items);
                }
                me.set(name, values);
            }
        }
    }
Exemplo n.º 7
0
_clazz.prototype.setCtxArguments = function (arr) {
    if (arr) {
        if (_typedas.isArray(arr)) {
            this.config.arguments = [];
            this.config.arguments = this.config.arguments.concat(arr);
            this.set("arguments",  _cleanObjectNoise(this.config.arguments));

        } else {
            _log.warning(_props.get("cat.arguments.type").format("[scrap class (addCtxArguments)]", "array"));
        }
    }
};
Exemplo n.º 8
0
        cleanupArray: function (arr) {
            var newArr = [];

            if (arr && _typedas.isArray(arr)) {
                arr.forEach(function (item) {
                    if (item !== null && item !== undefined) {
                        newArr.push(item);
                    }
                });
            }

            return newArr;
        },
Exemplo n.º 9
0
                        apply: function (line) {
                            var me = this,
                                currentLine,
                                counter= 0,
                                delta, idx=0, test;

                            if (action && line) {

                                // if the line registered add it
                                if (_jsutils.Object.contains(this.rows, line.row)) {
                                    this.lines.push(line.line);
                                    //this.$linesmap[line.row] = this.lines[this.lines.length-1];

                                    if (this.rows.indexOf(line.row) === this.rows.length-1) {
                                        // if this is the last cell...
                                        this.newlines =  action.call({}, this.lines, line.mark);
                                        if (this.newlines && _typedas.isArray(this.newlines)) {

                                            this.newlines.forEach(function(newline) {
                                                me.$linesmap[me.rows[counter]] = newline;
                                                counter++;
                                            });

                                            delta =  (this.rows.length - this.newlines.length);
                                            if (delta !== 0) {
                                                for (idx=counter; idx<delta; idx++) {
                                                    me.$linesmap[me.rows[idx]] = "\r\n";
                                                }
                                            }

                                        } else {
                                            _log.warning("[CAT ScrapItem] While invoking 'replace' implementation: '" + action + "', No valid return value of type Array was found");
                                        }
                                        this.$ready = 1;

                                    }
                                }

                                // after done processing the lines, replace the involved lines.
                                if (this.$ready === 1) {
                                    // if we have processed all rows...
                                    currentLine = line.row-1;
                                    if ( (currentLine) === (line.lines.length)) {
                                        test = this.$linesmap[currentLine];
                                        if (test || test === null) {
                                            line.lines[currentLine-1] =  ( (test || "") + ( (test && test.indexOf("\n") === -1) ? "\n" : "") );
                                        }
                                    }
                                }
                            }
                        }
Exemplo n.º 10
0
            _packageProcess(configvar, function() {
                if (this.data && typedas.isArray(this.data) && this.data.length > 0) {
                    me.spawn(this.data, init, function(){
                        if (callback) {
                            callback.call(me);
                        }
                    });
                } else {
                    if (callback) {
                        callback.call(me);
                    }

                }
            });
Exemplo n.º 11
0
        putScrapConfig: function(config, configKey, configVal, idx) {
                
            if (configKey) {
                configKey = configKey.trim();
                if (!config[configKey]) {
                    if (_typedas.isArray(configVal)) {
                        config[configKey] = configVal;
                    } else {
                        config[configKey] = [configVal];
                    }
                    
                    config.stack.push({ key: configKey, cell: (config[configKey] ? config[configKey].length-1 : 0) })
                } else {
                    if (_typedas.isArray(configVal)) {
                        config[configKey] = config[configKey].concat(configVal);
                    } else {
                        config[configKey].push(configVal);
                    }
                    config.stack.push({ key: configKey, cell: config[configKey].length-1})
                }
            }

        },
Exemplo n.º 12
0
        prepareCode: function (codeRows) {
            var row,
                nextText,

                size = (codeRows && _typedas.isArray(codeRows) ? codeRows.length : 0), idx = 0;

            function _row(row, ref, idx) {
                var rowTrimmed;

                if (row) {
                    rowTrimmed = (row.trim ? row.trim() : row);
                    if (rowTrimmed.charAt(rowTrimmed.length - 1) !== ";") {
                        if (idx !== undefined) {
                            ref[idx] += ";";
                        } else {
                            ref += ";"
                        }
                    }

                    if (idx !== undefined) {
                        ref[idx] = convertTestDataRexp(ref[idx]);
                    } else {
                        ref = convertTestDataRexp(ref);
                    }

                }
                return ref;
            }

            function convertTestDataRexp(codeRows) {
                var patt;

                patt = new RegExp("(.*)@d\\.([a-z]*\\()\\.(.*)(\\).*\\).*)","g");

                while (codeRows.match(patt)) {
                    codeRows = codeRows.replace(patt, "$1_cat.utils.TestsDB.$2'.$3'$4");
                }
                return codeRows;
            }

            if (size) {
                for (; idx < size; idx++) {
                    row = codeRows[idx];
                    codeRows = _row(row, codeRows, idx);
                }
            } else {
                codeRows = _row(codeRows, codeRows);
            }
            return codeRows;
        },
Exemplo n.º 13
0
            this.apply = function (internalConfig) {
                var actionsExists = (me.actions && _typedas.isArray(me.actions) ? true : false);

                if (!me.actions) {
                    _log.warning("[CAT] No actions for task: " + this.name);

                } else {

                    // apply all actions
                    if (actionsExists) {
                        _actionApply(internalConfig);
                    }

                }
            };
Exemplo n.º 14
0
        removeArrayItemByIdx: function (arr, idx) {
            var newArr = [],
                counter = 0;

            if (arr && _typedas.isArray(arr)) {

                arr.forEach(function (item) {
                    if (idx !== counter) {
                        newArr.push(item);
                    }
                    counter++;
                });
            }
            return newArr;
        },
Exemplo n.º 15
0
                    _parsers["Comment"].parse({file: file, callback: function (comments) {

                        var scrapComment,
                            scrap, scraps, scrapObjs=[],
                            size = 0, idx = 0;

                        if (comments && _typedas.isArray(comments)) {

                            scraps = _extractValidScrapRoot(comments);
                            if (scraps && _typedas.isArray(scraps) && scraps.length > 0) {
                                size = scraps.length;
                                for (idx = 0; idx < size; idx++) {
                                    scrapComment = scraps[idx];
                                    scrap = _Scrap.create({
                                        file: file,
                                        scrapComment: scrapComment
                                    });

                                    if (scrap) {
                                        scrapObjs.push(scrap);

                                        _Scrap.apply({
                                            basePath: _basePath,
                                            scraps: [scrap],
                                            apply: true
                                        });
                                    }
                                }
                                _Scrap.normalize(scrapObjs);
                            }

                        }

                        _emitter.emit("job.scrap.wait", {status: "wait"});

                    }});
Exemplo n.º 16
0
        removeArrayItemByValue: function (arr, value) {
            var newArr = [],
                counter = 0;

            if (arr && _typedas.isArray(arr)) {

                arr.forEach(function (item) {
                    if (item !== value && item !== null && item !== undefined) {
                        newArr.push(item);
                    }
                    counter++;
                });
            }

            return newArr;
        },
Exemplo n.º 17
0
function _cleanObjectNoise(obj) {

    function _cleanStringNoise(obj) {
        if (!obj) {
            return obj;
        }
        obj = (obj.indexOf("\r") !== -1 ? obj.split("\r").join("") : obj);
        obj = (obj.indexOf("\n") !== -1 ? obj.split("\n").join("") : obj);
        obj = (obj.indexOf("\t") !== -1 ? obj.split("\t").join("    ") : obj);

        return obj;
    }

    var idx = 0, size = 0, item, value;

    if (obj) {
        if (_typedas.isString(obj)) {

            return _cleanStringNoise(obj);

        } else if (_typedas.isArray(obj)) {

            size = obj.length;
            for (idx = 0; idx < size; idx++) {
                item = obj[idx];
                if (item) {
                    if (_ScrapConfigItem.instanceOf(item)) {
                        item = _ScrapConfigItem.create(item.config);
                        value = item.getValue();
                    } else {
                        value = item;
                    }
                    obj[idx] = _cleanStringNoise(value);
                }
            }

            return obj;
        }

    }

    return obj;
}
Exemplo n.º 18
0
_clazz.prototype.addConfig = function (arr, key) {

    if (arr && _typedas.isArray(arr)) {

        arr.forEach(function(item) {

            if (item && item.key && (typeof(item.value) !== 'undefined')) {

                this.config[key][item.key] = item.value;

            } else {
                _log.warning(_props.get("cat.scrap.single.properties").format("[scrap class (addSingle)]"));
            }

        });

    } else {
        _log.warning(_props.get("cat.arguments.type").format("[scrap class (addSingle)]", "array"));
    }
};
Exemplo n.º 19
0
        proto.validate = function(ref, data) {

            var plugindata,
                action;

            if (ref) {
                action = ref.action;
                plugindata = ( (action && action.validate) ? action.validate() : undefined );

                // validate runnable data with the plugin's data
                if (plugindata && data) {
                    if (("dependencies" in plugindata) && plugindata.dependencies) {
                        if (!_typedas.isArray(plugindata.dependencies)) {
                            _log.info("[CAT base plugin] returned property 'dependencies' of validate method should be of Array type");
                        } else {
                            if (("dependency" in data) ) {

                                if (_jsutilsobj.contains(plugindata.dependencies, data.dependency)) {

                                    // todo in case of other validation types collect the boolean values accordingly
                                    return true;

                                } else {

                                    _log.warning("[CAT base plugin] The current running dependency is: " + data.dependency +
                                        " that is not supported for the plugin named: " + ref.name +
                                        " that supports the following: " + plugindata.dependencies
                                    );
                                    return false;
                                }

                            }
                        }
                    }
                }
            } else {
                _log.info("[CAT base plugin] No plugin validation has implemented.");
            }

            return true;
        };
Exemplo n.º 20
0
    /**
     * Extract valid main scrap blocks out of comments
     *
     * @param comments
     * @private
     */
    function _extractValidScrapRoot(comments) {

        var gidx = 0, gsize, blockComment,
            scrap = [], extractedScraps;

        if (comments && _typedas.isArray(comments)) {

            gsize = comments.length;
            for (; gidx < gsize; gidx++) {

                blockComment = comments[gidx];
                if (blockComment) {
                    extractedScraps = _Scrap.extractScrapBlock(blockComment);
                    if (extractedScraps && extractedScraps.length > 0) {
                        scrap = scrap.concat(extractedScraps);
                    }
                }
            }
        }

        return scrap;
    }
Exemplo n.º 21
0
    function _getValue(key) {

        var size,
            value = me.config[key];

        if (value) {

            value = _cleanObjectNoise(value);
            if (value !== undefined && value !== null) {
                if (me.isSingle(key) || _utils.contains(_scrapEnum.scrapEnum.singleTypes, key)) {
                    // return only the first cell since we types this key as a single scrap value (the last cell takes)
                    if (_typedas.isArray(value)) {
                        _utils.cleanupArray(value);
                        size = value.length;
                        return value[size - 1];
                    } else {
                        // return value as is
                    }
                }
            }
        }
        return value;
    }
Exemplo n.º 22
0
        init: function (config) {


            var project = (config.internalConfig ? config.internalConfig.getProject() : undefined),
                imports,
                action,
                wipe = false,
                extensionParams,
                errors = ["[libraries plugin] No valid configuration"],
                catProjectLib,
                catProjectSrc,
                manifestLib,
                library, manifestMode,
                manifestDetails,
                workPath,
                libWorkPath,
                manifest = project.getManifest(),
                libraries,
                slot = 0;                                 
            

            function _copyResource() {


                if (!catProjectLib) {
                    _log.error(_props.get("cat.error.config.missing").format("[libraries ext]", "lib"));
                    return undefined;
                }
                var from,
                    artifact = library[manifestMode];

                /**
                 * Copy resource synchronously
                 *
                 * @param item The artifact file name
                 * @param base The base path
                 * @private
                 */
                function _copy(base, item) {

                    function _getExtension(filename) {
                        var ext = _path.extname(filename||'').split('.');
                        return ext[ext.length - 1];
                    }

                    function _getFileName(filename, name) {
                        var file = _path.basename(filename),
                            value;
                        
                        value = _path.join(name, file);
                        
                        return value;
                    }

                    var content, filetype, filename, basename,
                        itemName,
                        staticnames = ('static-names' in library ? library["static-names"] : undefined);


                    // copy the library to the current cat project
                    try {
                        // copy dev
                        if (item) {

                            itemName = (_typedas.isObject(item) && ("name" in item) ? item.name : item);
                            from = (base ? _path.join(libWorkPath, base, itemName) : _path.join(libWorkPath, itemName));

                            /* Copy all of the artifacts to the project's library
                                to = _path.join(catProjectLib, item);
                                _utils.copySync(from, to); */

                            // concatenation
                            content = _fs.readFileSync(from, "utf8");
                            if (content) {

                                filetype = _getExtension(from);
                                filename = _getFileName(from, library.name);
                                basename = _path.basename(from);

                                if (filetype) {
                                    //concatenated.add(filetype, content);
                                    concatenated.add(filename, content);
                                    if (_jsutils.Object.contains(staticnames, basename)) {
                                        concatenated.putName(filename, basename);
                                    }
                                }
                            }


                        } else {
                            _log.warning(_props.get("cat.plugin.libraries.config.missing").format("[libraries ext]", library.name));
                        }
                    } catch (e) {
                        _log.error(_props.get("cat.file.copy.failed").format("[libraries]", from, e));
                    }
                }

                if (artifact && _typedas.isArray(artifact)) {
                    artifact.forEach(function (item) {
                        // copy artifacts
                        _copy((library.base || undefined), item);
                    });
                }
            }

            function _exec() {

                var actions = {},
                    process1,
                    targetManifestPath = _path.join(catProjectLib, manifest.getFileName()),
                    doImport = false,
                    concatsByType;

                function _copydone() {

                    _copyResource();
                    _exec();

                }

                library = libraries[slot];


                if (imports && imports.length > 0 && library){
                    if (_typedas.isArray(imports)) {
                        doImport = _catlibrary.exists(imports, library.name);
                    } else {
                        // we are installing all libraries ignore the import stuff
                        doImport = true;
                    }
                }

                libWorkPath = (library ? _path.join(workPath, library.name) : undefined);

                // copy the manifest file
                try {
                    manifestLib = manifest.getFilePath();
                    if (_fs.existsSync(manifestLib) && _fs.existsSync(targetManifestPath)) {
                        _utils.copySync(manifestLib, targetManifestPath);
                    }
                } catch (e) {
                    _log.error(_props.get("cat.file.copy.failed").format("[libraries]", targetManifestPath, e));
                }

                actions.install = function () {

                    var bowerConfig = {cwd: workPath};

                    function _installLibs(lib, mode) {

                        function __installLib(data) {

                            if (!data) {
                                return undefined;
                            }

                            var src = data.src,
                                type = data.type,
                                path = data.path,
                                name = data.name,
                                funcs = {
                                    "_baseCopy": function(config) {
                                        var src = config.src,
                                            path = config.path,
                                            name = config.name,
                                            content = config.content;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                if (item) {
                                                    _utils.copySync(item, _path.join(path, name));
                                                }
                                            });
                                        } else if (content) {
                                            _fs.writeFileSync(_path.join(path, name), content);
                                        }
                                    },

                                    "json": function(config) {

                                        var parse = ('parse' in config ? config.parse : undefined),
                                            src = "src" in config && config.src,
                                            path = config.path,
                                            name = config.name;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                var content;

                                                if (item) {
                                                    content = _fs.readFileSync(item, "utf8");
                                                    if (content) {
                                                        funcs._baseCopy({
                                                            content: content,
                                                            name: name,
                                                            path: path
                                                        });
                                                    }
                                                }
                                            });
                                        }
                                    },

                                    "css": function(config) {

                                        funcs._baseCopy(config);
                                    },

                                    "js" : function(config) {

                                        var src = config.src,
                                            path = config.path,
                                            name = config.name;

                                        jsutils.dev({
                                            src: src,
                                            out:{
                                                name: name,
                                                path: path
                                            },
                                            jshint: {
                                                opt: {
                                                    "evil": true,
                                                    "strict": false,
                                                    "curly": true,
                                                    "eqeqeq": true,
                                                    "immed": false,
                                                    "latedef": true,
                                                    "newcap": false,
                                                    "noarg": true,
                                                    "sub": true,
                                                    "undef": true,
                                                    "boss": true,
                                                    "eqnull": true,
                                                    "node": true,
                                                    "es5": false
                                                },
                                                "globals": {
                                                    XMLHttpRequest: true,
                                                    document: true,
                                                    _cat: true,
                                                    _catjs: true,
                                                    $ : true,
                                                    Q : true,
                                                    q : true,
                                                    jQuery : true,
                                                    Ext : true,
                                                    window : true,
                                                    chai: true,
                                                    phantom: true,
                                                    JSPath: true,
                                                    flyer : true,
                                                    angular : true,
                                                    html2canvas: true,
                                                    canvg: true,
                                                    jsutilsObject: true,
                                                    jsutilsArray: true,
                                                    resemble: true
                                                }
                                            }
                                        });
                                    }
                                };

                            if (!src || !type || !path || !name) {
                                _log.error("[CAT libraries install] Not valid argument(s) 'src' / 'type' / 'path' / 'name' ");
                            }

                            resolvedSrcs = [];
                            src.forEach(function(item) {
                                resolvedSrcs.push(_path.join(libWorkPath, item));
                            });

                            data.src = resolvedSrcs;
                            funcs[type].call(this, data);


                        }

                        var jsutils = _jsutils.Task,
                            src,
                            resolvedSrcs = [],
                            targetPath = library.base,
                            libData;

                        // init
                        // TODO TBD ... DEV is hard coded
                        if (mode in library && library[mode]) {
                            libData = library[mode];
                            targetPath = _path.join(libWorkPath, targetPath);
                            if (targetPath) {
                                // create internal project library folder if not exists
                                if (!_fs.existsSync(targetPath)) {
                                    _fs.mkdirpSync(targetPath);
                                }
                            }

                            if (_typedas.isArray(libData)) {
                                libData.forEach(function(data) {
                                    data.path = targetPath;
                                    __installLib(data);
                                });

                                _copydone();

                            } else {
                                _log.error("[CAT libraries install] library's dev property should be of 'Array' type");

                            }
                        }

                    }

                    if (library.install === "static") {

                        _copydone();


                    } else if (library.install === "internal") {

                         _installLibs(library, "dev");


                    } else if (library.install === "bower") {

                        if (!_utils.isWindows()) {
                            if (_bower) {
                                _bower.commands.install([library.name], {}, bowerConfig)
                                    .on('end', function (installed) {
                                        _log.info('[bower] library ' + library.name + ' Installed');
                                        _copydone();
                                    });
                            } else {
                                _utils.log("[catjs bower] No bower support");
                            }
                        } else {

                            /* on windows we have an issue related to git <> bower
                             thus we are running custom spawn
                             */
                            process1 = _spawn().spawn({
                                command: "bowerutils.bat",
                                args: ["install", library.name],
                                options: bowerConfig,
                                emitter: _emitter
                            });

                            process1.on('close', function (code) {
                                if (code !== 0) {
                                    _log.info('[spawn close] exited with code ' + code);
                                } else {
                                    _log.info('[bower] library ' + library.name + ' Installed');
                                    _copydone();
                                }
                            });
                        }
                    }
                };


                actions.clean = function () {
                    var path = library.base;

                    if (library.install === "internal") {
                        path = _path.join(libWorkPath, path);
                        _utils.deleteSync(path);
                        _exec();
                    } else if (library.install === "bower") {
                        _utils.deleteSync(_path.join(workPath, library.name));
                        _exec();
                    }
                };


                actions.build = function() {
                    _copydone();
                };

                slot++;
                if (slot > libraries.length) {

                    // create project's library folder if not exists
                    if (!_fs.existsSync(catProjectLib)) {
                        _fs.mkdirSync(catProjectLib);
                    }

                    // concat artifact files
                    concatsByType = concatenated.all();

                    concatsByType.forEach(function(concatItem) {
                        var contentValue,
                            catProjectLibTarget,
                            filename, staticname,
                            // todo reflect the parse flag from the meta data file
                            parse = true,
                            catjsonpath,
                            targetfolder, targetfilename;

                        if (concatItem) {
                            if (concatItem.value.length > 0) {
                                catProjectLibTarget = catProjectLib;


                                staticname = concatenated.getName(concatItem.key);
                                contentValue = concatItem.value.join("");
                                // set the static name if found or else generate the name according to the project env
                                filename = (staticname ? staticname : [concatItem.key].join(""));

                                if (concatItem.key === _path.normalize("cat/cat.json")) {
                                    // parse content..
                                    if (parse) {
                                        _jsutils.Template.setMustache(true);
                                        contentValue = _jsutils.Template.template({
                                            content: contentValue,
                                            data: {
                                                project: project
                                            }
                                        });
                                    }
                                }
                                // specific condition for cat.json TODO put a generic property
                                if ( concatItem.key !== _path.normalize("cat/cat.json") ) {
                                    targetfilename = _path.normalize(_path.join(catProjectLibTarget, filename));
                                    targetfolder = _path.dirname(targetfilename);
                                    _utils.mkdirSync(targetfolder);
                                    _fs.writeFileSync(targetfilename, contentValue);

                                } else {                                    
                                    if (concatItem.key === _path.normalize("cat/cat.json")) {
                                        catjsonpath = _path.normalize(_path.join(catProjectSrc, "/config/cat.json"));
                                        if (!_fs.existsSync(catjsonpath)) {
                                            _fs.writeFileSync(catjsonpath, contentValue);
                                        }                                        
                                    }
                                }

                            }
                        }
                    });

                    if (_emitter) {
                        _emitter.emit("job.done", {status: "done"});
                    }

                    return undefined;
                }

                if ( doImport && actions[action]) {
                    actions[action].call(this);
                } else {
                    _exec();
                }

            }

            if (!config) {
                _log.error(errors[1]);
                _me.setDisabled(true);
            }

            _emitter = config.emitter;
            _global = config.global;
            _data = config.data;
            _internalConfig = config.internalConfig;
            _project = (_internalConfig ? _internalConfig.getProject() : undefined);

            // initial data binding to 'this'
            _me.dataInit(_data);
            extensionParams = _data.data;

            imports = extensionParams.imports;
            action = extensionParams.action;
            wipe = ((extensionParams.wipe === "true") ? true : false);

            if (imports) {
                imports = _catlibrary.all(imports) ;
                
            }
            
            if (config && extensionParams) {

                // prepare libraries
                if (manifest) {
                   
                    libraries = manifest.getLibraries();
                    manifestMode = manifest.getMode();
                    manifestDetails = manifest.getDetails();

                    if (_project) {
                        catProjectSrc = _project.getInfo("source");
                        if (manifestDetails) {
                            catProjectLib = manifestDetails.folder;
                        }

                        workPath = _path.join(cathome, _project.getInfo("libraries").path);
                    }

                    if (libraries &&
                        _typedas.isArray(libraries)) {

                        if (libraries.length > 0) {
                            _exec();
                        }
                    }
                }

            }
        },
Exemplo n.º 23
0
                    function _installLibs(lib, mode) {

                        function __installLib(data) {

                            if (!data) {
                                return undefined;
                            }

                            var src = data.src,
                                type = data.type,
                                path = data.path,
                                name = data.name,
                                funcs = {
                                    "_baseCopy": function(config) {
                                        var src = config.src,
                                            path = config.path,
                                            name = config.name,
                                            content = config.content;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                if (item) {
                                                    _utils.copySync(item, _path.join(path, name));
                                                }
                                            });
                                        } else if (content) {
                                            _fs.writeFileSync(_path.join(path, name), content);
                                        }
                                    },

                                    "json": function(config) {

                                        var parse = ('parse' in config ? config.parse : undefined),
                                            src = "src" in config && config.src,
                                            path = config.path,
                                            name = config.name;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                var content;

                                                if (item) {
                                                    content = _fs.readFileSync(item, "utf8");
                                                    if (content) {
                                                        funcs._baseCopy({
                                                            content: content,
                                                            name: name,
                                                            path: path
                                                        });
                                                    }
                                                }
                                            });
                                        }
                                    },

                                    "css": function(config) {

                                        funcs._baseCopy(config);
                                    },

                                    "js" : function(config) {

                                        var src = config.src,
                                            path = config.path,
                                            name = config.name;

                                        jsutils.dev({
                                            src: src,
                                            out:{
                                                name: name,
                                                path: path
                                            },
                                            jshint: {
                                                opt: {
                                                    "evil": true,
                                                    "strict": false,
                                                    "curly": true,
                                                    "eqeqeq": true,
                                                    "immed": false,
                                                    "latedef": true,
                                                    "newcap": false,
                                                    "noarg": true,
                                                    "sub": true,
                                                    "undef": true,
                                                    "boss": true,
                                                    "eqnull": true,
                                                    "node": true,
                                                    "es5": false
                                                },
                                                "globals": {
                                                    XMLHttpRequest: true,
                                                    document: true,
                                                    _cat: true,
                                                    _catjs: true,
                                                    $ : true,
                                                    Q : true,
                                                    q : true,
                                                    jQuery : true,
                                                    Ext : true,
                                                    window : true,
                                                    chai: true,
                                                    phantom: true,
                                                    JSPath: true,
                                                    flyer : true,
                                                    angular : true,
                                                    html2canvas: true,
                                                    canvg: true,
                                                    jsutilsObject: true,
                                                    jsutilsArray: true,
                                                    resemble: true
                                                }
                                            }
                                        });
                                    }
                                };

                            if (!src || !type || !path || !name) {
                                _log.error("[CAT libraries install] Not valid argument(s) 'src' / 'type' / 'path' / 'name' ");
                            }

                            resolvedSrcs = [];
                            src.forEach(function(item) {
                                resolvedSrcs.push(_path.join(libWorkPath, item));
                            });

                            data.src = resolvedSrcs;
                            funcs[type].call(this, data);


                        }

                        var jsutils = _jsutils.Task,
                            src,
                            resolvedSrcs = [],
                            targetPath = library.base,
                            libData;

                        // init
                        // TODO TBD ... DEV is hard coded
                        if (mode in library && library[mode]) {
                            libData = library[mode];
                            targetPath = _path.join(libWorkPath, targetPath);
                            if (targetPath) {
                                // create internal project library folder if not exists
                                if (!_fs.existsSync(targetPath)) {
                                    _fs.mkdirpSync(targetPath);
                                }
                            }

                            if (_typedas.isArray(libData)) {
                                libData.forEach(function(data) {
                                    data.path = targetPath;
                                    __installLib(data);
                                });

                                _copydone();

                            } else {
                                _log.error("[CAT libraries install] library's dev property should be of 'Array' type");

                            }
                        }

                    }
Exemplo n.º 24
0
            function _exec() {

                var actions = {},
                    process1,
                    targetManifestPath = _path.join(catProjectLib, manifest.getFileName()),
                    doImport = false,
                    concatsByType;

                function _copydone() {

                    _copyResource();
                    _exec();

                }

                library = libraries[slot];


                if (imports && imports.length > 0 && library){
                    if (_typedas.isArray(imports)) {
                        doImport = _catlibrary.exists(imports, library.name);
                    } else {
                        // we are installing all libraries ignore the import stuff
                        doImport = true;
                    }
                }

                libWorkPath = (library ? _path.join(workPath, library.name) : undefined);

                // copy the manifest file
                try {
                    manifestLib = manifest.getFilePath();
                    if (_fs.existsSync(manifestLib) && _fs.existsSync(targetManifestPath)) {
                        _utils.copySync(manifestLib, targetManifestPath);
                    }
                } catch (e) {
                    _log.error(_props.get("cat.file.copy.failed").format("[libraries]", targetManifestPath, e));
                }

                actions.install = function () {

                    var bowerConfig = {cwd: workPath};

                    function _installLibs(lib, mode) {

                        function __installLib(data) {

                            if (!data) {
                                return undefined;
                            }

                            var src = data.src,
                                type = data.type,
                                path = data.path,
                                name = data.name,
                                funcs = {
                                    "_baseCopy": function(config) {
                                        var src = config.src,
                                            path = config.path,
                                            name = config.name,
                                            content = config.content;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                if (item) {
                                                    _utils.copySync(item, _path.join(path, name));
                                                }
                                            });
                                        } else if (content) {
                                            _fs.writeFileSync(_path.join(path, name), content);
                                        }
                                    },

                                    "json": function(config) {

                                        var parse = ('parse' in config ? config.parse : undefined),
                                            src = "src" in config && config.src,
                                            path = config.path,
                                            name = config.name;

                                        if (src) {
                                            src = _utils.globmatch({src: src});

                                            src.forEach(function(item) {
                                                var content;

                                                if (item) {
                                                    content = _fs.readFileSync(item, "utf8");
                                                    if (content) {
                                                        funcs._baseCopy({
                                                            content: content,
                                                            name: name,
                                                            path: path
                                                        });
                                                    }
                                                }
                                            });
                                        }
                                    },

                                    "css": function(config) {

                                        funcs._baseCopy(config);
                                    },

                                    "js" : function(config) {

                                        var src = config.src,
                                            path = config.path,
                                            name = config.name;

                                        jsutils.dev({
                                            src: src,
                                            out:{
                                                name: name,
                                                path: path
                                            },
                                            jshint: {
                                                opt: {
                                                    "evil": true,
                                                    "strict": false,
                                                    "curly": true,
                                                    "eqeqeq": true,
                                                    "immed": false,
                                                    "latedef": true,
                                                    "newcap": false,
                                                    "noarg": true,
                                                    "sub": true,
                                                    "undef": true,
                                                    "boss": true,
                                                    "eqnull": true,
                                                    "node": true,
                                                    "es5": false
                                                },
                                                "globals": {
                                                    XMLHttpRequest: true,
                                                    document: true,
                                                    _cat: true,
                                                    _catjs: true,
                                                    $ : true,
                                                    Q : true,
                                                    q : true,
                                                    jQuery : true,
                                                    Ext : true,
                                                    window : true,
                                                    chai: true,
                                                    phantom: true,
                                                    JSPath: true,
                                                    flyer : true,
                                                    angular : true,
                                                    html2canvas: true,
                                                    canvg: true,
                                                    jsutilsObject: true,
                                                    jsutilsArray: true,
                                                    resemble: true
                                                }
                                            }
                                        });
                                    }
                                };

                            if (!src || !type || !path || !name) {
                                _log.error("[CAT libraries install] Not valid argument(s) 'src' / 'type' / 'path' / 'name' ");
                            }

                            resolvedSrcs = [];
                            src.forEach(function(item) {
                                resolvedSrcs.push(_path.join(libWorkPath, item));
                            });

                            data.src = resolvedSrcs;
                            funcs[type].call(this, data);


                        }

                        var jsutils = _jsutils.Task,
                            src,
                            resolvedSrcs = [],
                            targetPath = library.base,
                            libData;

                        // init
                        // TODO TBD ... DEV is hard coded
                        if (mode in library && library[mode]) {
                            libData = library[mode];
                            targetPath = _path.join(libWorkPath, targetPath);
                            if (targetPath) {
                                // create internal project library folder if not exists
                                if (!_fs.existsSync(targetPath)) {
                                    _fs.mkdirpSync(targetPath);
                                }
                            }

                            if (_typedas.isArray(libData)) {
                                libData.forEach(function(data) {
                                    data.path = targetPath;
                                    __installLib(data);
                                });

                                _copydone();

                            } else {
                                _log.error("[CAT libraries install] library's dev property should be of 'Array' type");

                            }
                        }

                    }

                    if (library.install === "static") {

                        _copydone();


                    } else if (library.install === "internal") {

                         _installLibs(library, "dev");


                    } else if (library.install === "bower") {

                        if (!_utils.isWindows()) {
                            if (_bower) {
                                _bower.commands.install([library.name], {}, bowerConfig)
                                    .on('end', function (installed) {
                                        _log.info('[bower] library ' + library.name + ' Installed');
                                        _copydone();
                                    });
                            } else {
                                _utils.log("[catjs bower] No bower support");
                            }
                        } else {

                            /* on windows we have an issue related to git <> bower
                             thus we are running custom spawn
                             */
                            process1 = _spawn().spawn({
                                command: "bowerutils.bat",
                                args: ["install", library.name],
                                options: bowerConfig,
                                emitter: _emitter
                            });

                            process1.on('close', function (code) {
                                if (code !== 0) {
                                    _log.info('[spawn close] exited with code ' + code);
                                } else {
                                    _log.info('[bower] library ' + library.name + ' Installed');
                                    _copydone();
                                }
                            });
                        }
                    }
                };


                actions.clean = function () {
                    var path = library.base;

                    if (library.install === "internal") {
                        path = _path.join(libWorkPath, path);
                        _utils.deleteSync(path);
                        _exec();
                    } else if (library.install === "bower") {
                        _utils.deleteSync(_path.join(workPath, library.name));
                        _exec();
                    }
                };


                actions.build = function() {
                    _copydone();
                };

                slot++;
                if (slot > libraries.length) {

                    // create project's library folder if not exists
                    if (!_fs.existsSync(catProjectLib)) {
                        _fs.mkdirSync(catProjectLib);
                    }

                    // concat artifact files
                    concatsByType = concatenated.all();

                    concatsByType.forEach(function(concatItem) {
                        var contentValue,
                            catProjectLibTarget,
                            filename, staticname,
                            // todo reflect the parse flag from the meta data file
                            parse = true,
                            catjsonpath,
                            targetfolder, targetfilename;

                        if (concatItem) {
                            if (concatItem.value.length > 0) {
                                catProjectLibTarget = catProjectLib;


                                staticname = concatenated.getName(concatItem.key);
                                contentValue = concatItem.value.join("");
                                // set the static name if found or else generate the name according to the project env
                                filename = (staticname ? staticname : [concatItem.key].join(""));

                                if (concatItem.key === _path.normalize("cat/cat.json")) {
                                    // parse content..
                                    if (parse) {
                                        _jsutils.Template.setMustache(true);
                                        contentValue = _jsutils.Template.template({
                                            content: contentValue,
                                            data: {
                                                project: project
                                            }
                                        });
                                    }
                                }
                                // specific condition for cat.json TODO put a generic property
                                if ( concatItem.key !== _path.normalize("cat/cat.json") ) {
                                    targetfilename = _path.normalize(_path.join(catProjectLibTarget, filename));
                                    targetfolder = _path.dirname(targetfilename);
                                    _utils.mkdirSync(targetfolder);
                                    _fs.writeFileSync(targetfilename, contentValue);

                                } else {                                    
                                    if (concatItem.key === _path.normalize("cat/cat.json")) {
                                        catjsonpath = _path.normalize(_path.join(catProjectSrc, "/config/cat.json"));
                                        if (!_fs.existsSync(catjsonpath)) {
                                            _fs.writeFileSync(catjsonpath, contentValue);
                                        }                                        
                                    }
                                }

                            }
                        }
                    });

                    if (_emitter) {
                        _emitter.emit("job.done", {status: "done"});
                    }

                    return undefined;
                }

                if ( doImport && actions[action]) {
                    actions[action].call(this);
                } else {
                    _exec();
                }

            }
Exemplo n.º 25
0
            function _copyResource() {


                if (!catProjectLib) {
                    _log.error(_props.get("cat.error.config.missing").format("[libraries ext]", "lib"));
                    return undefined;
                }
                var from,
                    artifact = library[manifestMode];

                /**
                 * Copy resource synchronously
                 *
                 * @param item The artifact file name
                 * @param base The base path
                 * @private
                 */
                function _copy(base, item) {

                    function _getExtension(filename) {
                        var ext = _path.extname(filename||'').split('.');
                        return ext[ext.length - 1];
                    }

                    function _getFileName(filename, name) {
                        var file = _path.basename(filename),
                            value;
                        
                        value = _path.join(name, file);
                        
                        return value;
                    }

                    var content, filetype, filename, basename,
                        itemName,
                        staticnames = ('static-names' in library ? library["static-names"] : undefined);


                    // copy the library to the current cat project
                    try {
                        // copy dev
                        if (item) {

                            itemName = (_typedas.isObject(item) && ("name" in item) ? item.name : item);
                            from = (base ? _path.join(libWorkPath, base, itemName) : _path.join(libWorkPath, itemName));

                            /* Copy all of the artifacts to the project's library
                                to = _path.join(catProjectLib, item);
                                _utils.copySync(from, to); */

                            // concatenation
                            content = _fs.readFileSync(from, "utf8");
                            if (content) {

                                filetype = _getExtension(from);
                                filename = _getFileName(from, library.name);
                                basename = _path.basename(from);

                                if (filetype) {
                                    //concatenated.add(filetype, content);
                                    concatenated.add(filename, content);
                                    if (_jsutils.Object.contains(staticnames, basename)) {
                                        concatenated.putName(filename, basename);
                                    }
                                }
                            }


                        } else {
                            _log.warning(_props.get("cat.plugin.libraries.config.missing").format("[libraries ext]", library.name));
                        }
                    } catch (e) {
                        _log.error(_props.get("cat.file.copy.failed").format("[libraries]", from, e));
                    }
                }

                if (artifact && _typedas.isArray(artifact)) {
                    artifact.forEach(function (item) {
                        // copy artifacts
                        _copy((library.base || undefined), item);
                    });
                }
            }
Exemplo n.º 26
0
 _scrapEnum.scrapEnum.fileTypes.forEach(function(type){
     if (type === (_typedas.isArray(value) ? value[0] : value)) {
         // supported type
         validation[key] = true;
     }
 });
Exemplo n.º 27
0
        proto.applyFileExtFilters = function (filters, typeObj) {

            var exitCondition = 0,
                me = this;

            function patternMatch() {
                if (!this.pattern) {
                    return false;
                }
                var size = this.ext.length, idx = 0, item;

                for (; idx<size; idx++) {
                    item = this.pattern[idx];
                    if (_minimatch(typeObj, item, { matchBase: true })) {
                        return true;
                    }
                }
                return false;
            }

            function extMatch() {

                if (!this.ext) {
                    return undefined;
                }
                var extName = _path.extname(typeObj),
                    size = this.ext.length, idx = 0, item,
                    isPattern;

                for (; idx<size; idx++) {
                    item = this.ext[idx];
                    if ( (item === extName || item === "*") ) {

                        // take the parent into the condition
                        if (this.pattern) {
                            isPattern = patternMatch.call(this);
                            if (!isPattern) {
                                continue;
                            }
                        }

                        if (!this.exclude) {
                            exitCondition = 0;
                        } else {
                            exitCondition = 1;
                        }

                    }
                }
            }

            if (typeObj && filters && _typedas.isArray(filters)) {

                filters.forEach(function (filter) {
                    if (filter) {
                        filter.apply(function () {
                            extMatch.call(this);
                        });
                    }
                });

                if (exitCondition > 0) {
                    return true;
                }

            }

            return false;
        };
Exemplo n.º 28
0
     _CATConfig = function (externalConfig, data) {

        var me = this,
            idx = 0, size, project, pluginsPath = [],
            dependencies = [],
            librariesConfig = [],
            librariesDefault = ["chai", "jspath", "tmr", "cat"],
            libraryBuildConfig, dependenciesInfo,
            appTargetPath, appPath,
            scrapfilter, projectcopy,
            scrapscan, customPlugins,
            cattarget, targetfolder,
            libIdx= 0,
            rmIdx=-1;

        /**
         * Extension initialization
         *
         * @param ext
         * @private
         */
        function _extension(ext) {
            if (ext && ext.name) {

                ext.getPhase = function() {
                    return (ext.phase || "default");
                };
                me._extmap[ext.name] = {externalConfig: externalConfig, ext: ext, ref: null};
            }
        }

        this._extmap = {};
        this._watch = {};
        this.extensions = data.extensions;
        this.plugins = data.plugins;
        this.externalConfig = externalConfig;

        if (this.extensions) {

            if (_typedas.isArray(this.extensions)) {
                // Index the extensions entries
                size = this.extensions.length;
                for (; idx < size; idx++) {
                    _extension(this.extensions[idx]);
                }
            }

            // load CAT environment variables and update the project class
            this.env = data.env;
            if (this.externalConfig) {
                project = this.externalConfig.project;
                if (project) {

                    if (data && data.extensions) {
                        data.extensions.forEach(function(ext) {
                            if (ext && ext.name) {
                                dependencies.push({
                                    name: ext.name,
                                    type: ext.name
                                });
                            }
                        });
                        // add internal extensions info
                        project.appendEntity("dependencies", dependencies);
                    }

                    // set environment info
                    project.setInfo("template", this.env.template);
                    project.setInfo("libraries", this.env.libraries);
                    this.plugins.forEach(function(path){
                        pluginsPath.push(_path.join(cathome, path));
                    });
                    project.addPluginLocations(pluginsPath);

                    customPlugins = [];
                    librariesConfig = ["cat"];
                    targetfolder = project.getInfo("target");
                    cattarget = (project.getInfo("cattarget") || "./");

                    appTargetPath = _path.join("./", _path.relative(_path.resolve("."), targetfolder), project.name);
                    appPath = project.getInfo("apppath");

                    if (appPath) {
                        projectcopy= {
                            "name": "*****@*****.**",
                            "type": "copy",
                            "dependency": "scan",
                            "path": appPath,
                            "from": {
                                "path": "/"
                            },
                            "to": {
                                "path": appTargetPath
                            }
                        };
                        customPlugins.push(projectcopy);

                    } else  {
                        _log.log("error", "[CAT config] 'apppath property is missing or not valid. See catproject.json spec");
                    }

                    scrapscan =   {
                        "name": "*****@*****.**",
                        "type": "scrap",
                        "dependency": "scan"
                    };

                    scrapfilter = project.getInfo("scrapfilter");
                    if (scrapfilter) {
                        scrapscan.filters = scrapfilter;
                    }
                    customPlugins.push(scrapscan);

                    customPlugins = customPlugins.concat([
                        {
                            "name": "*****@*****.**",
                            "type": "copy",
                            "from": {
                                "path": "./lib"
                            },
                            "to": {
                                "path": _path.join(appTargetPath, cattarget, "/cat/lib")
                            }
                        },
                        {
                            "name": "*****@*****.**",
                            "type": "fileparse",
                            "dependency": "manager",
                            "files": [_path.join(appTargetPath, cattarget, "/cat/lib/cat.js")],
                            "pattern": "_getBase=\"(.*)\";",
                            "replace": "_getBase=\"" + cattarget + "\";",
                            "applyto":["content"],
                            "flags": "g"
                        },
                        {
                            "name": "*****@*****.**",
                            "type": "copy",
                            "from": {
                                "path": "./src/config"
                            },
                            "to": {
                                "path": _path.join(appTargetPath, cattarget, "/cat/config")
                            }
                        },
                        {
                            "name": "*****@*****.**",
                            "type": "minify",
                            "path": _path.join(appTargetPath, cattarget, "/cat/lib"),
                            "filename": "cat.src.js",
                            "src":["./src/**/*.js"]
                        }
                        ]);

                    dependenciesInfo = project.getInfo("dependencies");
                    if (!dependenciesInfo) {
                        librariesConfig = dependenciesInfo = librariesDefault;

                    } else {
                        librariesConfig = dependenciesInfo;
                        if (!librariesConfig || (!_typedas.isArray(librariesConfig))) {
                            librariesConfig = librariesDefault;

                        } else {
                            libIdx= 0;
                            rmIdx=-1;

                            librariesConfig.forEach(function(item) {
                                if (item === "cat") {
                                    rmIdx = libIdx;
                                }
                                libIdx++;
                            });

                            // remove "cat" if was found
                            if (rmIdx > -1) {
                                librariesConfig.splice(rmIdx, 1);
                            }

                            // set "cat" to be last
                            librariesConfig.push("cat");
                        }
                    }

                    librariesConfig.unshift("cat.css");
                    librariesConfig.push("cat.src.js");

                    project.setInfo("dependencies", librariesConfig);

                    libraryBuildConfig = {
                        "name": "*****@*****.**",
                        "type": "libraries",
                        "dependency": "manager",
                        "imports": librariesConfig,
                        "action": "build"
                    };
                    customPlugins.push(libraryBuildConfig);

                    project.appendEntity("plugins", customPlugins);


                } else {
                    _log.warning(_props.get("cat.project.env.failed").format("[CAT Config Loader]"));
                }
            }

        }
    };
Exemplo n.º 29
0
function _packageProcess(config, callback) {
    var configval = [],
        names = [],
        baseobj = {
            command: "npm",
            args: [config.action]
        },
        isinstalled = config.isinstalled,
        spawnconfig = config.config,
        isglobal = config.global,
        isDebug = ('debug' in config ? (config.debug || 0) : 0),
        depth = ('depth' in config ? (config.depth || "10") : "10"),
        entry;

    if (spawnconfig && typedas.isArray(spawnconfig)) {

        spawnconfig.forEach(function(item) {
            if (item) {
                entry = {args:[]};
                jsutils.Object.copy(baseobj, entry);
                if (isglobal) {
                    entry.args.push("-g");
                }
                if (item.args) {
                    entry.args = entry.args.concat(item.args);
                }
                if (item.name) {
                    entry.args.push(item.name);
                    entry.name = item.name;
                    names.push (item.name);
                } else {
                    logger.console.error("[package-script install] 'name' is require parameter");
                }

                entry.admin = (('admin' in item) ? item.admin : undefined);
                entry.spawnopt = (('spawnopt' in item) ? item.spawnopt : undefined);
                configval.push(entry);
            }
        });


    } else {
        logger.logall("[package-script] No valid configuration for 'install' function, see the docs for more information ");
    }

    jsutils.NPM.installed({global: isglobal, list: names, depth:depth, debug:isDebug}, function() {

        var data  = this.data,
            newarr = [];
        if (data) {
            configval.forEach(function(item){
                if (item) {
                    if (item.name) {
                        if (!isinstalled) {
                            if (!data[item.name]) {
                                newarr.push(item);
                            }
                        } else {
                            if (data[item.name]) {
                                newarr.push(item);
                            }
                        }
                    }
                }
            });
        }

        if (callback) {
            callback.call({data: newarr});
        }
    });
}