Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rewrite core in typescript #536

Merged
merged 30 commits into from
Nov 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
e3ae0d9
improve declaration file
egoist Oct 29, 2019
ae947d4
type check parseAttributes.js
egoist Oct 31, 2019
a01e9c0
type check parseFrontmatter.js
egoist Oct 31, 2019
0a5bd63
type check parseFrontmatter.js
egoist Oct 31, 2019
93abee1
convert saber-log to typescript
egoist Oct 31, 2019
7afe08f
compile saber
egoist Oct 31, 2019
5cb2fe1
convert assetsAttribute.js to typescript
egoist Oct 31, 2019
40104e5
migrate to eslint
egoist Oct 31, 2019
2351923
some fixes
egoist Oct 31, 2019
33edfdc
convert BrowserApi to typescript
egoist Oct 31, 2019
090e8d7
conevrt Transformers to typescript
egoist Oct 31, 2019
3452706
convert Compiler to ts
egoist Oct 31, 2019
98c5415
convert WebpackUtils to typescript
egoist Oct 31, 2019
ac89085
convert index.js to typescript with a lot of todos and ts-ignore
egoist Oct 31, 2019
5c3428b
type-check website/saber-config.js
egoist Nov 1, 2019
ac83dbf
generate typedoc
egoist Nov 1, 2019
322d88a
fix path to babel preset
egoist Nov 1, 2019
7f1734d
remove TODOs related to Saber
egoist Nov 1, 2019
62ed64d
remove TODOs related to hooks
egoist Nov 1, 2019
0b1b38e
remove TODOs related to renderer
egoist Nov 1, 2019
c731e6e
fix path to saber cli
egoist Nov 1, 2019
bd5300e
make website a workspace to simplify commands
egoist Nov 1, 2019
e76923c
use the transform method
egoist Nov 1, 2019
34df6b5
remove more TODOs
egoist Nov 2, 2019
df0930c
remove ts-ignore for api.config
egoist Nov 2, 2019
3da6a2a
disable @typescript-eslint/triple-slash-reference for now
egoist Nov 2, 2019
63c79f5
no ts-ignore
egoist Nov 2, 2019
335add9
resolve lint errors
egoist Nov 2, 2019
4672fb5
fix jest config
egoist Nov 2, 2019
b6b935a
exclude dist
egoist Nov 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ public
.DS_Store
examples/*/yarn.lock
examples/*/package-lock.json
packages/*/types
10 changes: 10 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"eslint.validate": ["javascript", "javascriptreact", "typescript"],
"eslint.enable": true,
"eslint.workingDirectories": [
{
"directory": "packages/saber",
"changeProcessCWD": true
}
]
}
3 changes: 1 addition & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ cd saber
# Install dependencies
yarn

# Link the `saber` binary
# Link the `saber` binary if you want to run it globally
cd packages/saber
yarn link

# If you wanna run the website locally
cd website
yarn
yarn dev # which uses the global `saber` command
```

Expand Down
3 changes: 2 additions & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"packages": ["packages/*", "other-packages/*"],
"version": "independent"
"version": "independent",
"npmClient": "yarn"
}
42 changes: 42 additions & 0 deletions other-packages/eslint-config-saber/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
module.exports = {
parser: '@typescript-eslint/parser',
parserOptions: {
warnOnUnsupportedTypeScriptVersion: false,
sourceType: 'module',
jsx: false,
project: 'tsconfig.json'
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:prettier/recommended'
],
env: {
node: true,
jest: true,
es2017: true
},
rules: {
// Enable this rule when all files are migated to TS
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/camelcase': 'off',
// Enable this rule later, it explodes the terminal
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'none',
requireLast: false
},
singleline: {
delimiter: 'semi',
requireLast: false
}
}
],
'@typescript-eslint/prefer-includes': 'off'
}
}
16 changes: 16 additions & 0 deletions other-packages/eslint-config-saber/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "eslint-config-saber",
"version": "0.0.0",
"description": "ESLint config for core Saber repos",
"man": "index.js",
"files": [
"index.js"
],
"license": "MIT",
"dependencies": {
"@typescript-eslint/eslint-plugin": "^2.6.0",
"@typescript-eslint/parser": "^2.6.0",
"eslint-config-prettier": "6.3.0",
"eslint-plugin-prettier": "3.1.1"
}
}
43 changes: 9 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "saber",
"scripts": {
"test": "npm run lint && lerna run test",
"lint": "xo",
"lint": "lerna run lint",
"commit": "git-cz",
"prepare": "lerna run prepublishOnly"
},
Expand All @@ -18,39 +18,17 @@
"conf": "6.0.1",
"cz-conventional-changelog": "3.0.2",
"enquirer": "^2.3.1",
"eslint-config-prettier": "6.3.0",
"eslint-config-rem": "4.0.0",
"eslint-plugin-prettier": "3.1.1",
"eslint": "^6.6.0",
"husky": "3.0.5",
"jest": "^24.9.0",
"lerna": "3.16.4",
"lint-staged": "8.1.6",
"prettier": "1.18.2",
"xo": "0.24.0"
"typedoc": "^0.15.0",
"typescript": "^3.8.0-dev.20191031"
},
"xo": {
"extends": [
"rem",
"plugin:prettier/recommended"
],
"rules": {
"import/no-unassigned-import": "off",
"unicorn/filename-case": "off",
"no-await-in-loop": "off",
"unicorn/no-abusive-eslint-disable": "off",
"camelcase": "off"
},
"ignore": [
"**/dist/**",
"**/vendor/**",
"*.min.js",
"**/vue-renderer/app/**",
"**/example/**",
"**/examples/**",
"website/**"
],
"envs": [
"jest"
]
"resolutions": {
"typedoc/typescript": "^3.8.0-dev.20191031"
},
"husky": {
"hooks": {
Expand All @@ -59,10 +37,6 @@
},
"lint-staged": {
"linters": {
"*.js": [
"xo --fix",
"git add"
],
"*.{json,md}": [
"prettier --write",
"git add"
Expand All @@ -79,7 +53,8 @@
},
"workspaces": [
"packages/*",
"other-packages/*"
"other-packages/*",
"website"
],
"config": {
"commitizen": {
Expand Down
15 changes: 12 additions & 3 deletions packages/saber-log/package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
{
"name": "saber-log",
"version": "0.3.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"index.js",
"colors.js"
"dist"
],
"license": "MIT"
"license": "MIT",
"scripts": {
"prepublishOnly": "yarn build",
"build": "rollup -c"
},
"devDependencies": {
"rollup": "^1.26.0",
"rollup-plugin-typescript2": "^0.24.3"
}
}
16 changes: 16 additions & 0 deletions packages/saber-log/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export default {
input: 'src/index.ts',
output: {
file: 'dist/index.js',
format: 'cjs'
},
plugins: [
require('rollup-plugin-typescript2')({
tsconfigOverride: {
compilerOptions: {
declaration: true
}
}
})
]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// @ts-nocheck
/* eslint-disable */
let enabled =
process.env.FORCE_COLOR ||
Expand Down Expand Up @@ -25,7 +26,7 @@ const init = (open, close) => {
)
}

module.exports = {
export const colors = {
options: Object.defineProperty({}, 'enabled', {
get: () => enabled,
set: value => (enabled = value)
Expand Down
56 changes: 43 additions & 13 deletions packages/saber-log/index.js → packages/saber-log/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const colors = require('./colors')
import { colors } from './colors'

const chars = {
info: colors.cyan('info'),
Expand All @@ -7,14 +7,24 @@ const chars = {
error: colors.red('error')
}

const defined = n => typeof n !== 'undefined'
interface ILogConstructorOptions {
logLevel?: number
}


/**
* Check if a value is `undefined`
*/
const defined = (n: any) => typeof n !== 'undefined'

export class Log {
options: ILogConstructorOptions

class Log {
constructor() {
this.setOptions()
this.options = {}
}

setOptions(options) {
setOptions(options: ILogConstructorOptions) {
this.options = Object.assign({}, this.options, options)
}

Expand All @@ -32,44 +42,64 @@ class Log {
return Number(logLevel)
}

log(...args) {
/**
* Log anything using `console.log`
*/
log(...args: any[]) {
console.log(...args)
}

verbose(...args) {
/**
* Verbose logs
*/
verbose(...args: any[]) {
if (this.logLevel < 4) return

const messages = args.map(arg => (typeof arg === 'function' ? arg() : arg))
this.log(colors.dim('[verbose]'), ...messages)
}

info(...args) {
/**
* Info logs
*/
info(...args: any[]) {
if (this.logLevel < 3) return

this.log(`[${chars.info}]`, ...args)
}

warn(...args) {
/**
* Warning logs
*/
warn(...args: any[]) {
if (this.logLevel < 2) return

this.log(`[${chars.warning}]`, ...args)
}

error(...args) {
/**
* Error logs
*/
error(...args: any[]) {
if (this.logLevel < 1) return

this.log(`[${chars.error}]`, ...args)
}

success(...args) {
/**
* Success logs
*/
success(...args: any[]) {
if (this.logLevel < 3) return

this.log(`[${chars.success}]`, ...args)
}
}

module.exports = {
log: new Log(),
const log = new Log()

export {
log,
colors,
chars
}
7 changes: 7 additions & 0 deletions packages/saber-log/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
"module": "esnext"
}
}
1 change: 0 additions & 1 deletion packages/saber-plugin-code-copy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"files": [
"lib"
],
"xo": false,
"peerDependencies": {
"saber": ">=0.7.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"files": [
"lib"
],
"xo": false,
"dependencies": {
"feed": "^4.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-git-modification-time/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"files": [
"lib"
],
"xo": false,
"dependencies": {
"execa": "^2.0.3"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-meta-redirect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"files": [
"lib"
],
"xo": false,
"dependencies": {
"url-join": "^4.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-netlify-redirect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"files": [
"lib"
],
"xo": false,
"dependencies": {
"url-join": "^4.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-pwa/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"files": [
"lib"
],
"xo": false,
"peerDependencies": {
"saber": ">=0.7.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/saber-plugin-transformer-html/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"files": [
"lib"
],
"xo": false,
"dependencies": {
"extract-sfc-blocks": "^0.0.2"
},
Expand Down
Loading