Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Docker dev environment; turned lib path into template variable #56

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
module.exports = {
"env": {
"es6": true,
"node": true
env: {
es6: true,
node: true
},
"extends": "eslint:recommended",
"rules": {
"indent": [
"error",
2
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
]
extends: "eslint:recommended",
rules: {
indent: ["error", 2],
quotes: [false],
semi: ["error", "always"]
}
};
};
150 changes: 91 additions & 59 deletions generators/app/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
'use strict';
const Generator = require('yeoman-generator');
const chalk = require('chalk');
const yosay = require('yosay');
const path = require('path');
const _ = require('lodash');
const shelljs = require('shelljs');
"use strict";
const Generator = require("yeoman-generator");
const chalk = require("chalk");
const yosay = require("yosay");
const path = require("path");
const _ = require("lodash");
const shelljs = require("shelljs");

const BUILD_PATH = "build";

module.exports = Generator.extend({
initializing: function() {
Expand All @@ -13,31 +15,31 @@ module.exports = Generator.extend({
// Have Yeoman greet the user.
this.log(
yosay(
'Welcome to the minimal ' + chalk.red('Node TypeScript') + ' generator!'
"Welcome to the minimal " + chalk.red("Node TypeScript") + " generator!"
)
);

this.log(
chalk.cyan(
'I simply get down to business of generating, no questions asked!'
"I simply get down to business of generating, no questions asked!"
) +
'\n' +
"\n" +
chalk.yellow(
'Libraries you ask? I use npm as task runner and jest for testing.'
"Libraries you ask? I use npm as task runner and jest for testing."
) +
'\n' +
"\n" +
chalk.gray(
'Can you change these? Of course, it\'s your code. I get out of the way after scaffolding.'
"Can you change these? Of course, it's your code. I get out of the way after scaffolding."
)
);

this.composeWith(
require.resolve('../classlib'),
Object.assign({ arguments: ['Greeter'] }, this.options)
require.resolve("../classlib"),
Object.assign({ arguments: ["Greeter"] }, this.options)
);

if (this.options.gulp) {
throw new Error('Gulp option is no longer supported.');
throw new Error("Gulp option is no longer supported.");
}

done();
Expand All @@ -46,104 +48,134 @@ module.exports = Generator.extend({
writing: {
vsCodeFiles: function() {
this.fs.copy(
this.templatePath('_vscode/tasks.json'),
this.destinationPath('.vscode/tasks.json')
this.templatePath("_vscode/tasks.json"),
this.destinationPath(".vscode/tasks.json")
);
this.fs.copy(
this.templatePath('_vscode/settings.json'),
this.destinationPath('.vscode/settings.json')
this.templatePath("_vscode/settings.json"),
this.destinationPath(".vscode/settings.json")
);
if (!(this.options.mocha || this.options.ava)) {
// copy launch.json only for default jest configuration
this.fs.copy(
this.templatePath('_vscode/launch.json'),
this.destinationPath('.vscode/launch.json')
this.templatePath("_vscode/launch.json"),
this.destinationPath(".vscode/launch.json"),
{ buildpath: BUILD_PATH }
);
}
},

rootFiles: function() {
const today = new Date();

if (this.options.mocha) {
// copy mocha files
this.fs.copyTpl(
this.templatePath('_package_mocha.json'),
this.destinationPath('package.json'),
{ appname: _.kebabCase(path.basename(process.cwd())) }
this.templatePath("_package_mocha.json"),
this.destinationPath("package.json"),
{
appname: _.kebabCase(path.basename(process.cwd())),
buildpath: BUILD_PATH
}
);
this.fs.copy(
this.templatePath('travis_mocha.yml'),
this.destinationPath('.travis.yml')
this.templatePath("travis_mocha.yml"),
this.destinationPath(".travis.yml")
);
} else if (this.options.ava) {
// copy ava files
this.fs.copyTpl(
this.templatePath('_package_ava.json'),
this.destinationPath('package.json'),
{ appname: _.kebabCase(path.basename(process.cwd())) }
this.templatePath("_package_ava.json"),
this.destinationPath("package.json"),
{
appname: _.kebabCase(path.basename(process.cwd())),
buildpath: BUILD_PATH
}
);
this.fs.copy(
this.templatePath('travis_ava.yml'),
this.destinationPath('.travis.yml')
this.templatePath("travis_ava.yml"),
this.destinationPath(".travis.yml")
);
this.fs.copy(
this.templatePath('_tsconfig.test.json'),
this.destinationPath('tsconfig.test.json')
this.fs.copyTpl(
this.templatePath("_tsconfig.test.json"),
this.destinationPath("tsconfig.test.json"),
{
buildpath: BUILD_PATH
}
);
} else {
// copy files for default jest configuration
this.fs.copyTpl(
this.templatePath('_package.json'),
this.destinationPath('package.json'),
{ appname: _.kebabCase(path.basename(process.cwd())) }
this.templatePath("_package.json"),
this.destinationPath("package.json"),
{
appname: _.kebabCase(path.basename(process.cwd())),
buildpath: BUILD_PATH
}
);
this.fs.copy(
this.templatePath('travis.yml'),
this.destinationPath('.travis.yml')
this.templatePath("travis.yml"),
this.destinationPath(".travis.yml")
);
}
// copy files common for all configurations
this.fs.copy(
this.templatePath('README.md'),
this.destinationPath('README.md')
this.templatePath("README.md"),
this.destinationPath("README.md"),
{ buildpath: BUILD_PATH }
);
this.fs.copyTpl(
this.templatePath("_tsconfig.json"),
this.destinationPath("tsconfig.json"),
{ buildpath: BUILD_PATH }
);
this.fs.copy(
this.templatePath('_tsconfig.json'),
this.destinationPath('tsconfig.json')
this.templatePath("_tslint.json"),
this.destinationPath("tslint.json")
);
this.fs.copy(
this.templatePath('_tslint.json'),
this.destinationPath('tslint.json')
this.templatePath("editorconfig"),
this.destinationPath(".editorconfig")
);
this.fs.copy(
this.templatePath('editorconfig'),
this.destinationPath('.editorconfig')
this.templatePath("dockerignore"),
this.destinationPath(".dockerignore"),
{ buildpath: BUILD_PATH }
);
this.fs.copy(
this.templatePath('gitignore'),
this.destinationPath('.gitignore')
this.templatePath("gitignore"),
this.destinationPath(".gitignore"),
{ buildpath: BUILD_PATH }
);
this.fs.copy(
this.templatePath('npmignore'),
this.destinationPath('.npmignore')
this.templatePath("npmignore"),
this.destinationPath(".npmignore"),
{ buildpath: BUILD_PATH }
);
this.fs.copyTpl(
this.templatePath("docker-compose.yml"),
this.destinationPath("docker-compose.yml"),
{ appname: _.kebabCase(path.basename(process.cwd())) }
);
this.fs.copyTpl(
this.templatePath("docker-compose.builder.yml"),
this.destinationPath("docker-compose.builder.yml"),
{ appname: _.kebabCase(path.basename(process.cwd())) }
);
this.fs.copyTpl(
this.templatePath('LICENSE'),
this.destinationPath('LICENSE'),
{ year: today.getFullYear().toPrecision(4) }
this.templatePath("Makefile"),
this.destinationPath("Makefile"),
{ appname: _.kebabCase(path.basename(process.cwd())) }
);
}
},

install: {
npmInstall: function() {
const generator = this;
if (shelljs.which('yarn')) {
if (shelljs.which("yarn")) {
generator.yarnInstall();
} else {
generator.npmInstall(null, {
skipInstall: this.options['skip-install']
skipInstall: this.options["skip-install"]
});
}
}
Expand Down
21 changes: 0 additions & 21 deletions generators/app/templates/LICENSE

This file was deleted.

8 changes: 8 additions & 0 deletions generators/app/templates/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
setup:
docker volume create <%= appname %>-nodemodules

install:
docker-compose -f docker-compose.builder.yml run --rm install

build-watch:
docker-compose up
2 changes: 1 addition & 1 deletion generators/app/templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

# Using this module in other modules

Here is a quick example of how this module can be used in other modules. The [TypeScript Module Resolution Logic](https://www.typescriptlang.org/docs/handbook/module-resolution.html) makes it quite easy. The file `src/index.ts` is a [barrel](https://basarat.gitbooks.io/typescript/content/docs/tips/barrel.html) that re-exports selected exports from other files. The _package.json_ file contains `main` attribute that points to the generated `lib/index.js` file and `typings` attribute that points to the generated `lib/index.d.ts` file.
Here is a quick example of how this module can be used in other modules. The [TypeScript Module Resolution Logic](https://www.typescriptlang.org/docs/handbook/module-resolution.html) makes it quite easy. The file `src/index.ts` is a [barrel](https://basarat.gitbooks.io/typescript/content/docs/tips/barrel.html) that re-exports selected exports from other files. The _package.json_ file contains `main` attribute that points to the generated `<%= buildpath %>/index.js` file and `typings` attribute that points to the generated `<%= buildpath %>/index.d.ts` file.

> If you are planning to have code in multiple files (which is quite natural for a NodeJS module) that users can import, make sure you update `src/index.ts` file appropriately.

Expand Down
28 changes: 15 additions & 13 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "<%= appname %>",
"version": "0.0.0",
"description": "<%= appname %>",
"license": "MIT",
"license": "UNLICENSED",
"repository": "",
"author": {
"name": "",
Expand All @@ -13,32 +13,34 @@
""
],
"files": [
"lib"
"<%= buildpath %>"
],
"main": "lib/index",
"types": "lib/index",
"main": "<%= buildpath %>/index",
"types": "<%= buildpath %>/index",
"scripts": {
"clean": "rimraf lib && rimraf coverage",
"clean": "rimraf <%= buildpath %> && rimraf coverage",
"format": "prettier --write \"{src,__tests__}/**/*.ts\" --single-quote --trailing-comma es5",
"lint": "tslint --force --format verbose \"src/**/*.ts\"",
"prepublishOnly": "npm run build",
"start": "node ./<%= buildpath %>/index.js",
"prebuild": "npm run clean && npm run format && npm run lint && echo Using TypeScript && tsc --version",
"build": "tsc --pretty",
"build:watch": "nodemon --legacy-watch src/index.ts",
"test": "jest",
"coverage": "jest --coverage",
"watch": "npm run build -- --watch",
"watch:test": "jest --watch"
"test:watch": "jest --watch",
"coverage": "jest --coverage"
},
"dependencies": {},
"devDependencies": {
"@types/jest": "^23.3.3",
"@types/node": "^10.11.4",
"@types/jest": "^24.0.13",
"@types/node": "^10.14.7",
"coveralls": "^3.0.2",
"jest": "^23.6.0",
"jest": "^24.8.0",
"nodemon": "^1.19.0",
"prettier": "^1.14.3",
"rimraf": "^2.6.2",
"ts-jest": "^23.10.3",
"ts-node": "^7.0.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.1.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.15.0",
"typescript": "^3.1.1"
Expand Down
10 changes: 5 additions & 5 deletions generators/app/templates/_package_ava.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
""
],
"files": [
"lib"
"<%= buildpath %>"
],
"main": "lib/index",
"types": "lib/index",
"main": "<%= buildpath %>/index",
"types": "<%= buildpath %>/index",
"scripts": {
"clean": "rimraf lib && rimraf coverage && rimraf .nyc_output && rimraf lib_test",
"clean": "rimraf <%= buildpath %> && rimraf coverage && rimraf .nyc_output && rimraf lib_test",
"format": "prettier --write \"{src,test}/**/*.ts\"",
"lint": "tslint --force --format verbose \"src/**/*.ts\"",
"prepublishOnly": "npm run build",
"prepublishOnly": "npm run <%= buildpath %>",
"prebuild": "npm run clean && npm run format && npm run lint && echo Using TypeScript && tsc --version",
"build": "tsc --pretty && tsc -p tsconfig.test.json --pretty",
"test": "npm run clean && tsc -p tsconfig.test.json --pretty && nyc --exclude \"**/*-spec.js\" ava \"**/*-spec.js\" --verbose",
Expand Down
Loading