template.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * grunt-init-amber
  3. * https://amber-lang.net/
  4. *
  5. * Copyright (c) 2013 Manfred Kroehnert, contributors
  6. * Licensed under the MIT license.
  7. */
  8. 'use strict';
  9. // Basic template description.
  10. exports.description = 'Create a web application based on Amber Smalltalk.';
  11. // Template-specific notes to be displayed before question prompts.
  12. exports.notes = ' _Project title_ should be a human-readable title.';
  13. // Template-specific notes to be displayed after question prompts.
  14. exports.after = 'You need to have these installed globally via npm:' +
  15. ' _@ambers/cli_; _grunt-cli_; _bower_.' +
  16. ' Now, install project dependencies with _bower install_,' +
  17. ' tool dependencies with _npm install_ and recompile with _grunt_.' +
  18. ' If you are running _amber init_, these three tasks are going to be performed for you now.' +
  19. ' Afterwards, start the development server with _amber serve_.' +
  20. ' Your application is then accessible via _http://localhost:4000/_';
  21. // Any existing file or directory matching this wildcard will cause a warning.
  22. exports.warnOn = '*';
  23. // The actual init template.
  24. exports.template = function (grunt, init, done) {
  25. var remembered = {};
  26. function rememberViaValidator(name) {
  27. var oldValidator = init.prompts[name].validator || function (line) {
  28. return true;
  29. };
  30. var newValidator;
  31. switch (oldValidator.length) { //apply would not work, .length is used to call it differently
  32. case 1:
  33. newValidator = function (line) {
  34. remembered[name] = line;
  35. return oldValidator.call(this, line);
  36. };
  37. break;
  38. case 2:
  39. newValidator = function (line, next) {
  40. remembered[name] = line;
  41. return oldValidator.call(this, line, next);
  42. };
  43. break;
  44. default:
  45. throw new Error("Panic: " + oldValidator.length + "-argument validator for " + name + ".");
  46. }
  47. init.prompts[name].validator = newValidator;
  48. }
  49. function capitalize(string) {
  50. return string[0].toUpperCase() + string.slice(1).toLowerCase();
  51. }
  52. init.prompts.name.message = 'Main class and package of Amber application.\nProject name is derived by lowercasing this.';
  53. init.prompts.name.validator = function (line) {
  54. return /^[A-Z][A-Za-z0-9]*$/.test(line)
  55. };
  56. init.prompts.name.warning = 'Must be a valid class name: only alphanumeric and starting with an uppercase letter!';
  57. rememberViaValidator('name');
  58. rememberViaValidator('title');
  59. init.process({type: 'amber'}, [
  60. // Prompt for these values.
  61. init.prompt('title', 'Application or Library Title'),
  62. init.prompt('name', function (value, data, done) {
  63. var words = remembered.title.split(/\W/);
  64. words = words.filter(function (x) {
  65. return x && x !== "none";
  66. }).map(capitalize);
  67. value = words.length ? words.join('') : 'MysteriousApp';
  68. done(null, value);
  69. }),
  70. init.prompt('description', 'The Application or The Library doing The Thing.'),
  71. init.prompt('author_name'),
  72. init.prompt('author_email'),
  73. {
  74. name: 'namespace',
  75. message: 'Namespace of the new Amber package.',
  76. altDefault: function (value, data, done) {
  77. value = 'amber-' + remembered.name.toLowerCase();
  78. done(null, value);
  79. },
  80. validator: /^[a-z][a-z0-9/\-]*$/,
  81. warning: 'Only lowercase letters, numbers, and - are allowed in namespaces!'
  82. },
  83. init.prompt('version'),
  84. init.prompt('repository'),
  85. init.prompt('homepage'),
  86. init.prompt('bugs'),
  87. init.prompt('author_url'),
  88. init.prompt('licenses', 'MIT')
  89. ], function (err, props) {
  90. // Files to copy (and process).
  91. var files = init.filesToCopy(props);
  92. // Add properly-named license files.
  93. init.addLicenseFiles(files, props.licenses);
  94. // Actually copy (and process) files.
  95. init.copyAndProcess(files, props, {noProcess: 'libs/**'});
  96. // Clean up non-npm props.
  97. delete props.namespace;
  98. props.name = props.name.toLowerCase();
  99. // A few additional properties.
  100. props.keywords = ['Amber', 'Smalltalk'];
  101. props.devDependencies = {
  102. "@ambers/sdk": "^0.10.6",
  103. "grunt": "1.0.1",
  104. "grunt-contrib-clean": "^1.1.0",
  105. "grunt-contrib-requirejs": "^1.0.0",
  106. "grunt-exec": "^2.0.0",
  107. "requirejs": "^2.1.15"
  108. };
  109. props.node_version = '>=4.0.0';
  110. props.scripts = {
  111. "test": "grunt test"
  112. };
  113. // Generate package.json file, used by npm and grunt.
  114. init.writePackageJSON('package.json', props);
  115. // generate bower.json file
  116. grunt.file.write('bower.json', JSON.stringify({
  117. "name": props.name,
  118. "description": props.description,
  119. "ignore": [
  120. "**/.*",
  121. "node_modules",
  122. "bower_components",
  123. "/*.js",
  124. "/*.html",
  125. "test",
  126. "tests"
  127. ],
  128. "authors": [
  129. {
  130. "name": props.author_name,
  131. "email": props.author_email
  132. }
  133. ],
  134. "homepage": props.homepage,
  135. "main": props.main,
  136. "keywords": props.keywords,
  137. "license": props.licenses,
  138. "private": false,
  139. "dependencies": {
  140. "amber": "^0.22.0",
  141. "amber-compat-es2015": "^0.1.5",
  142. "amber-contrib-jquery": "^0.4.1",
  143. "amber-contrib-web": "^0.5.1",
  144. "domite": "^0.7.1",
  145. "silk": "^0.3.1"
  146. },
  147. "devDependencies": {
  148. "amber-contrib-legacy": "^0.6.1",
  149. "amber-ide-starter-dialog": "^0.1.0",
  150. "helios": "^0.9.1"
  151. }
  152. }, null, 2));
  153. // All done!
  154. done();
  155. });
  156. };