Skip to content

Commit

Permalink
DIG-185: yo @dizmo/module --typescript --upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
hsk81 committed Jul 30, 2018
1 parent e086c75 commit 7740352
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 143 deletions.
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
loglevel=silent
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ npm run build
```sh
npm run lint
```
#### with fixes:
```sh
npm run lint:fix
```
### Test
```sh
npm run test
Expand Down
1 change: 0 additions & 1 deletion cli/cli-spinner.js

This file was deleted.

92 changes: 62 additions & 30 deletions cli/run-build.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,69 @@
let child_process = require('child_process'),
let ps = require('child_process'),
fs = require('fs');

let run_script = function () {
child_process.spawn('npx', [
'tsc'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('close', function (code) {
if (code === 0) {
child_process.spawn('npx', [
'babel', 'dist', '-d', 'dist', '--presets=env', '-s'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
});
}
});
};
function argv(key, value) {
let argv = require('yargs')
.default('lint', true)
.argv;
if (argv[key] !== undefined) {
return argv[key];
} else {
return value;
}
}

fs.access('./node_modules', function (error) {
if (error) {
let Spinner = require('./cli-spinner').Spinner,
spinner = new Spinner('%s fetching dependencies: .. ');
let npm_install = child_process.spawn('npm', [
'install'
], {
shell: true, stdio: 'ignore'
function npm_install(flag) {
if (flag) {
ps.spawn('npm', ['install'], {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npm_lint(code);
});
npm_install.on('close', function () {
spinner.stop(true);
run_script();
} else {
npm_lint(0);
}
}

function npm_lint(code) {
if (code === 0 && argv('lint') === true) {
ps.spawn('npm', [
'run-script', '--', 'lint'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npx_tsc(code);
});
spinner.start();
} else {
run_script();
npx_tsc(code);
}
});
}

function npx_tsc(code) {
if (code === 0) {
ps.spawn('npx', [
'tsc'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npx_babel(code);
});
} else {
npx_babel(code);
}
};

function npx_babel(code) {
if (code === 0) {
ps.spawn('npx', [
'babel', 'dist', '-d', 'dist', '--presets=env', '-s'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
process.exit(code);
});
} else {
process.exit(code);
}
};

fs.access('./node_modules', npm_install);
47 changes: 24 additions & 23 deletions cli/run-cover.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
let child_process = require('child_process'),
let ps = require('child_process'),
fs = require('fs');

let run_script = function () {
child_process.spawn('npx', [
'istanbul', 'cover', '_mocha', 'test/*.js'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
});
};

fs.access('./node_modules', function (error) {
if (error) {
let Spinner = require('./cli-spinner').Spinner,
spinner = new Spinner('%s fetching dependencies: .. ');
let npm_install = child_process.spawn('npm', [
'install'
], {
shell: true, stdio: 'ignore'
function npm_install(flag) {
if (flag) {
ps.spawn('npm', ['install'], {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npx_istanbul(code);
});
npm_install.on('close', function () {
spinner.stop(true);
run_script();
} else {
npx_istanbul(0);
}
}

function npx_istanbul(code) {
if (code === 0) {
ps.spawn('npx', [
'istanbul', 'cover', '_mocha', 'test/*.js'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
process.exit(code);
});
spinner.start();
} else {
run_script();
process.exit(code);
}
});
}

fs.access('./node_modules', npm_install);
29 changes: 0 additions & 29 deletions cli/run-lint-fix.js

This file was deleted.

47 changes: 24 additions & 23 deletions cli/run-lint.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
let child_process = require('child_process'),
let ps = require('child_process'),
fs = require('fs');

let run_script = function () {
child_process.spawn('npx', [
'tslint', '--config', 'tslint.json', "'lib/**/*.ts'"
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
});
};

fs.access('./node_modules', function (error) {
if (error) {
let Spinner = require('./cli-spinner').Spinner,
spinner = new Spinner('%s fetching dependencies: .. ');
let npm_install = child_process.spawn('npm', [
'install'
], {
shell: true, stdio: 'ignore'
function npm_install(flag) {
if (flag) {
ps.spawn('npm', ['install'], {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npx_tslint(code);
});
npm_install.on('close', function () {
spinner.stop(true);
run_script();
} else {
npx_tslint(0);
}
}

function npx_tslint(code) {
if (code === 0) {
ps.spawn('npx', [
'tslint', '--config', 'tslint.json', "'lib/**/*.ts'"
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
process.exit(code);
});
spinner.start();
} else {
run_script();
process.exit(code);
}
});
}

fs.access('./node_modules', npm_install);
47 changes: 24 additions & 23 deletions cli/run-test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
let child_process = require('child_process'),
let ps = require('child_process'),
fs = require('fs');

let run_script = function () {
child_process.spawn('npx', [
'mocha'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
});
};

fs.access('./node_modules', function (error) {
if (error) {
let Spinner = require('./cli-spinner').Spinner,
spinner = new Spinner('%s fetching dependencies: .. ');
let npm_install = child_process.spawn('npm', [
'install'
], {
shell: true, stdio: 'ignore'
function npm_install(flag) {
if (flag) {
ps.spawn('npm', ['install'], {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
npx_mocha(code);
});
npm_install.on('close', function () {
spinner.stop(true);
run_script();
} else {
npx_mocha(0);
}
}

function npx_mocha(code) {
if (code === 0) {
ps.spawn('npx', [
'mocha'
].concat(process.argv.slice(2)), {
shell: true, stdio: 'inherit'
}).on('exit', function (code) {
process.exit(code);
});
spinner.start();
} else {
run_script();
process.exit(code);
}
});
}

fs.access('./node_modules', npm_install);
10 changes: 5 additions & 5 deletions package-lock.json

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

10 changes: 5 additions & 5 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
"noUnusedParameters": true, /* Report errors on unused parameters. */
"noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
Expand All @@ -56,4 +56,4 @@
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
}
}
}

0 comments on commit 7740352

Please sign in to comment.