UNPKG

1.93 kBJavaScriptView Raw
1/*
2* adonis-mrm-preset
3*
4* (c) Harminder Virk <virk@adonisjs.com>
5*
6* For the full copyright and license information, please view the LICENSE
7* file that was distributed with this source code.
8*/
9
10const { json, install, uninstall } = require('mrm-core')
11const debug = require('debug')('adonis:mrm-package')
12
13class TsPreset {
14 constructor () {
15 this.dependencies = [
16 '@adonisjs/require-ts',
17 'typescript',
18 '@types/node',
19 'del-cli'
20 ]
21 }
22
23 /**
24 * Installing dependencies for a Typescript project
25 *
26 * @method install
27 *
28 * @param {Array} baseDependencies
29 *
30 * @return {void}
31 */
32 install (baseDependencies) {
33 const dependencies = baseDependencies.concat(this.dependencies)
34
35 debug('installing dependencies %o', dependencies)
36 install(dependencies)
37 }
38
39 /**
40 * Removing dependencies for a Typescript project
41 *
42 * @method uninstall
43 *
44 * @return {void}
45 */
46 uninstall () {
47 debug('removing dependencies %o', this.dependencies)
48 uninstall(this.dependencies)
49 }
50
51 /**
52 * Mutating the package file for a typescript project
53 *
54 * @method up
55 *
56 * @param {Object} pkgFile
57 *
58 * @return {void}
59 */
60 up (pkgFile) {
61 pkgFile.setScript('clean', 'del build')
62 pkgFile.setScript('compile', 'npm run lint && npm run clean && tsc')
63 pkgFile.setScript('build', 'npm run compile')
64 pkgFile.setScript('prepublishOnly', 'npm run build')
65
66 /**
67 * Set files to publish along with the main file
68 */
69 if (!pkgFile.get('main')) {
70 pkgFile.set('main', 'build/index.js')
71 }
72
73 if (!pkgFile.get('files')) {
74 pkgFile.set('files', [
75 'build/src',
76 'build/index.d.ts',
77 'build/index.js'
78 ])
79 }
80
81 debug('creating files %o', ['tsconfig.json'])
82 json('tsconfig.json').merge({ extends: './node_modules/@adonisjs/mrm-preset/_tsconfig' }).save()
83 }
84}
85
86module.exports = new TsPreset()