/*
 * @Date: 2018-11-14 11:57:33
 * @Author: Scm <chengqiuhua@erayt.com>
 * @Copyright: 2015-2019 Erayt, Inc.
 * @Description: If you have some questions, please contact: chengqiuhua@erayt.com.
 */
module.exports = function(grunt) {
  const config = require('../../utils/config')(grunt);
  const copyTasks = require('../utils/index')(config, 'web');

  grunt.initConfig({

    config: config,

    meta: {
      base: 'node_modules/@erayt',
      project: `../../../packages/${config.projectName}`,
      dest: `../../../dist/static/${config.appModuleName}`,
    },

    copy: Object.assign({
      config: {
        expand: true,
        cwd: '../../../config/web',
        src: `*`,
        dest: `../../../dist/static/config`,
      },
      data: {
        expand: true,
        cwd: '../../../data',
        src: `*`,
        dest: `../../../dist/static/${config.appModuleName}/data`,
      },
    }, copyTasks),

    clean: {
      dest: '<%= meta.dest %>',
      cache: ['package-lock.json', 'yarn.lock'],
    },
  });

  require('time-grunt')(grunt);
  // grunt plugins
  require('load-grunt-tasks')(grunt);
  grunt.registerTask('emptyFile', 'Creates an empty file', function(args,args1) {
    console.log(args, args1);
    
    grunt.file.write(`${grunt.config.data.meta.dest}/version.txt`, '');
 });
  grunt.registerTask('build', ['clean:dest', 'clean', 'copy',"emptyFile"]);
  
};

