Gruntfile.js 6.4 KB

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