Gruntfile.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. 'use strict';
  2. module.exports = function (grunt) {
  3. // These plugins provide necessary tasks.
  4. grunt.loadNpmTasks('grunt-contrib-clean');
  5. grunt.loadNpmTasks('grunt-contrib-requirejs');
  6. grunt.loadNpmTasks('grunt-exec');
  7. grunt.loadNpmTasks('@ambers/sdk');
  8. var path = require('path'),
  9. helpers = require('@ambers/sdk').helpers;
  10. // Default task.
  11. grunt.registerTask('default', ['amdconfig:app', 'amberc:all']);
  12. grunt.registerTask('test', ['amdconfig:app', 'requirejs:test_runner', 'exec:test_runner', 'clean:test_runner']);
  13. grunt.registerTask('devel', ['amdconfig:app', 'requirejs:devel']);
  14. grunt.registerTask('deploy', ['amdconfig:app', 'requirejs:deploy']);
  15. var id = function (x) {
  16. return x
  17. };
  18. function mkDefine (deps, cb) {
  19. return "define(" + JSON.stringify(deps) + "," + cb + ");"
  20. }
  21. var cbRequireAndPromiseMain = function (require) {
  22. return new Promise(function (resolve, reject) {
  23. require(["app/main"], resolve, reject);
  24. });
  25. };
  26. // Project configuration.
  27. grunt.initConfig({
  28. // Metadata.
  29. // pkg: grunt.file.readJSON(''),
  30. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  31. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  32. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  33. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  34. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  35. // task configuration
  36. amberc: {
  37. options: {
  38. amber_dir: path.join(__dirname, "node_modules", "@ambers", "lang"),
  39. configFile: "config.js"
  40. },
  41. all: {
  42. src: [
  43. 'src/MiniMVP.st', 'src/MiniMVP-Backend.st', // list all sources in dependency order
  44. 'src/MiniMVP-Tests.st' // list all tests in dependency order
  45. ],
  46. amd_namespace: 'mini-mvp',
  47. libraries: ['amber/core/SUnit', 'amber/web/Web', 'silk/Silk']
  48. }
  49. },
  50. amdconfig: {app: {dest: 'config.js'}},
  51. requirejs: {
  52. options: {
  53. mainConfigFile: "config.js",
  54. paths: {
  55. "es6-promise/auto": "node_modules/es6-promise/dist/es6-promise.auto"
  56. },
  57. useStrict: true
  58. },
  59. deploy: {
  60. options: {
  61. rawText: {
  62. "helios/index": "",
  63. "app": mkDefine(["require", "es6-promise/auto"], cbRequireAndPromiseMain),
  64. "app/main": mkDefine(["deploy", "amber/core/Platform-Browser"], id)
  65. },
  66. pragmas: {
  67. excludeIdeData: true,
  68. excludeDebugContexts: true
  69. },
  70. include: ['config', 'node_modules/requirejs/require', 'app'],
  71. findNestedDependencies: true,
  72. exclude: ['helios/index'],
  73. optimize: "uglify2",
  74. out: "the.js"
  75. }
  76. },
  77. devel: {
  78. options: {
  79. rawText: {
  80. "app": mkDefine(["require", "es6-promise/auto"], cbRequireAndPromiseMain),
  81. "app/main": mkDefine(["devel", "amber/core/Platform-Browser"], id)
  82. },
  83. include: ['config', 'node_modules/requirejs/require', 'app', 'app/main'],
  84. exclude: ['devel', 'amber/core/Platform-Browser'],
  85. out: "the.js"
  86. }
  87. },
  88. test_runner: {
  89. options: {
  90. rawText: {
  91. "jquery": "/* do not load in node test runner */",
  92. "app": mkDefine(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  93. amber.initialize().then(function () {
  94. amber.globals.NodeTestRunner._main();
  95. });
  96. })
  97. },
  98. paths: {"amber_devkit": helpers.libPath},
  99. pragmas: {
  100. excludeIdeData: true
  101. },
  102. include: ['app'],
  103. findNestedDependencies: true,
  104. insertRequire: ['app'],
  105. optimize: "none",
  106. wrap: helpers.nodeWrapperWithShebang,
  107. out: "test_runner.js"
  108. }
  109. }
  110. },
  111. exec: {
  112. test_runner: 'node test_runner.js'
  113. },
  114. clean: {
  115. test_runner: ['test_runner.js']
  116. }
  117. });
  118. };