From 4733954af4ef03409681f5b7a19db7492edffa75 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Wed, 29 Apr 2020 20:16:16 -0700 Subject: [PATCH 1/7] feat: add plugin generator --- .../generators/app/index.js | 8 +++- .../generators/plugin-chart/index.js | 39 +++++++++++++++++++ .../plugin-chart/templates/README.md | 32 +++++++++++++++ .../plugin-chart/templates/_package.json | 32 +++++++++++++++ 4 files changed, 109 insertions(+), 2 deletions(-) create mode 100644 packages/generator-superset/generators/plugin-chart/index.js create mode 100644 packages/generator-superset/generators/plugin-chart/templates/README.md create mode 100644 packages/generator-superset/generators/plugin-chart/templates/_package.json diff --git a/packages/generator-superset/generators/app/index.js b/packages/generator-superset/generators/app/index.js index acefd320d4..8becd731ca 100644 --- a/packages/generator-superset/generators/app/index.js +++ b/packages/generator-superset/generators/app/index.js @@ -18,11 +18,15 @@ module.exports = class extends Generator { message: 'What do you want to do?', choices: [ { - name: 'Create superset-ui package in the monorepo', + name: 'Create superset-ui core package', value: 'package', }, { - name: 'Create superset-ui-legacy package in the monorepo', + name: 'Create superset-ui chart plugin package', + value: 'plugin-chart', + }, + { + name: 'Create superset-ui-legacy package', value: 'legacy-plugin-chart', }, { diff --git a/packages/generator-superset/generators/plugin-chart/index.js b/packages/generator-superset/generators/plugin-chart/index.js new file mode 100644 index 0000000000..1e2558c094 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/index.js @@ -0,0 +1,39 @@ +/* eslint-disable sort-keys */ + +const Generator = require('yeoman-generator'); +const _ = require('lodash'); + +module.exports = class extends Generator { + async prompting() { + this.option('skipInstall'); + + this.answers = await this.prompt([ + { + type: 'input', + name: 'packageName', + message: 'Package name:', + default: _.kebabCase(this.appname.replace('superset ui legacy plugin chart', '').trim()), // Default to current folder name + }, + { + type: 'input', + name: 'description', + message: 'Description:', + default: _.upperFirst( + _.startCase(this.appname.replace('superset ui legacy plugin chart', '').trim()), + ), // Default to current folder name + }, + ]); + } + + writing() { + this.fs.copyTpl( + this.templatePath('_package.json'), + this.destinationPath('package.json'), + this.answers, + ); + this.fs.copyTpl(this.templatePath('README.md'), this.destinationPath('README.md'), { + ...this.answers, + packageLabel: _.upperFirst(_.camelCase(this.answers.packageName)), + }); + } +}; diff --git a/packages/generator-superset/generators/plugin-chart/templates/README.md b/packages/generator-superset/generators/plugin-chart/templates/README.md new file mode 100644 index 0000000000..84617e5910 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/README.md @@ -0,0 +1,32 @@ +## @superset-ui/plugin-chart-<%= packageName %> + +[![Version](https://img.shields.io/npm/v/@superset-ui/plugin-chart-<%= packageName %>.svg?style=flat-square)](https://img.shields.io/npm/v/@superset-ui/plugin-chart-<%= packageName %>.svg?style=flat-square) +[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fsuperset-ui-plugin-chart-<%= packageName %>&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/superset-ui-plugin-chart-<%= packageName %>) + +This plugin provides <%= description %> for Superset. + +### Usage + +Configure `key`, which can be any `string`, and register the plugin. This `key` will be used to lookup this chart throughout the app. + +```js +import <%= packageLabel %>ChartPlugin from '@superset-ui/plugin-chart-<%= packageName %>'; + +new <%= packageLabel %>ChartPlugin() + .configure({ key: '<%= packageName %>' }) + .register(); +``` + +Then use it via `SuperChart`. See [storybook](https://apache-superset.github.io/superset-ui/?selectedKind=plugin-chart-<%= packageName %>) for more details. + +```js + +``` \ No newline at end of file diff --git a/packages/generator-superset/generators/plugin-chart/templates/_package.json b/packages/generator-superset/generators/plugin-chart/templates/_package.json new file mode 100644 index 0000000000..4cf7fb4f72 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/_package.json @@ -0,0 +1,32 @@ +{ + "name": "@superset-ui/plugin-chart-<%= packageName %>", + "version": "0.0.0", + "description": "Superset Chart - <%= description %>", + "sideEffects": false, + "main": "lib/index.js", + "module": "esm/index.js", + "files": [ + "esm", + "lib" + ], + "repository": { + "type": "git", + "url": "git+https://github.com/apache-superset/superset-ui.git" + }, + "keywords": [ + "superset" + ], + "author": "Superset", + "license": "Apache-2.0", + "bugs": { + "url": "https://github.com/apache-superset/superset-ui/issues" + }, + "homepage": "https://github.com/apache-superset/superset-ui#readme", + "publishConfig": { + "access": "public" + }, + "peerDependencies": { + "@superset-ui/chart": "latest", + "@superset-ui/translation": "latest" + } +} From 777f2edc7fe45acc71b843e8088a8699aa32ca81 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Fri, 1 May 2020 12:22:49 -0700 Subject: [PATCH 2/7] feat: add templates --- .../generators/plugin-chart/index.js | 22 +++++--- .../templates/{README.md => _README.md} | 0 .../plugin-chart/templates/src/MyChart.tsx | 49 ++++++++++++++++++ .../templates/src/images/thumbnail.png | Bin 0 -> 3619 bytes .../plugin-chart/templates/src/index.ts | 1 + .../templates/src/plugin/index.ts | 38 ++++++++++++++ .../templates/src/plugin/transformProps.ts | 32 ++++++++++++ .../templates/test/_index.test.ts | 7 +++ .../templates/types/external.d.ts | 4 ++ 9 files changed, 147 insertions(+), 6 deletions(-) rename packages/generator-superset/generators/plugin-chart/templates/{README.md => _README.md} (100%) create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/images/thumbnail.png create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/index.ts create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts create mode 100644 packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts create mode 100644 packages/generator-superset/generators/plugin-chart/templates/types/external.d.ts diff --git a/packages/generator-superset/generators/plugin-chart/index.js b/packages/generator-superset/generators/plugin-chart/index.js index 1e2558c094..caa5e61ca7 100644 --- a/packages/generator-superset/generators/plugin-chart/index.js +++ b/packages/generator-superset/generators/plugin-chart/index.js @@ -12,15 +12,15 @@ module.exports = class extends Generator { type: 'input', name: 'packageName', message: 'Package name:', - default: _.kebabCase(this.appname.replace('superset ui legacy plugin chart', '').trim()), // Default to current folder name + // Default to current folder name + default: _.kebabCase(this.appname.replace('plugin chart', '').trim()), }, { type: 'input', name: 'description', message: 'Description:', - default: _.upperFirst( - _.startCase(this.appname.replace('superset ui legacy plugin chart', '').trim()), - ), // Default to current folder name + // Default to current folder name + default: _.upperFirst(_.startCase(this.appname.replace('plugin chart', '').trim())), }, ]); } @@ -31,9 +31,19 @@ module.exports = class extends Generator { this.destinationPath('package.json'), this.answers, ); - this.fs.copyTpl(this.templatePath('README.md'), this.destinationPath('README.md'), { + + const packageLabel = _.upperFirst(_.camelCase(this.answers.packageName)); + + const params = { ...this.answers, - packageLabel: _.upperFirst(_.camelCase(this.answers.packageName)), + packageLabel, + }; + + [ + ['_README.md', 'README.md'], + ['test/_index.test.ts', 'test/index.test.ts'], + ].map(([src, dest]) => { + this.fs.copyTpl(this.templatePath(src), this.destinationPath(dest), params); }); } }; diff --git a/packages/generator-superset/generators/plugin-chart/templates/README.md b/packages/generator-superset/generators/plugin-chart/templates/_README.md similarity index 100% rename from packages/generator-superset/generators/plugin-chart/templates/README.md rename to packages/generator-superset/generators/plugin-chart/templates/_README.md diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx new file mode 100644 index 0000000000..b5ed309a37 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React from 'react'; + +export type MyChartProps = { + height: number; + width: number; + data: { x: number; y: number }[]; +}; + +export default class MyChart extends React.PureComponent { + render() { + const { data, height, width } = this.props; + + return ( + + {data.map(({ x, y }) => ( + + ))} + + Hello! + + + ); + } +} diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/images/thumbnail.png b/packages/generator-superset/generators/plugin-chart/templates/src/images/thumbnail.png new file mode 100644 index 0000000000000000000000000000000000000000..665bb0e8179f915ab31223eabb86138dbf35e873 GIT binary patch literal 3619 zcmeAS@N?(olHy`uVBq!ia0y~yV2S`?4mP03zO)&4fD~Jjx4R3&e-K=-cll(X${U_8 zjv*Cu-rlkAxnC-K{G8e!Q`^{{7RbdbQi` zKiQq!v(b=&;Y3Z^MP>$uZPJab3i_x?`( z^B-qFE?0}$Vtc3V_P&iZMV0UVzSyYz_`~0J^%xePmk%17AJ2Sz{@h;q8#}ZA{P}d= zcSlC`k7xDwB;V(*IltHb>zB#N|6_lv0}Xf+b!+d-oBtCS8IG`sF*x{)GN=~_InP_| zWh%eC07akQo|2@~zfYYyRq^nrxLVZa+CAUbf8Vxe|Bv0`$6wvtEWDO+*|t4@j!pZ1 zSvvdi(y#m=C3EDZqwmF6zx~=dEhpdl*pC+bOa=zMuJ9HH218g9L1oPT$#?B({EuTG z8_mwu8(jPUcf0HP8)as8Hs;5Uxfj1TzhCot$G^7M;AC<&JWh7?>ea>X!{aKSMnpx; zD!BOV!@u9}`?qf0y7T+$Y3rn{^=F@CwmS%P_OjBFe}T-t{~ubq8#HBY3JPqB|J>a9y}G{Oy~Vc~{mGyICtknw&i8zrAk%32qI%xS zIWCd>__2LV+1sz&vzTVDonKqt(|_&Rz3+E7=HDrLtt+g@wCu|r+hvfO>EOr2M&*Qh-@7??K?}u=`topx#v_+-|uEhPk z{A${F^J(`b`u~6W*m>>1(VK?HZbW?HU}$)IMB52l@d_?*&(^TNzEImPwvjpQ&%Yz5 zA3r(ybm#ZI)!+O6-oIxLDq`Qyt1I90b^3NO+vMAopU;{f|MlzFo!`Cj`wC-1WwBo1bs{w?W$H=|Oh6Tc4Dh%I_C{|M69L|EvPR154j)o4=9O*48e5 z?{E9}$&LEy^?Tyh#Cq>Gx2<;NfHXHz+Y+GKVN_%^5Qc8r*eILa)9c#Lz;MIw4?l9} c=FR?VqBqVg-ofPq?Da8ty85}Sb4q9e0GzGm1poj5 literal 0 HcmV?d00001 diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/index.ts b/packages/generator-superset/generators/plugin-chart/templates/src/index.ts new file mode 100644 index 0000000000..e500f6905d --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/src/index.ts @@ -0,0 +1 @@ +export { MyChartPlugin } from './plugin'; diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts new file mode 100644 index 0000000000..e81f775ec7 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts @@ -0,0 +1,38 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import { t } from '@superset-ui/translation'; +import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; +import transformProps from './transformProps'; +import thumbnail from './images/thumbnail.png'; + +const metadata = new ChartMetadata({ + description: '', + name: t('Example chart'), + thumbnail, +}); + +export default class MyChartPlugin extends ChartPlugin { + constructor() { + super({ + loadChart: () => import('../MyChart'), + metadata, + transformProps, + }); + } +} diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts new file mode 100644 index 0000000000..715f0af2f6 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts @@ -0,0 +1,32 @@ +import { ChartProps } from '@superset-ui/chart'; + +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +export default function transformProps(chartProps: ChartProps) { + const { width, height, formData, queryData } = chartProps; + const { color } = formData; + const { data } = queryData; + + return { + width, + height, + color, + data, + }; +} diff --git a/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts b/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts new file mode 100644 index 0000000000..6b0fb74b8b --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts @@ -0,0 +1,7 @@ +import { MyChartPlugin } from '../src'; + +describe('@superset-ui/plugin-chart-<%= packageName %>', () => { + it('exists', () => { + expect(MyChartPlugin).toBeDefined(); + }); +}); diff --git a/packages/generator-superset/generators/plugin-chart/templates/types/external.d.ts b/packages/generator-superset/generators/plugin-chart/templates/types/external.d.ts new file mode 100644 index 0000000000..0935dbbd80 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/types/external.d.ts @@ -0,0 +1,4 @@ +declare module '*.png' { + const value: any; + export default value; +} From 620ebce34d5cba736c8e7fca45753604cf4f9fa1 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 7 May 2020 17:19:27 -0700 Subject: [PATCH 3/7] feat: add templates --- .../generators/plugin-chart/index.js | 22 +++++---- .../templates/{_README.md => README.erb} | 0 .../templates/{_package.json => package.erb} | 0 .../src/{MyChart.tsx => MyChart.erb} | 4 +- .../plugin-chart/templates/src/index.erb | 1 + .../plugin-chart/templates/src/index.ts | 1 - .../src/plugin/{index.ts => index.erb} | 8 ++-- .../templates/test/_index.test.ts | 7 --- .../plugin-chart/templates/test/index.erb | 7 +++ .../test/plugin-chart.test.js | 45 +++++++++++++++++++ yarn.lock | 15 ++----- 11 files changed, 75 insertions(+), 35 deletions(-) rename packages/generator-superset/generators/plugin-chart/templates/{_README.md => README.erb} (100%) rename packages/generator-superset/generators/plugin-chart/templates/{_package.json => package.erb} (100%) rename packages/generator-superset/generators/plugin-chart/templates/src/{MyChart.tsx => MyChart.erb} (91%) create mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/index.erb delete mode 100644 packages/generator-superset/generators/plugin-chart/templates/src/index.ts rename packages/generator-superset/generators/plugin-chart/templates/src/plugin/{index.ts => index.erb} (85%) delete mode 100644 packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts create mode 100644 packages/generator-superset/generators/plugin-chart/templates/test/index.erb create mode 100644 packages/generator-superset/test/plugin-chart.test.js diff --git a/packages/generator-superset/generators/plugin-chart/index.js b/packages/generator-superset/generators/plugin-chart/index.js index caa5e61ca7..6d31d0b15d 100644 --- a/packages/generator-superset/generators/plugin-chart/index.js +++ b/packages/generator-superset/generators/plugin-chart/index.js @@ -26,12 +26,6 @@ module.exports = class extends Generator { } writing() { - this.fs.copyTpl( - this.templatePath('_package.json'), - this.destinationPath('package.json'), - this.answers, - ); - const packageLabel = _.upperFirst(_.camelCase(this.answers.packageName)); const params = { @@ -40,10 +34,20 @@ module.exports = class extends Generator { }; [ - ['_README.md', 'README.md'], - ['test/_index.test.ts', 'test/index.test.ts'], - ].map(([src, dest]) => { + ['package.erb', 'package.json'], + ['README.erb', 'README.md'], + ['src/plugin/index.erb', 'src/plugin/index.ts'], + ['src/index.erb', 'src/index.ts'], + ['src/MyChart.erb', `src/${packageLabel}.ts`], + ['test/index.erb', 'test/index.test.ts'], + ].forEach(([src, dest]) => { this.fs.copyTpl(this.templatePath(src), this.destinationPath(dest), params); }); + + ['types/external.d.ts', 'src/images/thumbnail.png', 'src/plugin/transformProps.ts'].forEach( + file => { + this.fs.copy(this.templatePath(file), this.destinationPath(file)); + }, + ); } }; diff --git a/packages/generator-superset/generators/plugin-chart/templates/_README.md b/packages/generator-superset/generators/plugin-chart/templates/README.erb similarity index 100% rename from packages/generator-superset/generators/plugin-chart/templates/_README.md rename to packages/generator-superset/generators/plugin-chart/templates/README.erb diff --git a/packages/generator-superset/generators/plugin-chart/templates/_package.json b/packages/generator-superset/generators/plugin-chart/templates/package.erb similarity index 100% rename from packages/generator-superset/generators/plugin-chart/templates/_package.json rename to packages/generator-superset/generators/plugin-chart/templates/package.erb diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb similarity index 91% rename from packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx rename to packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb index b5ed309a37..f2103ae34d 100644 --- a/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.tsx +++ b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb @@ -18,13 +18,13 @@ */ import React from 'react'; -export type MyChartProps = { +export type <%= packageLabel %>Props = { height: number; width: number; data: { x: number; y: number }[]; }; -export default class MyChart extends React.PureComponent { +export default class <%= packageLabel %> extends React.PureComponent<<%= packageLabel %>Props> { render() { const { data, height, width } = this.props; diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/index.erb b/packages/generator-superset/generators/plugin-chart/templates/src/index.erb new file mode 100644 index 0000000000..48e037ea93 --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/src/index.erb @@ -0,0 +1 @@ +export { default as <%= packageLabel %>ChartPlugin } from './plugin'; diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/index.ts b/packages/generator-superset/generators/plugin-chart/templates/src/index.ts deleted file mode 100644 index e500f6905d..0000000000 --- a/packages/generator-superset/generators/plugin-chart/templates/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { MyChartPlugin } from './plugin'; diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb similarity index 85% rename from packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts rename to packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb index e81f775ec7..9d7f25d7e9 100644 --- a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.ts +++ b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb @@ -22,15 +22,15 @@ import transformProps from './transformProps'; import thumbnail from './images/thumbnail.png'; const metadata = new ChartMetadata({ - description: '', - name: t('Example chart'), + description: '<%= description %>', + name: t('<%= packageLabel %>'), thumbnail, }); -export default class MyChartPlugin extends ChartPlugin { +export default class <%= packageLabel %>ChartPlugin extends ChartPlugin { constructor() { super({ - loadChart: () => import('../MyChart'), + loadChart: () => import('../<%= packageLabel %>'), metadata, transformProps, }); diff --git a/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts b/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts deleted file mode 100644 index 6b0fb74b8b..0000000000 --- a/packages/generator-superset/generators/plugin-chart/templates/test/_index.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { MyChartPlugin } from '../src'; - -describe('@superset-ui/plugin-chart-<%= packageName %>', () => { - it('exists', () => { - expect(MyChartPlugin).toBeDefined(); - }); -}); diff --git a/packages/generator-superset/generators/plugin-chart/templates/test/index.erb b/packages/generator-superset/generators/plugin-chart/templates/test/index.erb new file mode 100644 index 0000000000..6b2324dd4c --- /dev/null +++ b/packages/generator-superset/generators/plugin-chart/templates/test/index.erb @@ -0,0 +1,7 @@ +import { <%= packageLabel %>ChartPlugin } from '../src'; + +describe('@superset-ui/plugin-chart-<%= packageName %>', () => { + it('exists', () => { + expect(<%= packageLabel %>ChartPlugin).toBeDefined(); + }); +}); diff --git a/packages/generator-superset/test/plugin-chart.test.js b/packages/generator-superset/test/plugin-chart.test.js new file mode 100644 index 0000000000..d8d0b43c1c --- /dev/null +++ b/packages/generator-superset/test/plugin-chart.test.js @@ -0,0 +1,45 @@ +const path = require('path'); +const assert = require('yeoman-assert'); +const helpers = require('yeoman-test'); + +describe('generator-superset:plugin-chart', () => { + let dir; + + beforeAll(() => { + dir = process.cwd(); + + return helpers + .run(path.join(__dirname, '../generators/plugin-chart')) + .withPrompts({ packageName: 'cold-map', description: 'Cold Map' }) + .withOptions({ skipInstall: true }); + }); + + /* + * Change working directory back to original working directory + * after the test has completed. + * yeoman tests switch to tmp directory and write files there. + * Usually this is fine for solo package. + * However, for a monorepo like this one, + * it made jest confuses with current directory + * (being in tmp directory instead of superset-ui root) + * and interferes with other tests in sibling packages + * that are run after the yeoman tests. + */ + afterAll(() => { + process.chdir(dir); + }); + + it('creates files', () => { + assert.file([ + 'package.json', + 'README.md', + 'src/plugin/index.ts', + 'src/plugin/transformProps.ts', + 'src/index.ts', + 'src/ColdMap.ts', + 'test/index.test.ts', + 'types/external.d.ts', + 'src/images/thumbnail.png', + ]); + }); +}); diff --git a/yarn.lock b/yarn.lock index 8a79f24181..4212c025a3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3251,15 +3251,6 @@ conventional-changelog-cli "^2.0.12" cz-conventional-changelog "^2.1.0" -"@superset-ui/legacy-plugin-chart-partition@0.13.5": - version "0.13.5" - resolved "https://registry.yarnpkg.com/@superset-ui/legacy-plugin-chart-partition/-/legacy-plugin-chart-partition-0.13.5.tgz#f34d14bc204ef2ad7acb7dee32ee09c46726535b" - integrity sha512-YsgbAqj/sQKEWUmI0XXy6rJvGsWSPwfekmtWpa55CF19A+TJEuCCHmIGDPupgZsIqgJBZArwYT3HNnn7a8TfxA== - dependencies: - d3 "^3.5.17" - d3-hierarchy "^1.1.8" - prop-types "^15.6.2" - "@superset-ui/legacy-plugin-chart-word-cloud@^0.11.15": version "0.11.15" resolved "https://registry.yarnpkg.com/@superset-ui/legacy-plugin-chart-word-cloud/-/legacy-plugin-chart-word-cloud-0.11.15.tgz#70a146aaf3cf1977c29086c069f0216325f092b2" @@ -3729,9 +3720,9 @@ "@types/react" "*" "@types/react@*", "@types/react@^16.3.0", "@types/react@^16.9.11", "@types/react@^16.9.34": - version "16.9.35" - resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.35.tgz#a0830d172e8aadd9bd41709ba2281a3124bbd368" - integrity sha512-q0n0SsWcGc8nDqH2GJfWQWUOmZSJhXV64CjVN5SvcNti3TdEaA3AH0D8DwNmMdzjMAC/78tB8nAZIlV8yTz+zQ== + version "16.9.34" + resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.34.tgz#f7d5e331c468f53affed17a8a4d488cd44ea9349" + integrity sha512-8AJlYMOfPe1KGLKyHpflCg5z46n0b5DbRfqDksxBLBTUpB75ypDBAO9eCUcjNwE6LCUslwTz00yyG/X9gaVtow== dependencies: "@types/prop-types" "*" csstype "^2.2.0" From 4affa198cbfe8d379d890df0e2d6a777cd27edf1 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 7 May 2020 17:29:25 -0700 Subject: [PATCH 4/7] fix: wrong path --- packages/generator-superset/generators/plugin-chart/index.js | 2 +- .../generators/plugin-chart/templates/src/plugin/index.erb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/generator-superset/generators/plugin-chart/index.js b/packages/generator-superset/generators/plugin-chart/index.js index 6d31d0b15d..6698051776 100644 --- a/packages/generator-superset/generators/plugin-chart/index.js +++ b/packages/generator-superset/generators/plugin-chart/index.js @@ -38,7 +38,7 @@ module.exports = class extends Generator { ['README.erb', 'README.md'], ['src/plugin/index.erb', 'src/plugin/index.ts'], ['src/index.erb', 'src/index.ts'], - ['src/MyChart.erb', `src/${packageLabel}.ts`], + ['src/MyChart.erb', `src/${packageLabel}.tsx`], ['test/index.erb', 'test/index.test.ts'], ].forEach(([src, dest]) => { this.fs.copyTpl(this.templatePath(src), this.destinationPath(dest), params); diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb index 9d7f25d7e9..3a3fbe480e 100644 --- a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb +++ b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/index.erb @@ -19,7 +19,7 @@ import { t } from '@superset-ui/translation'; import { ChartMetadata, ChartPlugin } from '@superset-ui/chart'; import transformProps from './transformProps'; -import thumbnail from './images/thumbnail.png'; +import thumbnail from '../images/thumbnail.png'; const metadata = new ChartMetadata({ description: '<%= description %>', From 3b8dc62e239cf8449cc12d3f7a4366e5d153f706 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 7 May 2020 17:45:30 -0700 Subject: [PATCH 5/7] fix: unit test --- packages/generator-superset/test/plugin-chart.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/generator-superset/test/plugin-chart.test.js b/packages/generator-superset/test/plugin-chart.test.js index d8d0b43c1c..500cf107c2 100644 --- a/packages/generator-superset/test/plugin-chart.test.js +++ b/packages/generator-superset/test/plugin-chart.test.js @@ -36,7 +36,7 @@ describe('generator-superset:plugin-chart', () => { 'src/plugin/index.ts', 'src/plugin/transformProps.ts', 'src/index.ts', - 'src/ColdMap.ts', + 'src/ColdMap.tsx', 'test/index.test.ts', 'types/external.d.ts', 'src/images/thumbnail.png', From 965b165048191e6dfcfaa0b8c49fc6165915a731 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Thu, 7 May 2020 17:47:56 -0700 Subject: [PATCH 6/7] fix: coverage --- .../generators/plugin-chart/index.js | 11 +++++------ .../plugin/{transformProps.ts => transformProps.txt} | 0 2 files changed, 5 insertions(+), 6 deletions(-) rename packages/generator-superset/generators/plugin-chart/templates/src/plugin/{transformProps.ts => transformProps.txt} (100%) diff --git a/packages/generator-superset/generators/plugin-chart/index.js b/packages/generator-superset/generators/plugin-chart/index.js index 6698051776..f43812cc79 100644 --- a/packages/generator-superset/generators/plugin-chart/index.js +++ b/packages/generator-superset/generators/plugin-chart/index.js @@ -36,18 +36,17 @@ module.exports = class extends Generator { [ ['package.erb', 'package.json'], ['README.erb', 'README.md'], - ['src/plugin/index.erb', 'src/plugin/index.ts'], ['src/index.erb', 'src/index.ts'], + ['src/plugin/index.erb', 'src/plugin/index.ts'], + ['src/plugin/transformProps.txt', 'src/plugin/transformProps.ts'], ['src/MyChart.erb', `src/${packageLabel}.tsx`], ['test/index.erb', 'test/index.test.ts'], ].forEach(([src, dest]) => { this.fs.copyTpl(this.templatePath(src), this.destinationPath(dest), params); }); - ['types/external.d.ts', 'src/images/thumbnail.png', 'src/plugin/transformProps.ts'].forEach( - file => { - this.fs.copy(this.templatePath(file), this.destinationPath(file)); - }, - ); + ['types/external.d.ts', 'src/images/thumbnail.png'].forEach(file => { + this.fs.copy(this.templatePath(file), this.destinationPath(file)); + }); } }; diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts b/packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.txt similarity index 100% rename from packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.ts rename to packages/generator-superset/generators/plugin-chart/templates/src/plugin/transformProps.txt From e47f366f1111bbf590017ac3a61a224ca7d14cd4 Mon Sep 17 00:00:00 2001 From: Krist Wongsuphasawat Date: Wed, 13 May 2020 13:25:21 -0700 Subject: [PATCH 7/7] fix: simplify template --- .../plugin-chart/templates/src/MyChart.erb | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb index f2103ae34d..4bc2f65b31 100644 --- a/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb +++ b/packages/generator-superset/generators/plugin-chart/templates/src/MyChart.erb @@ -29,21 +29,12 @@ export default class <%= packageLabel %> extends React.PureComponent<<%= package const { data, height, width } = this.props; return ( - - {data.map(({ x, y }) => ( - - ))} - - Hello! - - +
+

Hello!

+
+          {JSON.stringify(this.props, null, 2)}
+        
+
); } }