GithubHelp home page GithubHelp logo

body-builder / typescript-cp Goto Github PK

View Code? Open in Web Editor NEW
57.0 5.0 3.0 152 KB

Copy non-typescript files to outDir

TypeScript 93.63% JavaScript 6.37%
typescript ts file asset copy watch watcher watchfile fs

typescript-cp's Introduction

Typescript-cp

npm version dependencies Status devDependencies Status peerDependencies Status

Copy non-typescript files to outDir

Installation

$ npm install typescript-cp -D

CLI

# Copy
$ tscp

# Copy for TS project references
$ tscp -b

# Watcher
$ tscp -w

# Watcher for TS project references
$ tscp -b -w

# Custom compiler settings
$ tscp -p tsconfig.production.json

# Help
$ tscp -h

Example

package.json

{
  //...
  "scripts": {
    "start": "tsc -w & tscp -w",
    "build": "tsc && tscp"
  },
  //...
}

Configuration

.tscprc

{
  "ignored_files": ['**/an_ignored_file.ext'], // files not to copy (defaults to `['node_modules']`)
  "compiled_files": [], // files compiled by TS (these also get ignored) (defaults to `['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx']`)
  "use_ts_exclude": true, // ignore files that are listed in the tsconfig `exclude` array (defaults to `true`)
}

Loaders

You can attach basic loader rules to the files. Loaders accept the actual content of the given file as the first parameter, and must return the content of the output file.

.tscprc.js

const path = require('path');

/**
 * @type {import('typescript-cp/dist/types').Config}
 */
module.exports = {
  rules: [
    {
      test: /\.(scss|sass)$/,
      include: [
        path.resolve('./file-to-include.css'),
      ],
      exclude: (source_path) => {
        return source_path.indexOf('file-to-include.sass') > -1;
      },
      use: [
        {
          loader: (content, meta) => {
            // Do something with `content`

            return content;
          },
        },
      ],
    },
  ],
};

See Config and Rule types in src/types.ts for the complete reference.

Contribution

$ npm run build


Sponsored by: SRG Group Kft.

typescript-cp's People

Contributors

bencergazda avatar billyzkid avatar nwalters512 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

typescript-cp's Issues

Handle two output directories

I have this in tsconfig

"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",

So, I have two folders with built typescript:
lib/cjs/ and lib/esm/

The first one is for when my package is used on server with commonjs' require(),
second is when it's used with import()

Right now tscp only adds files to esm folder.

My scripts in package.json:

"build": "npm run build:ts && npm run build:cjs",
"build:ts": "tsc && tscp",
"build:cjs": "tsc --module commonjs --outDir lib/cjs && tscp"

Update TypeScript version and fix package vulnerabilities

Great idea for a TS-friendly hot reload utility!

I tried installing the package in my project, but it failed because of the peer dependency on an old version of TypeScript.

Also could we update the package dependencies to fix the 3 vulnerabilities it's showing when installed?

Add included_files array to config

We should be able to manually add files even if they match the config.ignored_files rules.

Usecase: we generate typings for Sass files with a tscp loader, but the created .d.ts files are not getting copied to the outDir, because all .ts files are ignored (config.compiled_files).

Ignore project references with emitting disabled

I have a project consisting of a few project references. For one, I explicitly set "noEmit": true in the project's tsconfig.json. However, typescript-cp errors if a referenced project doesn't have outDir set. I was wondering if you'd accept a PR that would essentially skip any referenced projects that have emitting disabled? I think that would match the semantics of that option and the behavior of tsc itself.

tscp fails after update to 0.1.4

Ran tscp after update, got the following error (paths redacted):

Something went wrong during the copy of the non-typescript files 
 TypeError: Cannot read property 'map' of undefined
    at /***/node_modules/typescript-cp/dist/helpers.js:283:36
    at Array.map (<anonymous>)
    at Object.get_ignore_list (/***/node_modules/typescript-cp/dist/helpers.js:282:45)
    at /***/node_modules/typescript-cp/dist/actions.js:98:55
    at step (/***/node_modules/typescript-cp/dist/actions.js:63:23)
    at Object.next (/***/node_modules/typescript-cp/dist/actions.js:44:53)
    at /***/node_modules/typescript-cp/dist/actions.js:38:71
    at new Promise (<anonymous>)
    at __awaiter (/***/node_modules/typescript-cp/dist/actions.js:34:12)
    at /***/node_modules/typescript-cp/dist/actions.js:90:88

TSConfig

{
  "include": [
    "src/**/*",
    "@types"
  ],
  "ts-node": {
    "compiler": "ttypescript"
  },
  "compilerOptions": {
    /* Basic Options */
    // "incremental": true,                   /* Enable incremental compilation */
    "target": "ESNEXT", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
    "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
    // "lib": [],                             /* Specify library files to be included in the compilation. */
    // "allowJs": true,                       /* Allow javascript files to be compiled. */
    // "checkJs": true,                       /* Report errors in .js files. */
    // "jsx": "preserve",                     /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
    // "declaration": true,                   /* Generates corresponding '.d.ts' file. */
    // "declarationMap": true,                /* Generates a sourcemap for each corresponding '.d.ts' file. */
    "sourceMap": true, /* Generates corresponding '.map' file. */
    // "outFile": "./",                       /* Concatenate and emit output to single file. */
    "outDir": "./dist", /* Redirect output structure to the directory. */
    "rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
    // "composite": true,                     /* Enable project compilation */
    // "tsBuildInfoFile": "./",               /* Specify file to store incremental compilation information */
    // "removeComments": true,                /* Do not emit comments to output. */
    // "noEmit": true,                        /* Do not emit outputs. */
    // "importHelpers": true,                 /* Import emit helpers from 'tslib'. */
    "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
    // "isolatedModules": true,               /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
    "resolveJsonModule": true, /* Allow local importing of json files */
    /* Strict Type-Checking Options */
    "strict": true,                           /* Enable all strict type-checking options. */
    "useUnknownInCatchVariables": false,
    "noImplicitAny": false, /* Raise error on expressions and declarations with an implied 'any' type. */
    // "strictNullChecks": true,              /* Enable strict null checks. */
    // "strictFunctionTypes": true,           /* Enable strict checking of function types. */
    // "strictBindCallApply": true,           /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
    // "strictPropertyInitialization": true,  /* Enable strict checking of property initialization in classes. */
    // "noImplicitThis": true,                /* Raise error on 'this' expressions with an implied 'any' type. */
    // "alwaysStrict": true,                  /* Parse in strict mode and emit "use strict" for each source file. */

    /* Additional Checks */
    // "noUnusedLocals": true,                /* Report errors on unused locals. */
    // "noUnusedParameters": true,            /* Report errors on unused parameters. */
    // "noImplicitReturns": true,             /* Report error when not all code paths in function return a value. */
    // "noFallthroughCasesInSwitch": true,    /* Report errors for fallthrough cases in switch statement. */

    /* Module Resolution Options */
    // "moduleResolution": "node",            /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
    // "baseUrl": "./",                       /* Base directory to resolve non-absolute module names. */
    // "paths": {},                           /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
    // "rootDirs": ["./src"],                        /* List of root folders whose combined content represents the structure of the project at runtime. */
    // "typeRoots": [],                       /* List of folders to include type definitions from. */
    "types": ["node"],                           /* Type declaration files to be included in compilation. */
    // "allowSyntheticDefaultImports": true,  /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
    "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
    // "preserveSymlinks": true,              /* Do not resolve the real path of symlinks. */
    // "allowUmdGlobalAccess": true,          /* Allow accessing UMD globals from modules. */

    /* Source Map Options */
    // "sourceRoot": "",                      /* Specify the location where debugger should locate TypeScript files instead of source locations. */
    // "mapRoot": "",                         /* Specify the location where debugger should locate map files instead of generated locations. */
    // "inlineSourceMap": true,               /* Emit a single file with source maps instead of having a separate file. */
    // "inlineSources": true,                 /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

    /* Experimental Options */
    // "experimentalDecorators": true,        /* Enables experimental support for ES7 decorators. */
    // "emitDecoratorMetadata": true,         /* Enables experimental support for emitting type metadata for decorators. */
    "plugins": [
      {
        "name": "ts-transformer-keys",
        "transform": "ts-transformer-keys/transformer" 
      },
    ]
  }
}

bin file has Windows line endings

I'm on macOS, and when I try to use tscp, I get the following error:

env: node\r: No such file or directory

This is the classing CRLF vs. LF error and, on inspecting the file, I can see that it has Windows line endings, which the shell can't handle.

I normally use patch-package for these types of things, but it doesn't detect line ending changes, unfortunately.

Possible solution here: npm/npm#12371 (comment)

Add verbose CLI flag

It would be great if there was a "verbose" (-V) option for the CLI so that there's a log of what was copied. Similar to how cp has a verbose flag.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.