added --watch option
This commit is contained in:
@ -7,7 +7,7 @@ import * as early from 'early'
|
||||
early.start('NPMTS')
|
||||
import * as plugins from './npmts.plugins'
|
||||
import * as paths from './npmts.paths'
|
||||
import {promisechain} from './npmts.promisechain'
|
||||
import * as promisechain from './npmts.promisechain'
|
||||
early.stop()
|
||||
.then(() => {
|
||||
let npmtsProjectInfo = new plugins.projectinfo.ProjectinfoNpm(paths.npmtsPackageRoot)
|
||||
@ -16,11 +16,7 @@ early.stop()
|
||||
.then((argvArg) => {
|
||||
plugins.beautylog.figletSync('NPMTS')
|
||||
plugins.beautylog.info('npmts version: ' + npmtsProjectInfo.version)
|
||||
try {
|
||||
promisechain(argvArg)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
promisechain.run(argvArg).catch((err) => { console.log(err) })
|
||||
})
|
||||
|
||||
npmtsCli.addVersion(npmtsProjectInfo.version)
|
||||
|
@ -4,7 +4,7 @@ import paths = require('./npmts.paths')
|
||||
import {npmtsOra} from './npmts.promisechain'
|
||||
|
||||
export var run = function(configArg){
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
let config = configArg
|
||||
npmtsOra.text('now looking at ' + 'required assets'.yellow)
|
||||
if (config.cli === true) {
|
||||
|
@ -7,7 +7,8 @@ import {ProjectinfoNpm} from 'projectinfo'
|
||||
export let projectInfo: ProjectinfoNpm
|
||||
|
||||
let checkProjectTypings = (configArg) => {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('Check Module: Check Project Typings...')
|
||||
projectInfo = new ProjectinfoNpm(paths.cwd)
|
||||
if (typeof projectInfo.packageJson.typings === 'undefined') {
|
||||
plugins.beautylog.error(`please add typings field to package.json`)
|
||||
@ -33,7 +34,8 @@ const depcheckOptions = {
|
||||
}
|
||||
|
||||
let checkDependencies = (configArg) => {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('Check Module: Check Dependencies...')
|
||||
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
||||
ignoreDirs: [ // folder with these names will be ignored
|
||||
'test',
|
||||
@ -47,28 +49,29 @@ let checkDependencies = (configArg) => {
|
||||
})
|
||||
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||
for (let item of unused.dependencies) {
|
||||
plugins.beautylog.warn(`Watch out: unused dependency ${item.red}`)
|
||||
};
|
||||
for (let item of unused.missing) {
|
||||
plugins.beautylog.error(`unused devDependency ${item.red}`)
|
||||
};
|
||||
plugins.beautylog.warn(`Watch out: unused dependency "${item}"`)
|
||||
}
|
||||
for (let item in unused.missing) {
|
||||
plugins.beautylog.error(`unused devDependency "${item}"`)
|
||||
}
|
||||
if (unused.missing.length > 0) {
|
||||
plugins.beautylog.info('exiting due to missing dependencies in package.json')
|
||||
process.exit(1)
|
||||
}
|
||||
for (let item of unused.invalidFiles) {
|
||||
for (let item in unused.invalidFiles) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
|
||||
};
|
||||
for (let item of unused.invalidDirs) {
|
||||
for (let item in unused.invalidDirs) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`)
|
||||
};
|
||||
}
|
||||
done.resolve(configArg)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let checkDevDependencies = (configArg) => {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('Check Module: Check devDependencies...')
|
||||
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
||||
ignoreDirs: [ // folder with these names will be ignored
|
||||
'ts',
|
||||
@ -83,18 +86,18 @@ let checkDevDependencies = (configArg) => {
|
||||
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||
for (let item of unused.devDependencies) {
|
||||
plugins.beautylog.log(`unused devDependency ${item.red}`)
|
||||
};
|
||||
for (let item of unused.missing) {
|
||||
}
|
||||
for (let item in unused.missing) {
|
||||
plugins.beautylog.error(`unused devDependency ${item.red}`)
|
||||
};
|
||||
}
|
||||
if (unused.missing.length > 0) {
|
||||
plugins.beautylog.info('exiting due to missing dependencies in package.json')
|
||||
process.exit(1)
|
||||
}
|
||||
for (let item of unused.invalidFiles) {
|
||||
for (let item in unused.invalidFiles) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
|
||||
}
|
||||
for (let item of unused.invalidDirs) {
|
||||
for (let item in unused.invalidDirs) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`)
|
||||
}
|
||||
done.resolve(configArg)
|
||||
@ -103,18 +106,20 @@ let checkDevDependencies = (configArg) => {
|
||||
}
|
||||
|
||||
let checkNodeVersion = (configArg) => {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('checking node version')
|
||||
done.resolve(configArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
export let run = (configArg) => {
|
||||
let done = plugins.Q.defer()
|
||||
npmtsOra.text('running project checks...')
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('Check Module: ...')
|
||||
checkProjectTypings(configArg)
|
||||
.then(checkDependencies)
|
||||
.then(checkDevDependencies)
|
||||
.then(checkNodeVersion)
|
||||
.then(done.resolve)
|
||||
.catch((err) => { console.log(err) })
|
||||
return done.promise
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ let removePages = function(){
|
||||
|
||||
export let run = function(configArg){
|
||||
npmtsOra.text('cleaning up from previous builds...')
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
removeDist()
|
||||
.then(removePages)
|
||||
.then(function(){
|
||||
|
@ -4,7 +4,7 @@ import paths = require('./npmts.paths')
|
||||
import {npmtsOra} from './npmts.promisechain'
|
||||
|
||||
export let run = function (configArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
let config = configArg
|
||||
npmtsOra.text('now compiling ' + 'TypeScript'.yellow)
|
||||
plugins.tsn.compileGlobStringObject(config.ts,config.tsOptions,paths.cwd)
|
||||
|
@ -13,12 +13,13 @@ export interface INpmtsConfig {
|
||||
test: boolean,
|
||||
testTs: any,
|
||||
ts: any,
|
||||
tsOptions: any
|
||||
tsOptions: any,
|
||||
watch: boolean
|
||||
|
||||
};
|
||||
|
||||
export var run = function (argvArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
let defaultConfig: INpmtsConfig = {
|
||||
argv: undefined,
|
||||
coverageTreshold: 70,
|
||||
@ -27,7 +28,8 @@ export var run = function (argvArg) {
|
||||
test: true,
|
||||
testTs: {},
|
||||
ts: {},
|
||||
tsOptions: {}
|
||||
tsOptions: {},
|
||||
watch: false
|
||||
}
|
||||
|
||||
// mix with configfile
|
||||
@ -70,6 +72,9 @@ export var run = function (argvArg) {
|
||||
if (config.argv.nodocs) {
|
||||
config.docs = false
|
||||
};
|
||||
if (config.argv.watch) {
|
||||
config.watch = true
|
||||
};
|
||||
|
||||
plugins.beautylog.ok('build options are ready!')
|
||||
done.resolve(config)
|
||||
|
@ -15,8 +15,9 @@ export import lodash = require('lodash')
|
||||
export import npmextra = require('npmextra')
|
||||
export import projectinfo = require('projectinfo')
|
||||
export import path = require('path')
|
||||
export import Q = require('q')
|
||||
export import q = require('q')
|
||||
export import shelljs = require('shelljs')
|
||||
export import smartchok = require('smartchok')
|
||||
export import smartcli = require('smartcli')
|
||||
export import smartcov = require('smartcov')
|
||||
export import smartenv = require('smartenv')
|
||||
|
@ -4,16 +4,17 @@ import {Ora} from 'beautylog'
|
||||
|
||||
export let npmtsOra = new Ora('setting up TaskChain','cyan')
|
||||
|
||||
import NpmtsAssets = require('./npmts.assets')
|
||||
import NpmtsCheck = require('./npmts.check')
|
||||
import NpmtsClean = require('./npmts.clean')
|
||||
import NpmtsCompile = require('./npmts.compile')
|
||||
import NpmtsTypeDoc = require('./npmts.typedoc')
|
||||
import NpmtsOptions = require('./npmts.options')
|
||||
import NpmtsTests = require('./npmts.tests')
|
||||
import * as NpmtsAssets from './npmts.assets'
|
||||
import * as NpmtsCheck from './npmts.check'
|
||||
import * as NpmtsClean from './npmts.clean'
|
||||
import * as NpmtsCompile from './npmts.compile'
|
||||
import * as NpmtsTypeDoc from './npmts.typedoc'
|
||||
import * as NpmtsOptions from './npmts.options'
|
||||
import * as NpmtsTests from './npmts.tests'
|
||||
import * as NpmtsWatch from './npmts.watch'
|
||||
|
||||
export let promisechain = function(argvArg){
|
||||
let done = plugins.Q.defer()
|
||||
export let run = function(argvArg){
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.start()
|
||||
NpmtsOptions.run(argvArg)
|
||||
.then(NpmtsClean.run)
|
||||
@ -22,6 +23,7 @@ export let promisechain = function(argvArg){
|
||||
.then(NpmtsAssets.run)
|
||||
.then(NpmtsTypeDoc.run)
|
||||
.then(NpmtsTests.run)
|
||||
.then(NpmtsWatch.run)
|
||||
.then(function(configArg){
|
||||
let shipString = '' +
|
||||
'\n' +
|
||||
@ -43,7 +45,7 @@ export let promisechain = function(argvArg){
|
||||
} else {
|
||||
plugins.beautylog.success('Done!')
|
||||
}
|
||||
done.resolve()
|
||||
done.resolve(configArg)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import { npmtsOra } from './npmts.promisechain'
|
||||
let mocha = function (configArg) {
|
||||
npmtsOra.text('Instrumentalizing and testing transpiled JS')
|
||||
npmtsOra.end() // end npmtsOra for tests.
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
plugins.gulp.src([plugins.path.join(paths.cwd, 'dist/*.js')])
|
||||
.pipe(plugins.g.sourcemaps.init())
|
||||
.pipe(plugins.g.babel({
|
||||
@ -47,7 +47,7 @@ let mocha = function (configArg) {
|
||||
}
|
||||
|
||||
let coverage = function (configArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
plugins.smartcov.get.percentage(plugins.path.join(paths.coverageDir, 'lcov.info'), 2)
|
||||
.then(function (percentageArg) {
|
||||
if (percentageArg >= configArg.coverageTreshold) {
|
||||
@ -71,7 +71,7 @@ let coverage = function (configArg) {
|
||||
}
|
||||
|
||||
export let run = function (configArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
let config = configArg
|
||||
if (config.test === true) {
|
||||
npmtsOra.text('now starting tests')
|
||||
|
@ -6,7 +6,7 @@ import { npmtsOra } from './npmts.promisechain'
|
||||
import { projectInfo } from './npmts.check'
|
||||
|
||||
let genTypeDoc = function (configArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
npmtsOra.text('now generating ' + 'TypeDoc documentation'.yellow)
|
||||
plugins.beautylog.log('TypeDoc Output:')
|
||||
plugins.gulp.src(plugins.path.join(paths.tsDir, '**/*.ts'))
|
||||
@ -32,7 +32,7 @@ let genTypeDoc = function (configArg) {
|
||||
}
|
||||
|
||||
export let run = function (configArg) {
|
||||
let done = plugins.Q.defer()
|
||||
let done = plugins.q.defer()
|
||||
if (configArg.docs) {
|
||||
genTypeDoc(configArg)
|
||||
.then(() => {
|
||||
|
25
ts/npmts.watch.ts
Normal file
25
ts/npmts.watch.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import * as plugins from './npmts.plugins'
|
||||
import * as promisechain from './npmts.promisechain'
|
||||
let npmtsSmartchok: plugins.smartchok.Smartchok = null
|
||||
|
||||
export let run = (configArg) => {
|
||||
let done = plugins.q.defer()
|
||||
if (configArg.watch && npmtsSmartchok === null) {
|
||||
let pathsToWatch: string[] = []
|
||||
for (let key in configArg.ts) {
|
||||
pathsToWatch.push(key)
|
||||
}
|
||||
npmtsSmartchok = new plugins.smartchok.Smartchok(pathsToWatch)
|
||||
npmtsSmartchok.getObservableFor('change').then((changeObservableArg) => {
|
||||
plugins.beautylog.info('now watching...')
|
||||
changeObservableArg.subscribe(() => {
|
||||
promisechain.run(configArg)
|
||||
})
|
||||
})
|
||||
npmtsSmartchok.start()
|
||||
done.resolve(configArg)
|
||||
} else {
|
||||
done.resolve(configArg)
|
||||
}
|
||||
return done.promise
|
||||
}
|
Reference in New Issue
Block a user