template.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. init.prompts.name.validator= /^[A-Z][A-Za-z0-9]*$/;
  22. init.prompts.name.warning= 'Must be a valid class name: only alphanumeric and starting with an uppercase letter!';
  23. init.process({type: 'amber'}, [
  24. // Prompt for these values.
  25. init.prompt('name', 'AmberApplication'),
  26. init.prompt('title'),
  27. init.prompt('description', 'Amber Application.'),
  28. {
  29. name: 'namespace',
  30. message: 'The namespace used to store your Amber Packages. (Required for the AMD package definition).',
  31. validator: /^[a-z0-9\-]+$/,
  32. warning: 'Only lowercase letters, number, and - are allowed in namespaces!'
  33. },
  34. {
  35. name: 'amber_version',
  36. default: '>= 0.12.4',
  37. message: 'The version of Amber to use. Must be >= 0.12.4'
  38. },
  39. init.prompt('version'),
  40. init.prompt('repository'),
  41. init.prompt('homepage'),
  42. init.prompt('bugs'),
  43. init.prompt('licenses', 'MIT'),
  44. init.prompt('author_name'),
  45. init.prompt('author_email'),
  46. init.prompt('author_url')
  47. ], function(err, props) {
  48. // Files to copy (and process).
  49. var files = init.filesToCopy(props);
  50. // Add properly-named license files.
  51. init.addLicenseFiles(files, props.licenses);
  52. // Actually copy (and process) files.
  53. init.copyAndProcess(files, props, {noProcess: 'libs/**'});
  54. // Clean up non-npm props.
  55. delete props.namespace;
  56. var amberVersion = props.amber_version;
  57. delete props.amber_version;
  58. // Add '~' at the beginning if version is without operation (starts with number)
  59. if (amberVersion.match(/^\d/)) {
  60. amberVersion = '~' + amberVersion;
  61. }
  62. // A few additional properties.
  63. props.keywords = ['Amber', 'Smalltalk'];
  64. props.devDependencies = {
  65. "grunt": "~0.4.0",
  66. "amber-dev": "0.0.3"
  67. };
  68. props.node_version = '>= 0.8.0';
  69. props.scripts = {
  70. "test": "grunt amberc:test_runner && node test_runner.js && ( rm test_runner.js || del test_runner.js )"
  71. };
  72. // Generate package.json file, used by npm and grunt.
  73. init.writePackageJSON('package.json', props);
  74. // generate bower.json file
  75. grunt.file.write('bower.json', JSON.stringify({
  76. "name": props.name,
  77. "description": props.description,
  78. "version": props.version,
  79. "ignore": [
  80. "**/.*",
  81. "node_modules",
  82. "bower_components",
  83. "/test_runner.js",
  84. "test",
  85. "tests"
  86. ],
  87. "authors": [
  88. {
  89. "name": props.author_name,
  90. "email": props.author_email
  91. }
  92. ],
  93. "homepage": props.homepage,
  94. "main": props.main,
  95. "keywords": props.keywords,
  96. "license": props.licenses,
  97. "private": false,
  98. "dependencies": {
  99. "amber": amberVersion
  100. }
  101. }, null, 4));
  102. // All done!
  103. done();
  104. });
  105. };