template.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 should now install project dependencies with _bower install_.' +
  15. ' Afterwards, start the development server with _./bower_components/amber/bin/amber serve_.' +
  16. ' Your application is then accessible via _http://localhost:4000/_';
  17. // Any existing file or directory matching this wildcard will cause a warning.
  18. exports.warnOn = '*';
  19. // The actual init template.
  20. exports.template = function(grunt, init, done) {
  21. var remembered = {};
  22. function rememberViaValidator(name) {
  23. var old = init.prompts[name].validator || function (line) {
  24. return true;
  25. };
  26. init.prompts[name].validator = old.length == 1 ? function (line) {
  27. remembered[name] = line;
  28. return old.call(this, line);
  29. } : function (line, next) {
  30. remembered[name] = line;
  31. return old.call(this, line, next);
  32. }; //apply would not work, .length is used to call it differently.
  33. }
  34. function capitalize(string) {
  35. return string[0].toUpperCase() + string.slice(1).toLowerCase();
  36. }
  37. init.prompts.name.message= 'Main class and package of Amber application.';
  38. init.prompts.name.validator= function (line) { return /^[A-Z][A-Za-z0-9]*$/.test(line) };
  39. init.prompts.name.warning= 'Must be a valid class name: only alphanumeric and starting with an uppercase letter!';
  40. rememberViaValidator('name');
  41. rememberViaValidator('title');
  42. init.process({type: 'amber'}, [
  43. // Prompt for these values.
  44. init.prompt('title', 'ACME Application'),
  45. init.prompt('name', function (value, data, done) {
  46. var words = remembered.title.split(/\W/);
  47. words = words.filter(function (x) {
  48. return x && x !== "none";
  49. }).map(capitalize);
  50. value = words.length ? words.join('') : 'MysteriousApp';
  51. done(null, value);
  52. }),
  53. init.prompt('description', 'The ACME Application.'),
  54. init.prompt('author_name'),
  55. init.prompt('author_email'),
  56. {
  57. name: 'namespace',
  58. message: 'Namespace of the new Amber package.',
  59. altDefault: function(value, data, done) {
  60. value = 'amber-' + remembered.name.toLowerCase();
  61. done(null, value);
  62. },
  63. validator: /^[a-z][a-z0-9\-]*$/,
  64. warning: 'Only lowercase letters, numbers, and - are allowed in namespaces!'
  65. },
  66. init.prompt('version'),
  67. init.prompt('repository'),
  68. init.prompt('homepage'),
  69. init.prompt('bugs'),
  70. init.prompt('author_url'),
  71. init.prompt('licenses', 'MIT')
  72. ], function(err, props) {
  73. // Files to copy (and process).
  74. var files = init.filesToCopy(props);
  75. // Add properly-named license files.
  76. init.addLicenseFiles(files, props.licenses);
  77. // Actually copy (and process) files.
  78. init.copyAndProcess(files, props, {noProcess: 'libs/**'});
  79. // Clean up non-npm props.
  80. delete props.namespace;
  81. // A few additional properties.
  82. props.keywords = ['Amber', 'Smalltalk'];
  83. props.devDependencies = {
  84. "grunt": "~0.4.0",
  85. "grunt-execute": "~0.2.1",
  86. "grunt-contrib-clean": "~0.5.0",
  87. "amber-dev": "0.0.3"
  88. };
  89. props.node_version = '>= 0.8.0';
  90. props.scripts = {
  91. "test": "grunt test"
  92. };
  93. // Generate package.json file, used by npm and grunt.
  94. init.writePackageJSON('package.json', props);
  95. // generate bower.json file
  96. grunt.file.write('bower.json', JSON.stringify({
  97. "name": props.name,
  98. "description": props.description,
  99. "version": props.version,
  100. "ignore": [
  101. "**/.*",
  102. "node_modules",
  103. "bower_components",
  104. "/test_runner.js",
  105. "test",
  106. "tests"
  107. ],
  108. "authors": [
  109. {
  110. "name": props.author_name,
  111. "email": props.author_email
  112. }
  113. ],
  114. "homepage": props.homepage,
  115. "main": props.main,
  116. "keywords": props.keywords,
  117. "license": props.licenses,
  118. "private": false,
  119. "dependencies": {
  120. "amber": "~0.12.4"
  121. }
  122. }, null, 4));
  123. // All done!
  124. done();
  125. });
  126. };