Skip to content

Commit

Permalink
Adds TS support & updates setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Jan 9, 2019
1 parent 14884ed commit 293c7bb
Show file tree
Hide file tree
Showing 43 changed files with 7,496 additions and 3,881 deletions.
16 changes: 16 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"presets": [
["@babel/preset-env", { "targets": { "node": "8.0.0" } }],
"@babel/typescript"
],
"plugins": [
[
"babel-plugin-module-resolver",
{ "root": ["./src/lib"], "alias": { "~": "./src" } }
],
["@babel/plugin-proposal-decorators", { "decoratorsBeforeExport": false }],
"@babel/plugin-proposal-class-properties",
["@babel/plugin-proposal-object-rest-spread", { "useBuiltIns": true }]
],
"ignore": ["node_modules"]
}
8 changes: 4 additions & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Top-most EditorConfig file
# http://editorconfig.org
root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.json]
indent_size = 2
[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src/@types
71 changes: 35 additions & 36 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
// npm i --save-dev eslint eslint-config-standard eslint-plugin-import eslint-plugin-jest eslint-plugin-node eslint-plugin-promise eslint-plugin-standard
const globals = require('eslint-restricted-globals');

module.exports = {
extends: 'standard',
env: {
node: true,
jasmine: true,
jest: true
},
plugins: [
"jest"
root: true,
parser: 'babel-eslint',
extends: ['standard', 'plugin:import/errors', 'prettier'],
env: {
node: true,
jest: true
},
parserOptions: {
impliedStrict: true
},
plugins: ['prettier', 'jest', 'import', 'babel'],
globals: {},
rules: {
'no-warning-comments': [
1,
{ terms: ['xxx', 'fixme', 'todo', 'refactor'], location: 'start' }
],
globals: {

'no-unused-vars': 1, // Set as warning
'no-console': 1,
'no-restricted-globals': [2, 'fetch'].concat(globals),
// eslint-plugin-babel
'babel/no-invalid-this': 1,
'babel/semi': 1,
// Prettier
'prettier/prettier': [2, require('./.prettierrc')]
},
settings: {
// babel-plugin-module-resolver
'import/resolver': {
'babel-module': {}
},
rules: {
// Console.log
'no-console': 1,
// Indentation
"indent": [ 2, 4 ],
// Semicolons
"semi": [2, "always"],
// Space before function parenthesis
"space-before-function-paren": [2, {
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}],
// Template strings inner spacing
"template-curly-spacing": 0,
"operator-linebreak": [2, "before"],
// Line length
"max-len": [2, {
"code": 90,
"ignoreUrls": true,
"ignoreComments": true,
"ignoreStrings": true,
"ignoreTemplateLiterals": true,
"ignoreRegExpLiterals": true
}]
// eslint-import-resolver-typescript
'import/resolver': {
typescript: {}
}
}
};
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
# Project Specific #
####################
/docs

# Node, Frameworks, Editors #
#############################
_test.js
_test.ts
build
dist
.cache
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
coverage
node_modules
npm-debug.log
config.env

# Compiled source #
###################
Expand Down
14 changes: 14 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
_test.js
setup
docs
src
test
.cache
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
coverage
*.log
DS_Store
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib
build
dist
out
.vscode
.cache
coverage
node_modules
*.md
12 changes: 12 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: true,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'always',
proseWrap: 'never'
};
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: node_js
node_js:
- "8.0.0"
- '8.0.0'
script:
- npm run checks
- npm run validate
after_success:
- coveralls < coverage/lcov.info
3 changes: 3 additions & 0 deletions Jakefile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const path = require('path');
const { CONFIG_DIR } = require('./project.config');
require(path.join(CONFIG_DIR, 'setup/jake'));
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2017 Rafa Mel
Copyright (c) 2019 Rafa Mel

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 Down
52 changes: 28 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# yaml-import

[![Version](https://img.shields.io/github/package-json/v/rafamel/yaml-import.svg)](https://github.com/rafamel/yaml-import)
[![Version](https://img.shields.io/npm/v/yaml-import.svg)](https://www.npmjs.com/package/yaml-import)
[![Build Status](https://travis-ci.org/rafamel/yaml-import.svg)](https://travis-ci.org/rafamel/yaml-import)
[![Coverage](https://img.shields.io/coveralls/rafamel/yaml-import.svg)](https://coveralls.io/github/rafamel/yaml-import)
[![Dependencies](https://david-dm.org/rafamel/yaml-import/status.svg)](https://david-dm.org/rafamel/yaml-import)
Expand All @@ -24,13 +24,13 @@ Imports the contents of a single file

```yaml
some:
- yaml
- where I
- yaml
- where I
import: a file like
here: !!import/single mydir/myfile.yml
or:
- like below
- !!import/single myotherdir/myotherfile.yml
- like below
- !!import/single myotherdir/myotherfile.yml
```

### `!!import/merge` *array*
Expand All @@ -42,9 +42,9 @@ Merges the contents of numerous files into one object or array.

```yaml
!!import/merge [
'mydir/file-one.yml',
'mydir/file-two.yml',
'myotherdir/file-three.yml',
'mydir/file-one.yml',
'mydir/file-two.yml',
'myotherdir/file-three.yml',
]
```

Expand Down Expand Up @@ -104,17 +104,17 @@ Reads a *YAML* file and writes the output on a file.
- `input`: *String*, the path of the file to read.
- `output`: *String*, the path for the output file.
- `options` (optional): *Object*
- `ext`: *Array*, list of extensions to use for directory imports. By default, `['.yml', '.yaml']`.
- `safe`: *Boolean*, whether it should use `safeLoad` or `load` when loading the *YAML* file via [js-yaml](https://www.npmjs.com/package/js-yaml). `true` by default.
- [All others offered by js-yaml](https://github.com/nodeca/js-yaml#safeload-string---options-), except `schema`.
- `ext`: *Array*, list of extensions to use for directory imports. By default, `['.yml', '.yaml']`.
- `safe`: *Boolean*, whether it should use `safeLoad` or `load` when loading the *YAML* file via [js-yaml](https://www.npmjs.com/package/js-yaml). `true` by default.
- [All others offered by js-yaml](https://github.com/nodeca/js-yaml#safeload-string---options-), except `schema`.

```javascript
const yimp = require('yaml-import');
const path = require('path');
import path from 'path';
import * as yimp from 'yaml-import';

yimp.write(
path.join(__dirname, 'myfiles/base.yml'),
path.join(__dirname, 'out/yaml.yml')
path.join(__dirname, 'myfiles/base.yml'),
path.join(__dirname, 'out/yaml.yml')
);
```

Expand All @@ -126,14 +126,18 @@ Reads a *YAML* file and returns the parsed object.
- `options` (optional): Same as [`yimp.write()`](#yimpwriteinput-output-options).

```javascript
const yimp = require('yaml-import');
const path = require('path');
import path from 'path';
import * as yimp from 'yaml-import';

const myYmlObj = yimp.read(path.join(__dirname, 'myfiles/base.yml'));
```

We could write it later on with js-yaml and fs:

```javascript
import yaml from 'js-yaml';
import fs from 'fs';

// We could write it later on with js-yaml and fs
const yaml = require('js-yaml');
const fs = require('fs');
// To YAML
const myYml = yaml.dump(myYmlObj);
// Write to file
Expand All @@ -150,10 +154,10 @@ You can use `yaml-import` to return a `schema` and pair it with [js-yaml](https:
- `options` (optional): Same as for [`yimp.write()`](#yimpwriteinput-output-options). Used when files to import are loaded.

```javascript
const yaml = require('js-yaml');
const yimp = require('yaml-import');
const path = require('path');
const fs = require('fs');
import path from 'path';
import fs from 'fs';
import yaml from 'js-yaml';
import * as yimp from 'yaml-import';

const src = fs.readFileSync(path.join(__dirname, 'myfiles/base.yml'), 'utf8');
const dir = path.join(__dirname, 'myfiles')
Expand Down
43 changes: 0 additions & 43 deletions bin/yimp.js

This file was deleted.

18 changes: 18 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { EXTENSIONS } = require('./project.config');
const EXT_ARR = EXTENSIONS.split(',');

module.exports = {
testEnvironment: 'node',
collectCoverage: true,
collectCoverageFrom: [`<rootDir>/src/**/*.{${EXTENSIONS}}`],
modulePathIgnorePatterns: ['<rootDir>/build', '<rootDir>/src/bin'],
moduleFileExtensions: EXT_ARR.concat(['json']),
testMatch: [
`**/__tests__/**/*.{${EXTENSIONS}}`,
`**/?(*.)+(spec|test).{${EXTENSIONS}}`
],
testPathIgnorePatterns: ['/node_modules/'],
transform: {
[`^.+\\.(${EXT_ARR.join('|')})$`]: 'babel-jest'
}
};
10 changes: 10 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"baseUrl": ".",
"paths": {
"*": ["src/lib/*"],
"~/*": ["src/*"]
}
}
}
Loading

0 comments on commit 293c7bb

Please sign in to comment.