Skip to content

Commit

Permalink
Merge pull request #37 from nobrainr/feat/add-template-typescript-server
Browse files Browse the repository at this point in the history
feat: base scaffolding of typescript server module
  • Loading branch information
emyann authored Sep 28, 2018
2 parents 12e0798 + 2e64e7e commit a7c44ae
Show file tree
Hide file tree
Showing 13 changed files with 2,839 additions and 10 deletions.
24 changes: 24 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ jobs:
- run: npm run build
- run: npm test

test-preset-node8:
docker:
- image: circleci/node:10-browsers
working_directory: ~/repo
steps:
- checkout
- run: npm install
- run: npm run build
- run: cd packages/e2e && npm run test:preset
test-preset-node10:
docker:
- image: circleci/node:10-browsers
working_directory: ~/repo
steps:
- checkout
- run: npm install
- run: npm run build
- run: cd packages/e2e && npm run test:preset

publish-job:
docker:
- image: circleci/node:10
Expand All @@ -41,12 +60,17 @@ workflows:
test:
jobs:
- test-job-8
- test-preset-node8
- test-job-10
- test-preset-node10

- publish-job:
filters:
branches:
only:
- master
requires:
- test-job-8
- test-preset-node8
- test-job-10
- test-preset-node10
29 changes: 22 additions & 7 deletions packages/cli/createTsLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,20 @@ const packageJson = require('./package.json');

let projectName;

const PRESETS = {
default: ['typescript_universal', 'webpack', 'karma_jasmine'],
server: ['typescript_server']
};

const program = new commander.Command(packageJson.name)
.version(packageJson.version)
.option(
'-p, --preset [name]',
`[ default | server ]
* default: Typescript, Webpack, Karma, Jasmine
* server: Typescript, ts-node, nodemon`,
'default'
)
.arguments('<project-directory>')
.usage(`${chalk.green('<project-directory>')}`)
.action(name => {
Expand All @@ -36,9 +48,9 @@ if (typeof projectName === 'undefined') {
process.exit(1);
}

createApp(projectName);
createApp(projectName, program.preset);

function createApp(name) {
function createApp(name, preset) {
const root = path.resolve(name);
const appName = path.basename(root);

Expand All @@ -51,7 +63,6 @@ function createApp(name) {
console.log(`Creating a new TypeScript library in ${chalk.green(root)}.`);
console.log();

const originalDirectory = process.cwd();
process.chdir(root);

if (!semver.satisfies(process.version, '>=6.0.0')) {
Expand All @@ -74,23 +85,23 @@ function createApp(name) {
);
}
}
run(root, appName, originalDirectory);
run(root, appName, preset);
}

async function run(root, appName, originalDirectory) {
async function run(root, appName, preset) {
function installTemplate(templateName) {
try {
console.log(`loading ${templateName} template in ${path.resolve(__dirname)}`);
const res = require('child_process')
.execSync(`npm install ${templateName}`, { cwd: path.resolve(__dirname) })
.execSync(`npm install -D ${templateName}`, { cwd: path.resolve(__dirname) })
.toString()
.trim();
console.log(`${templateName} loaded successfully`);
} catch (e) {
console.log(`${templateName} err`);
}
}
const templateName = '@nobrainr/typescript_universal-webpack-karma_jasmine';
const templateName = getTemplateNameFromPreset(PRESETS[preset]);
const templatePath = path.resolve(__dirname, 'node_modules', templateName);
if (!fs.existsSync(templatePath)) {
try {
Expand All @@ -113,6 +124,10 @@ async function run(root, appName, originalDirectory) {
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
console.log('Installing packages. This might take a couple of minutes.');
return await install();

function getTemplateNameFromPreset(preset) {
return `@nobrainr/${preset.join('-')}`;
}
}

function install() {
Expand Down
5 changes: 5 additions & 0 deletions packages/cli/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"create-ts-lib": "./index.js"
},
"dependencies": {
"@nobrainr/typescript_server": "^1.0.0",
"chalk": "^2.4.1",
"commander": "^2.17.1",
"cross-spawn": "^6.0.5",
Expand Down
7 changes: 4 additions & 3 deletions packages/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"private": true,
"main": "index.js",
"scripts": {
"pretest": "rimraf app",
"test": "create-ts-lib app && cd app && npm run build && npm run test"
"clean": "rimraf app",
"test": "npm run clean && create-ts-lib app && cd app && npm run build && npm run test",
"test:preset": "npm run clean && create-ts-lib --preset server app && cd app && npm run build && ls -l ./dist"
},
"dependencies": {
"create-ts-lib": "^0.4.0",
Expand All @@ -16,6 +17,6 @@
"author": "",
"license": "ISC",
"devDependencies": {
"create-ts-lib": "0.4.0"
"create-ts-lib": "^0.4.0"
}
}
8 changes: 8 additions & 0 deletions packages/templates/typescript_server/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Build results
dist/
typings/**/*

# Others
~$*
*~
node_modules/
7 changes: 7 additions & 0 deletions packages/templates/typescript_server/nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"watch": ["src/**/*.ts"],
"execMap": {
"ts": "ts-node --compilerOptions '{\"module\":\"commonjs\"}'",
"js": "node"
}
}
Loading

0 comments on commit a7c44ae

Please sign in to comment.