Gruntfile.js 5.55 KB
module.exports = function (grunt) {
    "use strict";
    
    let shim = function(obj) { return `\nexport default ${obj};\n`; };

// Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        copy: {
            dist: {
                files:[
                    {src: 'src/arcs_browser.js', dest: 'build/arcs_browser.js'},
                    {src: 'src/arcs_node.mjs', dest: 'build/arcs_node.mjs'}
                ]
                
            }            
        },
        jsdoc: {
            dist: {
                src: ['src/*.js', 'docs/Readme.md'], //, 'components/*.js'],
                options: {
                    /*verbose: true,
                    access: 'all',
                    private: true,*/
                    destination:  'docs/engine',
                    template: 'docs/arcs',
                    configure: 'docs/jsdoc.conf.json'

                }
            },
            components : {
                src: ['components/*.js', 'deps/surf/surf.js', 'deps/pose/posit_gen.js'],
                options: { 
                    verbose: true,
                    destination: 'docs/components',
                    template: 'docs/arcs',
                    configure: 'docs/jsdoc.conf.json'
                }
            }                
        },
        jslint: {
            dist: {
                src: ['*.js'],
                exclude: ['require.js', 'text.js'],
                directives: {
                    node: true,
                    sloppy: true,
                    plusplus: true,
                    forin: true,
                    devel: true,
                    white: true,
                    predef: ['define', 'arcs_module', 'document']
                    //browser: true,                    
                }
            }
        },
        terser: {
            build: {
                files: { 
                    'build/arcs.min.js': [
                        'build/arcs.js'
                    ],
                    'build/arcs_browser.min.js': [
                        'src/arcs_browser.js'
                    ],
                    'build/arcseditor.min.js': [
                        'build/arcseditor.js'
                    ]
                }
            }
        },
        bower: {
            options : {
                verbose: true,
                targetDir: './deps',
                copy: true,
                cleanBowerDir: true, 
                layout: 'byComponent'
            },
            install : {
                
            }
            
        },
        file_append: {
            default_options: {
                files: [
                    {
                        append: shim('AR'),
                        prepend: `import CV from '../cv/index.js';\n`,
                        input: './deps/aruco/index.js'
                    },
                    {
                        append: shim('CV'), 
                        input: './deps/cv/index.js'
                    }
                ]
            }            
        },
        'string-replace': {
            dist: {
                files: {
                    'deps/objloader/objloader.js': 'deps/objloader/index.js',
                    'deps/mtlloader/mtlloader.js': 'deps/mtlloader/index.js',
                    'deps/ddsloader/ddsloader.js': 'deps/ddsloader/index.js'
                },
                options: {
                    replacements:[{                      
                        pattern: '../../../build/three.module.js',
                        replacement: '../three.js/index.js'
                    }]                    
                }                
                
            }                        
        },        
	    concat: {
            dist: {
                src: [
                        'src/arcs.js', *
                        'src/component.js', *
                        'src/context.js', *
                        'src/invocation.js', *
                        'src/connection.js', *
                        'src/sheet.js',
                        'src/eventlogicparser.js', *
                        'src/tokenevent.js', *
                        'src/transitionnetwork.js', *
                        'src/statemachine.js', *
                        'src/application.js',
                        'src/exports.js' *
                    ],
                dest: 'build/arcs.js'
            }, 
            editor : {
                src: [ 
                        'utils/editor/arcseditor.js',
                        'utils/editor/dragdrop.js',
                        'utils/editor/template.js',
                        'utils/editor/dialog.js',
                        'utils/editor/componentdialog.js',
                        'utils/editor/invocationdialog.js',
                        'utils/editor/connectiondialog.js'
                     ],
                dest: 'build/arcseditor.js'
            }

	    }
	
    });

    // Load the plugin that provides the "uglify" task.
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-jsdoc');
    grunt.loadNpmTasks('grunt-jslint');
    grunt.loadNpmTasks('grunt-terser');
    grunt.loadNpmTasks('grunt-bower-task');
    grunt.loadNpmTasks('grunt-file-append');
    grunt.loadNpmTasks('grunt-string-replace');

    // Default task(s).
    grunt.registerTask('default', ['concat','copy','terser']);
    grunt.registerTask('lint', ['jslint']);
    grunt.registerTask('doc', ['jsdoc']);
    grunt.registerTask('install-deps', ['bower', 'file_append', 'string-replace']);
    
};