Gruntfile.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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(''),
  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/Webstore.st', 'src/Webstore-Backend.st', // list all sources in dependency order
  63. 'src/Webstore-Tests.st' // list all tests in dependency order
  64. ],
  65. amd_namespace: 'amber-webstore',
  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/main"], lambdaExports),
  112. "app/main": mkDefine(["lambda", "amber/core/Platform-Node"], function (amber) {
  113. return amber.initialize().then(function () {
  114. return amber;
  115. });
  116. })
  117. },
  118. pragmas: {
  119. excludeIdeData: true,
  120. excludeDebugContexts: true
  121. },
  122. include: ['app'],
  123. findNestedDependencies: true,
  124. exclude: ['helios/index'],
  125. wrap: {start: helpers.nodeWrapper.start, end: "return require('app');" + helpers.nodeWrapper.end},
  126. optimize: "uglify2",
  127. out: "lambda/the.js"
  128. }
  129. },
  130. test_runner: {
  131. options: {
  132. rawText: {
  133. "jquery": "/* do not load in node test runner */",
  134. "app": mkDefine(["testing", "amber/core/Platform-Node", "amber_devkit/NodeTestRunner"], function (amber) {
  135. amber.initialize().then(function () {
  136. amber.globals.NodeTestRunner._main();
  137. });
  138. })
  139. },
  140. paths: {"amber_devkit": helpers.libPath},
  141. pragmas: {
  142. excludeIdeData: true
  143. },
  144. include: ['app'],
  145. findNestedDependencies: true,
  146. insertRequire: ['app'],
  147. optimize: "none",
  148. wrap: helpers.nodeWrapperWithShebang,
  149. out: "test_runner.js"
  150. }
  151. }
  152. },
  153. exec: {
  154. test_runner: 'node test_runner.js'
  155. },
  156. clean: {
  157. test_runner: ['test_runner.js']
  158. }
  159. });
  160. };