template.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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_ and _grunt-cli_.' +
  16. ' Now, install project dependencies with _npm install_' +
  17. ' and recompile / prepare with _grunt default devel_.' +
  18. ' If you are running _amber init_, these two 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.dependencies = {
  102. "@ambers/contrib-jquery": "^0.6.0",
  103. "@ambers/contrib-web": "^0.7.0",
  104. "@ambers/lang": "^0.23.2",
  105. "@ambers/domite": "^0.9.0",
  106. "es6-promise": "^4.2.6",
  107. "@ambers/silk": "^0.5.1"
  108. };
  109. props.devDependencies = {
  110. "@ambers/ide-starter-modal": "^0.2.0",
  111. "@ambers/sdk": "^0.12.1",
  112. "@ambers/contrib-legacy": "^0.8.0",
  113. "@ambers/helios": "^0.11.2",
  114. "grunt": "^1.0.3",
  115. "grunt-contrib-clean": "^1.1.0",
  116. "grunt-contrib-requirejs": "^1.0.0",
  117. "grunt-exec": "^3.0.0",
  118. "requirejs": "^2.3.5"
  119. };
  120. props.node_version = '>=4.0.0';
  121. props.scripts = {
  122. "reset": "npm run clean && npm run init",
  123. "clean": "(rm -rf node_modules || rd /s/q node_modules)",
  124. "init": "npm install && grunt default devel",
  125. "test": "grunt test"
  126. };
  127. // Generate package.json file, used by npm and grunt.
  128. init.writePackageJSON('package.json', props);
  129. // All done!
  130. done();
  131. });
  132. };