Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
TypeScript generator for v4 (#424)
Browse files Browse the repository at this point in the history
  • Loading branch information
daffl authored Jun 20, 2019
1 parent 6e3dee5 commit 2f920f5
Show file tree
Hide file tree
Showing 122 changed files with 1,911 additions and 89 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ npm install -g yo
Then install the feathers generator.

```bash
npm install -g yo generator-feathers
npm install -g yo generator-feathers-ts
```

## Usage
Expand All @@ -29,7 +29,7 @@ mkdir my-new-app; cd my-new-app/
Generate your app and follow the prompts.

```bash
yo feathers
yo feathers-ts
```

Start your brand new app! 💥
Expand All @@ -42,22 +42,22 @@ npm start

```bash
# short alias for generate new application
yo feathers
yo feathers-ts

# set up authentication
yo feathers:authentication
yo feathers-ts:authentication

# set up a database connection
yo feathers:connection
yo feathers-ts:connection

# generate new hook
yo feathers:hook
yo feathers-ts:hook

# generate new middleware
yo feathers:middleware
yo feathers-ts:middleware

# generate new service
yo feathers:service
yo feathers-ts:service
```

## Production
Expand All @@ -74,7 +74,7 @@ then inside the repo's directory, run `npm link`. This sets up a global
link to your local package for running tests (`npm test`) and generating
new feathers apps/services/hooks/etc.

When finished testing, optionally run `npm uninstall generator-feathers` to remove
When finished testing, optionally run `npm uninstall generator-feathers-ts` to remove
the link.

## License
Expand Down
6 changes: 5 additions & 1 deletion generators/app/configs/config.default.json.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module.exports = function() {
module.exports = function(generator) {
const { props } = generator;
const config = {
host: 'localhost',
port: 3030,
Expand All @@ -8,6 +9,9 @@ module.exports = function() {
max: 50
}
};
if (props.ts) {
config.ts = true;
}

return config;
};
3 changes: 2 additions & 1 deletion generators/app/configs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ module.exports = {
configDefault: require('./config.default.json.js'),
configProduction: require('./config.production.json.js'),
package: require('./package.json.js'),
eslintrc: require('./eslintrc.json.js')
eslintrc: require('./eslintrc.json.js'),
tsconfig: require('./tsconfig.json.js')
};
11 changes: 8 additions & 3 deletions generators/app/configs/package.json.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ module.exports = function(generator) {
'scripts': {
test: `${packager} run eslint && NODE_ENV= ${packager} run ${props.tester}`,
eslint: `eslint ${lib}/. test/. --config .eslintrc.json`,
dev: `nodemon ${lib}/`,
start: `node ${lib}/`
dev: props.ts ? `ts-node-dev --no-notify ${lib}/` : `nodemon ${lib}/`,
start: props.ts ? 'shx rm -rf lib/ && tsc && node lib/' : `node ${lib}/`
}
};
if ('mocha' === props.tester) {
pkg.scripts['mocha'] = 'mocha test/ --recursive --exit';
pkg.scripts['mocha'] = props.ts ? 'ts-mocha "test/**/*.ts"' : 'mocha test/ --recursive --exit';
} else {
pkg.scripts['jest'] = 'jest';
}

if (props.ts) {
pkg.scripts['test'] = `NODE_ENV= ${packager} run ${props.tester}`;
delete pkg.scripts['eslint'];
}

return pkg;
};
15 changes: 15 additions & 0 deletions generators/app/configs/tsconfig.json.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = function() {
const config = {
compilerOptions: {
target: 'es5',
module: 'commonjs',
outDir: './lib',
rootDir: './src',
strict: true,
esModuleInterop: true
},
exclude: ['test']
};

return config;
};
56 changes: 48 additions & 8 deletions generators/app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ module.exports = class AppGenerator extends Generator {
'@feathersjs/primus'
]);
const prompts = [{
type: 'confirm',
name: 'ts',
message: 'Use typescript',
default: false,
}, {
name: 'name',
message: 'Project name',
when: !this.pkg.name,
Expand Down Expand Up @@ -138,14 +143,14 @@ module.exports = class AppGenerator extends Generator {
);

this.fs.copyTpl(
this.templatePath('app.js'),
this.destinationPath(props.src, 'app.js'),
this.srcTemplatePath('app'),
this.srcDestinationPath(this.libDirectory, 'app'),
context
);

this.fs.copyTpl(
this.templatePath(`app.test.${props.tester}.js`),
this.destinationPath(this.testDirectory, 'app.test.js'),
this.srcTemplatePath(`app.test.${props.tester}`),
this.srcDestinationPath(this.testDirectory, 'app.test'),
context
);

Expand All @@ -154,10 +159,25 @@ module.exports = class AppGenerator extends Generator {
pkg
);

this.fs.writeJSON(
this.destinationPath('.eslintrc.json'),
makeConfig.eslintrc(this)
);
if (props.ts) {
this.fs.writeJSON(
this.destinationPath('tsconfig.json'),
makeConfig.tsconfig(this)
);

if (props.tester === 'jest') {
this.fs.copyTpl(
this.templatePath('jest.config.js'),
this.destinationPath('jest.config.js'),
context
);
}
} else {
this.fs.writeJSON(
this.destinationPath('.eslintrc.json'),
makeConfig.eslintrc(this)
);
}

this.fs.writeJSON(
this.destinationPath(this.configDirectory, 'default.json'),
Expand Down Expand Up @@ -185,6 +205,26 @@ module.exports = class AppGenerator extends Generator {
save: true
});

if (this.props.ts) {
const excluded = [
'eslint',
'nodemon@^1.18.7',
];
this.devDependencies = this.devDependencies.concat([
'@types/compression',
'@types/cors',
'@types/helmet',
'@types/request-promise',
'@types/serve-favicon',
'shx',
'ts-node-dev',
'tslint',
'typescript',
`@types/${this.props.tester}`,
`ts-${this.props.tester}`,
]).filter(item => !excluded.includes(item));
}

this.devDependencies.push(this.props.tester);

this._packagerInstall(this.devDependencies, {
Expand Down
File renamed without changes.
File renamed without changes.
56 changes: 56 additions & 0 deletions generators/app/templates/ts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# <%= name %>

> <%= description %>
## About

This project uses [Feathers](http://feathersjs.com). An open source web framework for building modern real-time applications.

## Getting Started

Getting up and running is as easy as 1, 2, 3.

1. Make sure you have [NodeJS](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed.
2. Install your dependencies

```
cd path/to/<%= name %>; npm install
```
3. Start your app
```
npm start
```
## Testing
Simply run `npm test` and all your tests in the `test/` directory will be run.
## Scaffolding
Feathers has a powerful command line interface. Here are a few things it can do:
```
$ npm install -g @feathersjs/cli # Install Feathers CLI

$ feathers generate service # Generate a new Service
$ feathers generate hook # Generate a new Hook
$ feathers help # Show all commands
```
## Help
For more information on all the things you can do with Feathers visit [docs.feathersjs.com](http://docs.feathersjs.com).
## Changelog
__0.1.0__
- Initial release
## License
Copyright (c) 2018
Licensed under the [MIT license](LICENSE).
112 changes: 112 additions & 0 deletions generators/app/templates/ts/_gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Logs
logs
*.log

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directory
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules

# Users Environment Variables
.lock-wscript

# IDEs and editors (shamelessly copied from @angular/cli's .gitignore)
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# Others
lib/
data/
13 changes: 13 additions & 0 deletions generators/app/templates/ts/app.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Application, Service } from '@feathersjs/feathers';

interface User {
id: number;
username: string;
password: string;
}

interface ServiceTypes {
users: Service<User>;
}

export type App = Application<ServiceTypes>;
Loading

0 comments on commit 2f920f5

Please sign in to comment.