Gruntfile.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. grunt.registerTask('deploy:lambda', ['amdconfig:app', 'requirejs:deploy_lambda']);
  16. var id = function (x) {
  17. return x
  18. };
  19. function mkDefine (deps, cb) {
  20. return "define(" + JSON.stringify(deps) + "," + cb + ");"
  21. }
  22. var cbRequireAndPromiseMain = function (require) {
  23. return new Promise(function (resolve, reject) {
  24. require(["app/main"], resolve, reject);
  25. });
  26. };
  27. var lambdaExports = function (amberPromised) {
  28. return function (className) {
  29. var worker, workerPromise = amberPromised.then(function (amber) {
  30. worker = amber.globals[className]._new();
  31. });
  32. return function (selector) {
  33. var jsSelector, jsSelectorPromise = amberPromised.then(function (amber) {
  34. jsSelector = amber.api.st2js(selector);
  35. });
  36. var readyPromise = Promise.all([workerPromise, jsSelectorPromise]);
  37. return function (event, context) {
  38. return readyPromise.then(function () {
  39. return worker[jsSelector](event, context);
  40. });
  41. };
  42. };
  43. };
  44. };
  45. // Project configuration.
  46. grunt.initConfig({
  47. // Metadata.
  48. // pkg: grunt.file.readJSON('{%= amberjson %}'),
  49. banner: '/*! <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' +
  50. '<%= grunt.template.today("yyyy-mm-dd") %>\n' +
  51. '<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
  52. '* Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>;' +
  53. ' Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %> */\n',
  54. // task configuration
  55. amberc: {
  56. options: {
  57. amber_dir: path.join(__dirname, "node_modules", "@ambers", "lang"),
  58. configFile: "config.js"
  59. },
  60. all: {
  61. src: [
  62. 'src/{%= name %}.st', 'src/{%= name %}-Backend.st', // list all sources in dependency order
  63. 'src/{%= name %}-Tests.st' // list all tests in dependency order
  64. ],
  65. amd_namespace: '{%= namespace %}',
  66. libraries: ['amber/core/SUnit', 'amber/web/Web', 'silk/Silk']
  67. }
  68. },
  69. amdconfig: {app: {dest: 'config.js'}},
  70. requirejs: {
  71. options: {
  72. mainConfigFile: "config.js",
  73. paths: {
  74. "es6-promise/auto": "node_modules/es6-promise/dist/es6-promise.auto"
  75. },
  76. useStrict: true
  77. },
  78. deploy: {
  79. options: {
  80. rawText: {
  81. "helios/index": "",
  82. "app": mkDefine(["require"], cbRequireAndPromiseMain),
  83. "app/main": mkDefine(["deploy", "amber/core/Platform-Browser"], id)
  84. },
  85. pragmas: {
  86. excludeIdeData: true,
  87. excludeDebugContexts: true
  88. },
  89. include: ['config', 'node_modules/requirejs/require', 'es6-promise/auto', 'app'],
  90. insertRequire: ['es6-promise/auto'],
  91. findNestedDependencies: true,
  92. exclude: ['helios/index'],
  93. optimize: "uglify2",
  94. out: "the.js"
  95. }
  96. },
  97. devel: {
  98. options: {
  99. rawText: {
  100. "app": mkDefine(["require"], cbRequireAndPromiseMain),
  101. "app/main": mkDefine(["devel", "amber/core/Platform-Browser"], id)
  102. },
  103. include: ['config', 'node_modules/requirejs/require', 'es6-promise/auto', 'app', 'app/main'],
  104. insertRequire: ['es6-promise/auto'],
  105. exclude: ['devel', 'amber/core/Platform-Browser'],
  106. out: "the.js"
  107. }
  108. },
  109. deploy_lambda: {
  110. options: {
  111. rawText: {
  112. "helios/index": "",
  113. "app": mkDefine(["app/promise"], lambdaExports),
  114. "app/promise": mkDefine(["require"], cbRequireAndPromiseMain),
  115. "app/main": mkDefine(["lambda", "amber/core/Platform-Node"], function (amber) {
  116. return amber.initialize().then(function () {
  117. return amber;
  118. });
  119. })
  120. },
  121. pragmas: {
  122. excludeIdeData: true,
  123. excludeDebugContexts: true
  124. },
  125. include: ['app'],
  126. findNestedDependencies: true,
  127. exclude: ['helios/index'],
  128. wrap: {start: helpers.nodeWrapper.start, end: "return require('app');" + helpers.nodeWrapper.end},
  129. optimize: "uglify2",
  130. out: "lambda/the.js"
  131. }
  132. },
  133. test_runner: {
  134. options: {
  135. rawText: {
  136. "jquery": "/* do not load in node test runner */",
  137. "app/main": mkDefine(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  138. amber.initialize().then(function () {
  139. amber.globals.NodeTestRunner._main();
  140. });
  141. }),
  142. "app": mkDefine(["require"], cbRequireAndPromiseMain)
  143. },
  144. paths: {"amber_devkit": helpers.libPath},
  145. pragmas: {
  146. excludeIdeData: true
  147. },
  148. include: ['app'],
  149. findNestedDependencies: true,
  150. insertRequire: ['app'],
  151. optimize: "none",
  152. wrap: helpers.nodeWrapperWithShebang,
  153. out: "test_runner.js"
  154. }
  155. }
  156. },
  157. exec: {
  158. test_runner: 'node test_runner.js'
  159. },
  160. clean: {
  161. test_runner: ['test_runner.js']
  162. }
  163. });
  164. };