Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

Commit

Permalink
Add generator-superset (#21)
Browse files Browse the repository at this point in the history
* add generator to monorepo

* Squash all attempts (+21 squashed commits)
Squashed commits:
[cca27ae] enable jest projects
[e7dc4ce] wip
[dd3ea7a] run in order
[cf87275] define projects
[69baf16] use specific version
[c880cfa] ignore generator test
[e9e0fd3] update travis
[4bbb3c0] update travis
[d63118b] update travis config
[267fe08] remove config
[44883e8] update travis
[40580c3] reduce node version
[59b6add] update ignore rule
[fbbd03c] update readme
[b299dfe] remove script
[a988933] fix test and lint
[95b7d5b] try install and not install
[f4583b4] remove unnecessary files
[c735329] remove eslint-config-xo
[49b3106] pass lint and test
[56c6def] remove git and readd

* can get test to pass if exclude generator-superset

* add afterall to correct working directory

* update config

* add readme
  • Loading branch information
kristw authored Nov 8, 2018
1 parent b495213 commit 8968cbc
Show file tree
Hide file tree
Showing 13 changed files with 272 additions and 5 deletions.
6 changes: 4 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ install:
- npm install -g codecov
- yarn install

script:
before_script:
- yarn run build
- yarn run test

script:
- yarn test

after_script:
- codecov
22 changes: 19 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "yarn run build:cjs && yarn run build:esm",
"build:cjs": "NODE_ENV=production beemo babel ./src --out-dir lib/ --minify --workspaces=\"@superset-ui/!(demo)\"",
"build:esm": "NODE_ENV=production beemo babel ./src --out-dir esm/ --esm --minify --workspaces=\"@superset-ui/!(demo)\"",
"build:cjs": "NODE_ENV=production beemo babel ./src --out-dir lib/ --minify --workspaces=\"@superset-ui/!(demo|generator-superset)\"",
"build:esm": "NODE_ENV=production beemo babel ./src --out-dir esm/ --esm --minify --workspaces=\"@superset-ui/!(demo|generator-superset)\"",
"lint": "beemo create-config prettier && beemo eslint \"./packages/*/{src,test,storybook}/**/*.{js,jsx}\"",
"jest": "beemo jest --color --coverage",
"postrelease": "lerna run gh-pages",
Expand Down Expand Up @@ -55,7 +55,23 @@
}
},
"prettier"
]
],
"jest": {
"testPathIgnorePatterns": [
"<rootDir>/packages/generator-superset"
],
"projects": [
"<rootDir>",
{
"displayName": "node",
"rootDir": "<rootDir>/packages/generator-superset",
"testMatch": [
"<rootDir>/test/**/?(*.)+(spec|test).{js,jsx}"
],
"testEnvironment": "node"
}
]
}
},
"workspaces": [
"./packages/*"
Expand Down
1 change: 1 addition & 0 deletions packages/generator-superset/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
32 changes: 32 additions & 0 deletions packages/generator-superset/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# generator-superset

[![Version](https://img.shields.io/npm/v/@superset-ui/generator-superset.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/generator-superset.svg?style=flat-square)
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fgenerator-superset&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/generator-superset)

> Scaffolder for Superset
## Installation

First, install [Yeoman](http://yeoman.io) and `generator-superset` using [npm](https://www.npmjs.com/) (we assume you have pre-installed [node.js](https://nodejs.org/)).

```bash
npm install -g yo
npm install -g @superset-ui/generator-superset
```

## Usage

Generate a new package in `@superset-ui`

```bash
cd superset-ui/packages
mkdir superset-ui-new-package
cd superset-ui-new-package
yo @superset-ui/superset
```

## License

Apache-2.0

[learn more about Yeoman](http://yeoman.io/).
12 changes: 12 additions & 0 deletions packages/generator-superset/generators/app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Generator = require('yeoman-generator');

module.exports = class extends Generator {
initializing() {
// Redirect the default 'app' generator
// to 'package' subgenerator
// until there are multiple subgenerators
// then this can be changed into a menu to select
// subgenerator.
this.composeWith(require.resolve('../package'));
}
};
38 changes: 38 additions & 0 deletions packages/generator-superset/generators/package/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable sort-keys */

const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');

module.exports = class extends Generator {
async prompting() {
// Have Yeoman greet the user.
this.log(yosay(`Welcome to the rad ${chalk.red('generator-superset')} generator!`));

this.option('skipInstall');

this.answers = await this.prompt([
{
type: 'input',
name: 'name',
message: 'Package name:',
default: this.appname.replace('superset ui ', ''), // 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,
);
this.fs.copy(this.templatePath('src/index.js'), this.destinationPath('src/index.js'));
this.fs.copy(this.templatePath('test/index.js'), this.destinationPath('test/index.test.js'));
}
};
27 changes: 27 additions & 0 deletions packages/generator-superset/generators/package/templates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## @superset-ui/<%= name %>

[![Version](https://img.shields.io/npm/v/@superset-ui/<%= name
%>.svg?style=flat)](https://img.shields.io/npm/v/@superset-ui/<%= name %>.svg?style=flat)
[![David (path)](https://img.shields.io/david/apache-superset/superset-ui.svg?path=packages%2Fsuperset-ui-<%=
name
%>&style=flat-square)](https://david-dm.org/apache-superset/superset-ui?path=packages/superset-ui-<%=
name %>)

Description

#### Example usage

```js
import { xxx } from '@superset-ui/<%= name %>';
```

#### API

`fn(args)`

- Do something

### Development

`@data-ui/build-config` is used to manage the build configuration for this package including babel
builds, jest testing, eslint, and prettier.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "@superset-ui/<%= name %>",
"version": "0.0.0",
"description": "Superset UI <%= name %>",
"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"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const x = 1;
export default x;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('My Test', () => {
it('tests something', () => {
expect(1).toEqual(1);
});
});
37 changes: 37 additions & 0 deletions packages/generator-superset/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "generator-superset",
"version": "0.0.0",
"description": "Scaffolder for Superset",
"bugs": {
"url": "https://github.com/apache-superset/superset-ui/issues"
},
"homepage": "https://github.com/apache-superset/superset-ui#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/apache-superset/superset-ui.git"
},
"author": "Superset",
"files": [
"generators"
],
"main": "generators/index.js",
"keywords": [
"yeoman",
"generator",
"superset",
"yeoman-generator"
],
"devDependencies": {
"yeoman-test": "^1.9.1",
"yeoman-assert": "^3.1.0"
},
"engines": {
"npm": ">= 4.0.0"
},
"dependencies": {
"yeoman-generator": "^3.1.1",
"chalk": "^2.4.1",
"yosay": "^2.0.2"
},
"license": "Apache-2.0"
}
34 changes: 34 additions & 0 deletions packages/generator-superset/test/app.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-superset:app', () => {
let dir;

beforeAll(() => {
dir = process.cwd();

return helpers
.run(path.join(__dirname, '../generators/app'))
.withPrompts({ name: 'my-package' });
});

it('creates files', () => {
assert.file(['package.json', 'README.md', 'src/index.js', 'test/index.test.js']);
});

/*
* 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);
});
});
35 changes: 35 additions & 0 deletions packages/generator-superset/test/package.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path');
const assert = require('yeoman-assert');
const helpers = require('yeoman-test');

describe('generator-superset:package', () => {
let dir;

beforeAll(() => {
dir = process.cwd();

return helpers
.run(path.join(__dirname, '../generators/package'))
.withPrompts({ name: 'my-package' })
.withOptions({ skipInstall: true });
});

it('creates files', () => {
assert.file(['package.json', 'README.md', 'src/index.js', 'test/index.test.js']);
});

/*
* 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);
});
});

0 comments on commit 8968cbc

Please sign in to comment.