How can I compile several typescript files in a directory

1

I have a project whose structure of files and folders is as follows

app
core
|--Cumulus
|--|--Cumulu.ts
|--Dimensions
|--|--Dimension.ts
|--Galaxies
|--|--Galaxy.ts
|--SolarSystems
|--|--SolarSystem.ts
|--Universes
|--|--Universe.ts
c137.ts
package.json

I would like to know how I can transcompile all the files .ts without having to go through each tsc file.ts , tsc file2.ts , tsc file3.ts , the expected would be something like this:

app
core
|--Cumulus
|--|--Cumulu.js // javascript
|--|--Cumulu.ts
|--Dimensions
|--|--Universe.js // javascript
|--|--Universe.ts
|--Galaxies
|--|--Galaxy.js // javascript
|--|--Galaxy.ts
|--SolarSystems
|--|--SolarSystem.js // javascript
|--|--SolarSystem.ts
|--Universes
|--|--Universe.js // javascript
|--|--Universe.ts
c137.js // javascript
c137.ts
package.json
    
asked by Jorius 28.04.2017 в 18:40
source

2 answers

1

I managed to do what I wanted by creating a tsconfig.ts file, adding this and executing tsc in the console

{
    "compilerOptions": {
        "module": "es6",
        "noImplicitAny": true,
        "removeComments": false,
        "preserveConstEnums": true,
        "sourceMap": false
    },
    "files": [
        "c137.ts" // Aquí añado un archivo estático también a compilar
    ],
    "include": [
        "core/**/*", // Con esta línea pude compilar todos los archivos ts dentro de las subcarpetas de core
    ],
    "exclude": [
        "node_modules",
        "**/*.spec.ts"
    ]
}
    
answered by 28.04.2017 / 20:42
source
2

If you're looking to compile all the files .ts of a project ( or directory ), you only need to do two things:

1.- Create a file tsconfig.json where you can set the options for compiler . Open a terminal, locate over the root directory of your project and execute:

$ tsc --init
# message TS6071: Successfully created a tsconfig.json file.

2.- Finally, only the compiler on the directory remains to be executed

$ tsc -p ./

More info: Compiler Options

    
answered by 28.04.2017 в 20:02