@athenna/tsconfig 4.8.2 → 4.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@athenna/tsconfig",
3
- "version": "4.8.2",
3
+ "version": "4.9.1",
4
4
  "description": "Exports the base TypeScript configuration for Athena applications and packages.",
5
5
  "license": "MIT",
6
6
  "author": "João Lenon <lenon@athenna.io>",
@@ -25,6 +25,8 @@
25
25
  ".": "./src/index.js",
26
26
  "./package": "./package.json",
27
27
  "./package.json": "./package.json",
28
+ "./tsc": "./src/tsc.js",
29
+ "./copyfiles": "./src/copyfiles.js",
28
30
  "./tsconfig.app.json": "./tsconfig.app.json",
29
31
  "./tsconfig.app-slim.json": "./tsconfig.app-slim.json",
30
32
  "./tsconfig.base.json": "./tsconfig.base.json",
@@ -34,6 +36,7 @@
34
36
  "dependencies": {
35
37
  "copyfiles": "^2.4.1",
36
38
  "cross-env": "^7.0.3",
39
+ "lodash": "^4.17.21",
37
40
  "reflect-metadata": "^0.1.13",
38
41
  "rimraf": "^5.0.5",
39
42
  "ts-node": "^10.9.1",
package/src/build.js CHANGED
@@ -7,33 +7,23 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
 
10
- import copyfiles from 'copyfiles'
11
10
 
12
11
  import { tsc } from './tsc.js'
13
12
  import { rimraf } from 'rimraf'
13
+ import { copyfiles } from './copyfiles.js'
14
+ import { META_FILES, TS_CONFIG_PATH, BUILD_FOLDER_NAME } from './constants.js'
14
15
 
15
16
  /**
16
- * Delete old build folder.
17
+ * Delete old `BUILD_FOLDER_NAME` folder.
17
18
  */
18
- rimraf('build')
19
+ await rimraf(BUILD_FOLDER_NAME)
19
20
 
20
21
  /**
21
- * Copy default files to build folder.
22
+ * Compile the application using tsc.
22
23
  */
23
- copyfiles([
24
- 'templates',
25
- 'configurer',
26
- 'package.json',
27
- 'package-lock.json',
28
- 'LICENSE.md',
29
- 'README.md',
30
- 'build'
31
- ], '', (err) => {
32
- if (err) throw err
24
+ await tsc(TS_CONFIG_PATH)
33
25
 
34
- /**
35
- * Run tsc compiler after copyfiles because
36
- * `tsc` exits the process after compile.
37
- */
38
- tsc()
39
- })
26
+ /**
27
+ * Copy `META_FILES` to `BUILD_FOLDER_NAME` folder.
28
+ */
29
+ await copyfiles(META_FILES, BUILD_FOLDER_NAME)
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Files that will be copied to the `BUILD_FOLDER_NAME` folder.
3
+ */
4
+ export const META_FILES = [
5
+ 'templates/**/*',
6
+ 'configurer/**/*',
7
+ 'package.json',
8
+ 'package-lock.json',
9
+ 'LICENSE.md',
10
+ 'README.md'
11
+ ]
12
+
13
+ /**
14
+ * Path to tsconfig file that will be used by `tsc` compiler.
15
+ */
16
+ export const TS_CONFIG_PATH = 'node_modules/@athenna/tsconfig/tsconfig.lib-build.json'
17
+
18
+ /**
19
+ * Build folder name that files will be copied to.
20
+ */
21
+ export const BUILD_FOLDER_NAME = 'build'
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @athenna/tsconfig
3
+ *
4
+ * (c) João Lenon <lenon@athenna.io>
5
+ *
6
+ * For the full copyright and license information, please view the LICENSE
7
+ * file that was distributed with this source code.
8
+ */
9
+
10
+ import copyfilesSync from 'copyfiles'
11
+
12
+ /**
13
+ * Promisified version of copyfiles.
14
+ *
15
+ * @param {string[]} files
16
+ * @param {string} dest
17
+ * @return {Promise<void>}
18
+ */
19
+ export function copyfiles(files, dest) {
20
+ files.push(dest)
21
+ return new Promise((resolve, reject) => {
22
+ copyfilesSync(files, '', (err) => {
23
+ if (err) {
24
+ return reject(err)
25
+ }
26
+
27
+ resolve()
28
+ })
29
+ })
30
+ }
package/src/tsc.js CHANGED
@@ -7,8 +7,27 @@
7
7
  * file that was distributed with this source code.
8
8
  */
9
9
 
10
- export async function tsc() {
11
- process.argv.push('--project', 'node_modules/@athenna/tsconfig/tsconfig.lib-build.json')
10
+ import lodash from 'lodash'
12
11
 
13
- await import('typescript/lib/tsc.js')
12
+ /**
13
+ * Run tsc compiler "programmatically".
14
+ *
15
+ * @param {string} tsConfigPath
16
+ * @return {Promise<void>}
17
+ */
18
+ export async function tsc(tsConfigPath) {
19
+ const originalArgv = lodash.cloneDeep(process.argv)
20
+ const originalExit = lodash.cloneDeep(process.exit)
21
+
22
+ process.exit = () => {}
23
+
24
+ process.argv = process.argv.slice(0, 2)
25
+ process.argv.push('--project', tsConfigPath)
26
+
27
+ try {
28
+ await import('typescript/lib/tsc.js')
29
+ } finally {
30
+ process.argv = originalArgv
31
+ process.exit = originalExit
32
+ }
14
33
  }