index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. import Generator from 'yeoman-generator';
  20. import { kebabCase, camelCase, startCase, upperFirst } from 'lodash-es';
  21. export default class extends Generator {
  22. async prompting() {
  23. this.option('skipInstall');
  24. this.answers = await this.prompt([
  25. {
  26. type: 'input',
  27. name: 'packageName',
  28. message: 'Package name:',
  29. // Default to current folder name, e.g. superset-plugin-chart-hello-world
  30. default: kebabCase(this.appname),
  31. },
  32. {
  33. type: 'input',
  34. name: 'pluginName',
  35. message: 'Plugin name:',
  36. // Hello World
  37. default: startCase(
  38. camelCase(this.appname.replace('superset plugin chart', '').trim()),
  39. ),
  40. },
  41. {
  42. type: 'input',
  43. name: 'description',
  44. message: 'Description:',
  45. // Superset Plugin Chart Hello World
  46. default: upperFirst(startCase(this.appname)),
  47. },
  48. {
  49. type: 'list',
  50. name: 'chartType',
  51. message: 'What type of chart would you like?',
  52. choices: [
  53. {
  54. name: 'Regular chart',
  55. value: 'regular',
  56. },
  57. {
  58. name: 'Time-series chart',
  59. value: 'timeseries',
  60. },
  61. ],
  62. },
  63. ]);
  64. }
  65. writing() {
  66. // SupersetPluginChartHelloWorld
  67. const packageLabel = upperFirst(camelCase(this.answers.packageName));
  68. const params = {
  69. ...this.answers,
  70. packageLabel,
  71. };
  72. [
  73. ['gitignore.erb', '.gitignore'],
  74. ['babel.config.erb', 'babel.config.js'],
  75. ['jest.config.erb', 'jest.config.js'],
  76. ['package.erb', 'package.json'],
  77. ['package-lock.erb', 'package-lock.json'],
  78. ['README.erb', 'README.md'],
  79. ['tsconfig.json', 'tsconfig.json'],
  80. ['src/index.erb', 'src/index.ts'],
  81. ['src/plugin/buildQuery.erb', 'src/plugin/buildQuery.ts'],
  82. ['src/plugin/controlPanel.erb', 'src/plugin/controlPanel.ts'],
  83. ['src/plugin/index.erb', 'src/plugin/index.ts'],
  84. ['src/plugin/transformProps.erb', 'src/plugin/transformProps.ts'],
  85. ['src/types.erb', 'src/types.ts'],
  86. ['src/MyChart.erb', `src/${packageLabel}.tsx`],
  87. ['test/index.erb', 'test/index.test.ts'],
  88. [
  89. 'test/__mocks__/mockExportString.js',
  90. 'test/__mocks__/mockExportString.js',
  91. ],
  92. ['test/plugin/buildQuery.test.erb', 'test/plugin/buildQuery.test.ts'],
  93. [
  94. 'test/plugin/transformProps.test.erb',
  95. 'test/plugin/transformProps.test.ts',
  96. ],
  97. ].forEach(([src, dest]) => {
  98. this.fs.copyTpl(
  99. this.templatePath(src),
  100. this.destinationPath(dest),
  101. params,
  102. );
  103. });
  104. ['types/external.d.ts', 'src/images/thumbnail.png'].forEach(file => {
  105. this.fs.copy(this.templatePath(file), this.destinationPath(file));
  106. });
  107. }
  108. }