Skip to content

Commit

Permalink
refactor: rewrite core in typescript (#536)
Browse files Browse the repository at this point in the history
* improve declaration file

* type check parseAttributes.js

* type check parseFrontmatter.js

* type check parseFrontmatter.js

* convert saber-log to typescript

* compile saber

* convert assetsAttribute.js to typescript

* migrate to eslint

* some fixes

* convert BrowserApi to typescript

* conevrt Transformers to typescript

* convert Compiler to ts

* convert WebpackUtils to typescript

* convert index.js to typescript with a lot of todos and ts-ignore

* type-check website/saber-config.js

* generate typedoc

* fix path to babel preset

* remove TODOs related to Saber

* remove TODOs related to hooks

* remove TODOs related to renderer

remove custom renderer support (since we won't be able to  add react support anytime soon)

* fix path to saber cli

* make website a workspace to simplify commands

* use the transform method

* remove more TODOs

* remove ts-ignore for api.config

* disable @typescript-eslint/triple-slash-reference for now

* no ts-ignore

* resolve lint errors

* fix jest config

* exclude dist
  • Loading branch information
egoist authored Nov 2, 2019
1 parent 3e17d29 commit a05e73d
Show file tree
Hide file tree
Showing 129 changed files with 2,743 additions and 2,183 deletions.
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

0 comments on commit a05e73d

Please sign in to comment.