template.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. ' _amber-cli_; _grunt-cli_; _bower_.' +
  16. ' Now, install project dependencies with _bower install_,' +
  17. ' tool dependencies with _npm install_ and optionally, 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. "amber-dev": "^0.8.2",
  103. "grunt": "^0.4.5",
  104. "grunt-contrib-clean": "^0.7.0",
  105. "grunt-contrib-requirejs": "^0.4.4",
  106. "grunt-execute": "^0.2.2",
  107. "requirejs": "^2.1.15"
  108. };
  109. props.node_version = '0.10.x || 0.12.x || >=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. "version": props.version,
  120. "ignore": [
  121. "**/.*",
  122. "node_modules",
  123. "bower_components",
  124. "/*.js",
  125. "/*.html",
  126. "test",
  127. "tests"
  128. ],
  129. "authors": [
  130. {
  131. "name": props.author_name,
  132. "email": props.author_email
  133. }
  134. ],
  135. "homepage": props.homepage,
  136. "main": props.main,
  137. "keywords": props.keywords,
  138. "license": props.licenses,
  139. "private": false,
  140. "dependencies": {
  141. "amber": "^0.15.0",
  142. "amber-compat-es2015": "^0.1.0",
  143. "amber-contrib-jquery": "^0.2.0",
  144. "amber-contrib-web": "^0.3.0",
  145. "domite": "^0.4.0",
  146. "silk": "^0.2.0"
  147. },
  148. "devDependencies": {
  149. "amber-contrib-legacy": "^0.3,0",
  150. "amber-ide-starter-dialog": "^0.1.0",
  151. "helios": "^0.6.0"
  152. }
  153. }, null, 4));
  154. // All done!
  155. done();
  156. });
  157. };