-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): clone @adonisjs/ace into @tensei/cli package
- Loading branch information
Showing
54 changed files
with
8,297 additions
and
865 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/usr/bin/env node | ||
|
||
import { Kernel, handleError, serve, app } from './src' | ||
|
||
// Set cli env variable | ||
process.env.TENSEI_MODE = 'cli' | ||
;(async () => { | ||
let tensei = await app() | ||
|
||
const { commands } = tensei.ctx | ||
|
||
const kernel = new Kernel(tensei) | ||
|
||
kernel.register([serve, ...commands]) | ||
|
||
kernel.flag( | ||
'help', | ||
(value, _, command) => { | ||
if (!value) { | ||
return | ||
} | ||
|
||
kernel.printHelp(command) | ||
process.exit(0) | ||
}, | ||
{ type: 'boolean' } | ||
) | ||
|
||
kernel.onExit(() => { | ||
if (kernel.error) { | ||
handleError(kernel.error) | ||
} | ||
process.exit(kernel.exitCode) | ||
}) | ||
|
||
kernel.handle(process.argv.splice(2)) | ||
})() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require('@adonisjs/require-ts/build/register') | ||
|
||
const { configure } = require('japa') | ||
configure({ | ||
files: ['test/**/*.spec.ts'], | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* @adonisjs/assembler | ||
* | ||
* (c) Harminder Virk <virk@adonisjs.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
import { join } from 'path' | ||
import tsStatic from 'typescript' | ||
import { logger as uiLogger } from '@poppinss/cliui' | ||
import { TypescriptCompiler } from '@poppinss/chokidar-ts' | ||
import { resolveFrom } from '@poppinss/utils/build/helpers' | ||
|
||
const TSCONFIG_FILE_NAME = 'tsconfig.json' | ||
const DEFAULT_BUILD_DIR = 'build' | ||
|
||
/** | ||
* Exposes the API to work with the Typescript compiler API | ||
*/ | ||
export class Ts { | ||
/** | ||
* Reference to the typescript compiler | ||
*/ | ||
public tsCompiler = new TypescriptCompiler( | ||
this.appRoot, | ||
this.tsconfig, | ||
require(resolveFrom(this.appRoot, 'typescript/lib/typescript')) | ||
) | ||
|
||
constructor( | ||
private appRoot: string, | ||
private logger: typeof uiLogger, | ||
private tsconfig = TSCONFIG_FILE_NAME | ||
) {} | ||
|
||
/** | ||
* Render ts diagnostics | ||
*/ | ||
public renderDiagnostics( | ||
diagnostics: tsStatic.Diagnostic[], | ||
host: tsStatic.CompilerHost | ||
) { | ||
console.error( | ||
this.tsCompiler.ts.formatDiagnosticsWithColorAndContext(diagnostics, host) | ||
) | ||
} | ||
|
||
/** | ||
* Parses the tsconfig file | ||
*/ | ||
public parseConfig(): undefined | tsStatic.ParsedCommandLine { | ||
const { error, config } = this.tsCompiler.configParser().parse() | ||
|
||
if (error) { | ||
this.logger.error(`unable to parse ${this.tsconfig}`) | ||
this.renderDiagnostics([error], this.tsCompiler.ts.createCompilerHost({})) | ||
return | ||
} | ||
|
||
if (config && config.errors.length) { | ||
this.logger.error(`unable to parse ${this.tsconfig}`) | ||
this.renderDiagnostics( | ||
config.errors, | ||
this.tsCompiler.ts.createCompilerHost(config.options) | ||
) | ||
return | ||
} | ||
|
||
config!.options.rootDir = config!.options.rootDir || this.appRoot | ||
config!.options.outDir = | ||
config!.options.outDir || join(this.appRoot, DEFAULT_BUILD_DIR) | ||
return config | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { command } from '@tensei/common' | ||
|
||
export const help = command('help') | ||
.describe('See help for all commands.') | ||
.run(function () { | ||
this.kernel.printHelp() | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import { command } from '@tensei/common' | ||
import { getWatcherHelpers } from '@adonisjs/require-ts' | ||
import { logger as uiLogger, sticker } from '@poppinss/cliui' | ||
import { app, kill } from '../utils/get-app' | ||
import { Ts } from './Compiler/Ts' | ||
|
||
export const serve = command('serve') | ||
.stayAlive() | ||
.describe('Start the HTTP server and watch for file changes.') | ||
.run(async function () { | ||
const ts = new Ts(process.cwd(), this.logger) | ||
|
||
console.log('========@process.cwd()', process.cwd()) | ||
|
||
const config = ts.parseConfig() | ||
|
||
if (!config) { | ||
this.logger.warning( | ||
'Cannot start watcher because of errors in the config file' | ||
) | ||
|
||
return | ||
} | ||
|
||
const watcher = ts.tsCompiler.watcher(config, 'raw') | ||
|
||
watcher.on('watcher:ready', () => { | ||
this.logger.info('watching file system for changes') | ||
}) | ||
|
||
await this.kernel.application.listen() | ||
|
||
watcher.on('source:change', async ({ absPath, relativePath }) => { | ||
this.logger.action('update').succeeded(relativePath) | ||
|
||
let tensei = await app() | ||
|
||
this.logger.info('Restarting server ...') | ||
|
||
await kill(this.kernel.application.server) | ||
|
||
this.kernel.application = tensei | ||
|
||
await this.kernel.application.listen() | ||
|
||
this.logger.success('Server restarted successfully.') | ||
}) | ||
}) |
Oops, something went wrong.