Gruntfile.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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", "es6-promise/auto"], 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', 'app'],
  90. findNestedDependencies: true,
  91. exclude: ['helios/index'],
  92. optimize: "uglify2",
  93. out: "the.js"
  94. }
  95. },
  96. devel: {
  97. options: {
  98. rawText: {
  99. "app": mkDefine(["require", "es6-promise/auto"], cbRequireAndPromiseMain),
  100. "app/main": mkDefine(["devel", "amber/core/Platform-Browser"], id)
  101. },
  102. include: ['config', 'node_modules/requirejs/require', 'app', 'app/main'],
  103. exclude: ['devel', 'amber/core/Platform-Browser'],
  104. out: "the.js"
  105. }
  106. },
  107. deploy_lambda: {
  108. options: {
  109. rawText: {
  110. "helios/index": "",
  111. "app": mkDefine(["app/promise"], lambdaExports),
  112. "app/promise": mkDefine(["require"], cbRequireAndPromiseMain),
  113. "app/main": mkDefine(["lambda", "amber/core/Platform-Node"], function (amber) {
  114. return amber.initialize().then(function () {
  115. return amber;
  116. });
  117. })
  118. },
  119. pragmas: {
  120. excludeIdeData: true,
  121. excludeDebugContexts: true
  122. },
  123. include: ['app'],
  124. findNestedDependencies: true,
  125. exclude: ['helios/index'],
  126. wrap: {start: helpers.nodeWrapper.start, end: "return require('app');" + helpers.nodeWrapper.end},
  127. optimize: "uglify2",
  128. out: "lambda/the.js"
  129. }
  130. },
  131. test_runner: {
  132. options: {
  133. rawText: {
  134. "jquery": "/* do not load in node test runner */",
  135. "app/main": mkDefine(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  136. amber.initialize().then(function () {
  137. amber.globals.NodeTestRunner._main();
  138. });
  139. }),
  140. "app": mkDefine(["require"], cbRequireAndPromiseMain)
  141. },
  142. paths: {"amber_devkit": helpers.libPath},
  143. pragmas: {
  144. excludeIdeData: true
  145. },
  146. include: ['app'],
  147. findNestedDependencies: true,
  148. insertRequire: ['app'],
  149. optimize: "none",
  150. wrap: helpers.nodeWrapperWithShebang,
  151. out: "test_runner.js"
  152. }
  153. }
  154. },
  155. exec: {
  156. test_runner: 'node test_runner.js'
  157. },
  158. clean: {
  159. test_runner: ['test_runner.js']
  160. }
  161. });
  162. };