now modularized, implements #11
This commit is contained in:
27
ts/mod00/index.ts
Normal file
27
ts/mod00/index.ts
Normal file
@ -0,0 +1,27 @@
|
||||
/* ------------------------------------------
|
||||
* This module compiles TypeScript files
|
||||
* -------------------------------------------- */
|
||||
import * as q from 'q'
|
||||
|
||||
import { npmtsOra } from '../npmts.log'
|
||||
import { INpmtsConfig } from '../npmts.config'
|
||||
|
||||
import * as plugins from './mod00.plugins'
|
||||
|
||||
import * as NpmtsAssets from './mod00.assets'
|
||||
import * as NpmtsCheck from './mod00.check'
|
||||
import * as NpmtsClean from './mod00.clean'
|
||||
import * as NpmtsCompile from './mod00.compile'
|
||||
|
||||
export let run = function(configArg: INpmtsConfig): q.Promise<INpmtsConfig> {
|
||||
let done = q.defer<INpmtsConfig>()
|
||||
npmtsOra.text('starting TypeScript Compilation')
|
||||
NpmtsClean.run(configArg)
|
||||
.then(NpmtsCheck.run)
|
||||
.then(NpmtsCompile.run)
|
||||
.then(NpmtsAssets.run)
|
||||
.then(function(){
|
||||
done.resolve(configArg)
|
||||
})
|
||||
return done.promise
|
||||
}
|
25
ts/mod00/mod00.assets.ts
Normal file
25
ts/mod00/mod00.assets.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import * as q from 'q'
|
||||
|
||||
import paths = require('../npmts.paths')
|
||||
import { npmtsOra } from '../npmts.log'
|
||||
|
||||
import plugins = require('./mod00.plugins')
|
||||
import { projectInfo } from '../mod00/mod00.check'
|
||||
|
||||
export var run = function(configArg){
|
||||
let done = q.defer()
|
||||
let config = configArg
|
||||
npmtsOra.text('now looking at ' + 'required assets'.yellow)
|
||||
if (config.cli === true) {
|
||||
let mainJsPath = projectInfo.packageJson.main
|
||||
let cliJsString: string = plugins.smartfile.fs.toStringSync(plugins.path.join(paths.npmtsAssetsDir,'cli.js'))
|
||||
cliJsString = cliJsString.replace('{{pathToIndex}}',mainJsPath)
|
||||
plugins.smartfile.memory.toFsSync(cliJsString, plugins.path.join(paths.distDir,'cli.js'))
|
||||
plugins.beautylog.ok('installed CLI assets!')
|
||||
done.resolve(config)
|
||||
} else {
|
||||
plugins.beautylog.ok('No additional assets required!')
|
||||
done.resolve(config)
|
||||
}
|
||||
return done.promise
|
||||
}
|
127
ts/mod00/mod00.check.ts
Normal file
127
ts/mod00/mod00.check.ts
Normal file
@ -0,0 +1,127 @@
|
||||
import * as q from 'q'
|
||||
import { ProjectinfoNpm } from 'projectinfo'
|
||||
|
||||
import * as paths from '../npmts.paths'
|
||||
import { npmtsOra } from '../npmts.log'
|
||||
|
||||
import * as plugins from './mod00.plugins'
|
||||
|
||||
export let projectInfo: ProjectinfoNpm
|
||||
|
||||
let checkProjectTypings = (configArg) => {
|
||||
let done = 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`)
|
||||
process.exit(1)
|
||||
};
|
||||
done.resolve(configArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
const depcheckOptions = {
|
||||
ignoreBinPackage: false, // ignore the packages with bin entry
|
||||
parsers: { // the target parsers
|
||||
'*.ts': plugins.depcheck.parser.typescript
|
||||
},
|
||||
detectors: [ // the target detectors
|
||||
plugins.depcheck.detector.requireCallExpression,
|
||||
plugins.depcheck.detector.importDeclaration
|
||||
],
|
||||
specials: [ // the target special parsers
|
||||
plugins.depcheck.special.eslint,
|
||||
plugins.depcheck.special.webpack
|
||||
]
|
||||
}
|
||||
|
||||
let checkDependencies = (configArg) => {
|
||||
let done = q.defer()
|
||||
npmtsOra.text('Check Module: Check Dependencies...')
|
||||
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
||||
ignoreDirs: [ // folder with these names will be ignored
|
||||
'test',
|
||||
'dist',
|
||||
'bower_components'
|
||||
],
|
||||
ignoreMatches: [ // ignore dependencies that matches these globs
|
||||
'@types/*',
|
||||
'babel-preset-*'
|
||||
]
|
||||
})
|
||||
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||
for (let item of unused.dependencies) {
|
||||
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 in unused.invalidFiles) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
|
||||
};
|
||||
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 = q.defer()
|
||||
npmtsOra.text('Check Module: Check devDependencies...')
|
||||
let depcheckOptionsMerged = plugins.lodash.merge(depcheckOptions, {
|
||||
ignoreDirs: [ // folder with these names will be ignored
|
||||
'ts',
|
||||
'dist',
|
||||
'bower_components'
|
||||
],
|
||||
ignoreMatches: [ // ignore dependencies that matches these globs
|
||||
'@types/*',
|
||||
'babel-preset-*'
|
||||
]
|
||||
})
|
||||
plugins.depcheck(paths.cwd, depcheckOptionsMerged, (unused) => {
|
||||
for (let item of unused.devDependencies) {
|
||||
plugins.beautylog.log(`unused devDependency ${item.red}`)
|
||||
}
|
||||
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 in unused.invalidFiles) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse file ${item.red}`)
|
||||
}
|
||||
for (let item in unused.invalidDirs) {
|
||||
plugins.beautylog.warn(`Watch out: could not parse directory ${item.red}`)
|
||||
}
|
||||
done.resolve(configArg)
|
||||
})
|
||||
return done.promise
|
||||
}
|
||||
|
||||
let checkNodeVersion = (configArg) => {
|
||||
let done = q.defer()
|
||||
npmtsOra.text('checking node version')
|
||||
done.resolve(configArg)
|
||||
return done.promise
|
||||
}
|
||||
|
||||
export let run = (configArg) => {
|
||||
let done = 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
|
||||
}
|
47
ts/mod00/mod00.clean.ts
Normal file
47
ts/mod00/mod00.clean.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import * as q from 'q'
|
||||
import paths = require('../npmts.paths')
|
||||
|
||||
import { npmtsOra } from '../npmts.log'
|
||||
|
||||
import plugins = require('./mod00.plugins')
|
||||
|
||||
/**
|
||||
* removes the dist directory which will be entirely rebuild
|
||||
*/
|
||||
let removeDist = function () {
|
||||
npmtsOra.text('cleaning dist folder')
|
||||
return plugins.smartfile.fs.remove(paths.distDir)
|
||||
}
|
||||
|
||||
/**
|
||||
* remove .d.ts files from testDirctory
|
||||
*/
|
||||
let removeTestDeclarations = function () {
|
||||
let done = q.defer()
|
||||
plugins.smartfile.fs.listFileTree('./test/', '**/*.d.ts').then(fileArray => {
|
||||
let fileArrayToRemove = plugins.smartpath.transform.toAbsolute(fileArray, process.cwd() + '//test/')
|
||||
plugins.smartfile.fs.removeManySync(fileArrayToRemove)
|
||||
done.resolve()
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* remove old pages
|
||||
*/
|
||||
let removePages = function () {
|
||||
npmtsOra.text('cleaning pages folder')
|
||||
return plugins.smartfile.fs.remove(paths.pagesDir)
|
||||
}
|
||||
|
||||
export let run = function (configArg) {
|
||||
npmtsOra.text('cleaning up from previous builds...')
|
||||
let done = q.defer()
|
||||
removeDist()
|
||||
.then(removeTestDeclarations)
|
||||
.then(removePages)
|
||||
.then(function () {
|
||||
plugins.beautylog.ok('Cleaned up from previous builds!')
|
||||
done.resolve(configArg)
|
||||
})
|
||||
return done.promise
|
||||
}
|
23
ts/mod00/mod00.compile.ts
Normal file
23
ts/mod00/mod00.compile.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as q from 'q'
|
||||
|
||||
import * as paths from '../npmts.paths'
|
||||
import { npmtsOra } from '../npmts.log'
|
||||
|
||||
import * as plugins from './mod00.plugins'
|
||||
|
||||
export let run = function (configArg) {
|
||||
let done = q.defer()
|
||||
let config = configArg
|
||||
npmtsOra.text('now compiling ' + 'TypeScript'.yellow)
|
||||
plugins.tsn.compileGlobStringObject(config.ts,config.tsOptions,paths.cwd)
|
||||
.then(() => {
|
||||
plugins.beautylog.ok('compiled main TypeScript!')
|
||||
plugins.beautylog.log('now compiling tests!')
|
||||
return plugins.tsn.compileGlobStringObject(config.testTs,config.tsOptions,paths.cwd)
|
||||
})
|
||||
.then(function () {
|
||||
plugins.beautylog.ok('compiled all TypeScript!')
|
||||
done.resolve(config)
|
||||
}).catch(err => { console.log(err) })
|
||||
return done.promise
|
||||
}
|
13
ts/mod00/mod00.plugins.ts
Normal file
13
ts/mod00/mod00.plugins.ts
Normal file
@ -0,0 +1,13 @@
|
||||
export * from '../npmts.plugins'
|
||||
|
||||
import * as tsn from 'tsn'
|
||||
import * as shelljs from 'shelljs'
|
||||
import * as smartchok from 'smartchok'
|
||||
import * as smartstream from 'smartstream'
|
||||
|
||||
export {
|
||||
tsn,
|
||||
shelljs,
|
||||
smartchok,
|
||||
smartstream
|
||||
}
|
Reference in New Issue
Block a user