Skip to content

Commit

Permalink
Full rewrite to use Slune tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sveyret committed Feb 7, 2020
1 parent cbd3eb0 commit ad65b4e
Show file tree
Hide file tree
Showing 34 changed files with 460 additions and 476 deletions.
9 changes: 9 additions & 0 deletions .depcheckrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
specials:
- bin
- eslint
- istanbul
- mocha
- prettier
ignore-dirs:
- __test__
5 changes: 5 additions & 0 deletions .eslintrc.full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
extends:
- ./.eslintrc.yaml
rules:
import/no-cycle: error
109 changes: 109 additions & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
---
env:
node: true
es6: true
parser: '@typescript-eslint/parser'
parserOptions:
project: tsconfig.json
plugins:
- prettier
settings:
jsdoc:
mode: typescript
extends:
- eslint:recommended
- plugin:node/recommended
- plugin:@typescript-eslint/eslint-recommended
- plugin:@typescript-eslint/recommended
- plugin:import/warnings
- plugin:import/typescript
- plugin:jsdoc/recommended
- prettier
- prettier/@typescript-eslint
rules:
'@typescript-eslint/array-type':
- error
- default: array-simple
readonly: generic
'@typescript-eslint/consistent-type-definitions': error
curly: error
dot-notation: error
eqeqeq: error
'@typescript-eslint/explicit-function-return-type': 'off'
'@typescript-eslint/explicit-member-accessibility':
- error
- accessibility: explicit
id-blacklist:
- error
- any
- Number
- number
- String
- string
- Boolean
- boolean
- Undefined
id-match: error
'@typescript-eslint/interface-name-prefix': 'off'
max-classes-per-file: 'off'
jsdoc/newline-after-description: error
no-bitwise: 'off'
no-caller: error
no-console: warn
no-eval: error
'@typescript-eslint/no-explicit-any': 'off'
no-extra-bind: error
import/no-extraneous-dependencies:
- error
- optionalDependencies: false
devDependencies:
- '**/*.spec.ts'
import/no-internal-modules: error
no-invalid-this: 'off'
node/no-missing-import: 'off'
no-new-wrappers: error
'@typescript-eslint/no-non-null-assertion': 'off'
'@typescript-eslint/no-parameter-properties': 'off'
no-restricted-syntax:
- error
- SequenceExpression
no-return-await: error
import/no-self-import: error
no-shadow:
- error
- hoist: all
no-template-curly-in-string: error
no-throw-literal: error
jsdoc/no-types: error
no-undef-init: error
node/no-unsupported-features/es-syntax: 'off'
no-unused-expressions:
- error
- allowShortCircuit: true
'@typescript-eslint/no-unused-vars':
- error
- argsIgnorePattern: '^_'
ignoreRestSiblings: true
'@typescript-eslint/no-use-before-define': 'off'
object-shorthand: error
one-var:
- error
- never
prefer-arrow-callback:
- error
- allowUnboundThis: false
'@typescript-eslint/prefer-for-of': error
'@typescript-eslint/prefer-function-type': error
prefer-object-spread: error
prettier/prettier: warn
radix: error
require-atomic-updates: 'off'
jsdoc/require-description-complete-sentence: warn
jsdoc/require-hyphen-before-param-description: warn
jsdoc/require-jsdoc: 'off'
jsdoc/require-param-type: 'off'
jsdoc/require-returns-type: 'off'
spaced-comment: error
valid-typeof: 'off'
space-in-parens: error
'@typescript-eslint/unified-signatures': error
13 changes: 6 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Distributable
node_modules/
dist/

# Test results
test/*.js

# Coverage
.nyc_output/
coverage/

# Npm and Yarn
# Package managers
package-lock.json
yarn-error.log
yarn.lock
pnpm-lock.yaml

# VS code
.vscode/
# IDE
*.code-workspace
.vscode/
4 changes: 4 additions & 0 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
require:
- 'ts-node/register'
- 'source-map-support/register'
20 changes: 0 additions & 20 deletions .npmignore

This file was deleted.

7 changes: 0 additions & 7 deletions .prettierrc

This file was deleted.

6 changes: 6 additions & 0 deletions .prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
arrowParens: avoid
printWidth: 108
semi: false
singleQuote: true
trailingComma: es5
5 changes: 1 addition & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
language: node_js

node_js:
- "8"

- '10'
before_install:
- npm install -g coveralls

after_success:
- coveralls < ./coverage/lcov.info
4 changes: 2 additions & 2 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Stéphane Veyret
Copyright (c) 2020 Slune

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
64 changes: 25 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![npm package](https://badge.fury.io/js/ts-transform-asset.svg)](https://www.npmjs.com/package/ts-transform-asset)
[![license](https://img.shields.io/github/license/slune-org/ts-transform-asset.svg)](https://github.com/slune-org/ts-transform-asset/blob/master/LICENSE)
[![build](https://travis-ci.org/slune-org/ts-transform-asset.svg?branch=master)](https://travis-ci.com/slune-org/ts-transform-asset)
[![License](https://img.shields.io/github/license/slune-org/ts-transform-asset.svg)](https://github.com/slune-org/ts-transform-asset/blob/master/LICENSE)
[![Build Status](https://travis-ci.org/slune-org/ts-transform-asset.svg?branch=master)](https://travis-ci.org/slune-org/ts-transform-asset)
[![Coverage Status](https://coveralls.io/repos/github/slune-org/ts-transform-asset/badge.svg?branch=master)](https://coveralls.io/github/slune-org/ts-transform-asset?branch=master)
[![issues](https://img.shields.io/github/issues/slune-org/ts-transform-asset.svg)](https://github.com/slune-org/ts-transform-asset/issues)
[![Issues](https://img.shields.io/github/issues/slune-org/ts-transform-asset.svg)](https://github.com/slune-org/ts-transform-asset/issues)

# ts-transform-asset - Typescript transformer for asset imports

Expand All @@ -27,7 +27,7 @@ export const foobar = 'assets/foobar.ico'

# Language/langue

Because French is my native language, finding all documents and messages in French is mandatory. Other translations are welcome.
Because Slune is French firm, you will find all documents and messages in French. Other translations are welcome.

Anyway, because English is the language of programming, the code, including variable names and comments, are in English.

Expand Down Expand Up @@ -64,39 +64,7 @@ The transformer accepts the following parameters:
- `assetsMatch`: a regular expression used to select asset imports, e.g., for all `.png` files, `assetsMatch = "\\.png$"`. This parameter is mandatory.
- `targetName`: a template similar to [Webpack file-loader name](https://webpack.js.org/loaders/file-loader/#name) used to convert the name of the asset. If you defined a `publicPath` in the `output` parameter of `Webpack`, then you will probably need to specify this path here too. This parameter is optional and defaults to `[hash].[ext]`.

There is currently no way of declaring a transformer in the vanilla `typescript` compiler. If you do not want to write your own compiler using the `typescript` API, you can use the `ttypescript` wrapper. Below is explained how.

## Installation

First of all, you need to install `ttypescript`, either with `npm`:

```bash
$ npm install --save-dev ttypescript
```

or with `yarn`:

```bash
$ yarn add --dev ttypescript
```

## Configuration

Then, configure your `tsconfig.json`

```json
{
"compilerOptions": {
"plugins": [
{
"transform": "ts-transform-asset",
"assetsMatch": "\\.png$",
"targetName": "assets/[name]-[hash].[ext]"
}
]
}
}
```
There is currently no way of declaring a transformer in the vanilla _TypeScript_ compiler. If you do not want to write your own compiler using the `typescript` API, you can use the [ttypescript](https://www.npmjs.com/package/ttypescript) wrapper.

## Code

Expand Down Expand Up @@ -154,12 +122,30 @@ import * as image from './image.png'
const url: string = image
```

## Configuration with ttypescript

For `ttypescript`, configure your `tsconfig.json`. Example:

```json
{
"compilerOptions": {
"plugins": [
{
"transform": "ts-transform-asset",
"assetsMatch": "\\.png$",
"targetName": "assets/[name]-[hash].[ext]"
}
]
}
}
```

# Notices

- The transformer will not detect nor modify any `require` statement. It is advised to run it in the `before` phase of the compilation, before the code is converted to an older version of `ECMAScript`.
- The transformer either modify the code if it conforms to what is expected, or do not touch it at all. There is an exception anyway for the re-export declarations: if the source module matches the given parameters, but the exported property is not `default`, then this export property will be removed.
- Please file an issue if you have any problem using the transformer. Even if I cannot give a response time, I will do my best to correct problems or answer questions.
- Contributions are of course always welcome.
- Please file an issue if you have any problem using the transformer. Even though we cannot guarantee a response time, we will do our best to correct problems or answer questions.
- Contributions (_pull request_) are welcome.

# Migration

Expand Down
2 changes: 1 addition & 1 deletion test/failure.ts → __test__/failure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default function getData() {
}

export { ogg as sound } from './sound.ogg'
export * from './skip.ogg'
export * from './skip.svg'
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ad65b4e

Please sign in to comment.