-
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): add build command to @tensei/cli
- Loading branch information
Showing
36 changed files
with
548 additions
and
5,124 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,27 @@ | ||
{ | ||
"name": "@examples/typescript", | ||
"version": "0.9.1", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@mikro-orm/sqlite": "^4.4.0", | ||
"@tensei/cms": "^0.9.1", | ||
"@tensei/core": "^0.9.1", | ||
"@tensei/graphql": "^0.9.1", | ||
"@tensei/mde": "^0.9.1", | ||
"@tensei/media": "^0.9.1", | ||
"@tensei/social-auth": "^0.9.1" | ||
}, | ||
"scripts": { | ||
"example:dev": "yarn ts-node-dev --respawn src/index.ts", | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^15.12.4", | ||
"nodemon": "^2.0.7", | ||
"ts-node": "^10.0.0", | ||
"ts-node-dev": "^1.1.8", | ||
"typescript": "^4.3.4" | ||
}, | ||
"private": true | ||
"name": "@examples/typescript", | ||
"version": "0.9.1", | ||
"main": "src/index.ts", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@mikro-orm/sqlite": "^4.4.0", | ||
"@tensei/cms": "^0.9.1", | ||
"@tensei/core": "^0.9.1", | ||
"@tensei/graphql": "^0.9.1", | ||
"@tensei/mde": "^0.9.1", | ||
"@tensei/media": "^0.9.1", | ||
"@tensei/social-auth": "^0.9.1" | ||
}, | ||
"scripts": { | ||
"example:dev": "yarn ts-node-dev --respawn src/index.ts", | ||
"build": "tsc" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^15.12.4", | ||
"nodemon": "^2.0.7", | ||
"ts-node": "^10.0.0", | ||
"ts-node-dev": "^1.1.8", | ||
"typescript": "^4.3.4" | ||
}, | ||
"private": true | ||
} |
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
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,55 @@ | ||
import hasYarn from 'has-yarn' | ||
import { command } from '@tensei/common' | ||
import { getProjectDirectory } from '../utils/get-app' | ||
|
||
import { Compiler } from './Compiler/Compiler' | ||
|
||
export const build = command('build') | ||
.flag({ | ||
name: 'production', | ||
alias: 'prod', | ||
description: 'Build for production', | ||
type: 'boolean' | ||
}) | ||
.flag({ | ||
name: 'ignoreTsErrors', | ||
description: 'Ignore typescript errors and complete the build process.', | ||
type: 'boolean' | ||
}) | ||
.flag({ | ||
name: 'client', | ||
description: 'Select a package manager (npm or yarn).', | ||
type: 'string' | ||
}) | ||
.describe('Compile project from Typescript to Javascript.') | ||
.run(async function () { | ||
const appRoot = getProjectDirectory() | ||
|
||
const client = this.flagValues.client || hasYarn(appRoot) ? 'yarn' : 'npm' | ||
|
||
if (client !== 'npm' && client !== 'yarn') { | ||
this.logger.warning('--client must be set to "npm" or "yarn"') | ||
this.exitCode = 1 | ||
return | ||
} | ||
|
||
const stopOnError = !this.flagValues.ignoreTsErrors | ||
|
||
try { | ||
const compiler = new Compiler(appRoot, this.logger, 'tsconfig.json') | ||
|
||
const compiled = this.flagValues.production | ||
? await compiler.compileForProduction(stopOnError, client) | ||
: await compiler.compile(stopOnError) | ||
|
||
/** | ||
* Set exitCode based upon the compiled status | ||
*/ | ||
if (!compiled) { | ||
this.exitCode = 1 | ||
} | ||
} catch (error) { | ||
this.logger.fatal(error) | ||
this.exitCode = 1 | ||
} | ||
}) |
Oops, something went wrong.