Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"env": {
"es6": true,
"node": true
},
"rules": {
"comma-dangle": ["error", "always-multiline"]
},
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": false
},
"project": "./tsconfig.json"
},
"extends": [
"xo"
]
}
Copy link
Owner

@egoist egoist Jun 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this project uses XO which is an eslint wrapper.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not what I mean, see

"xo": {

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, still can't work. I set:

"xo": {
    "extends": "xo-typescript",
    "extensions": [
      "ts"
    ],
    "rules": {
      "unicorn/filename-case": "off"
    }
  },

but report: Cannot find module 'eslint-plugin-@typescript-eslint'

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
.idea/
19 changes: 9 additions & 10 deletions bin/cli.js → bin/cli.ts
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/usr/bin/env node
const chalk = require('chalk')
import chalk from 'chalk';
import cac from 'cac';
import pkg from '../package.json';
import { humanlizePath } from '../lib/utils';
const importLazy = require('import-lazy')(require);

if (parseInt(process.versions.node, 10) < 8) {
console.error(
Expand All @@ -8,9 +12,7 @@ if (parseInt(process.versions.node, 10) < 8) {
console.error(chalk.dim(`Current version: ${process.versions.node}`))
process.exit(1)
}

const cac = require('cac')
const pkg = require('../package.json')
const VueCompile = importLazy('../lib');

const cli = cac('vue-compile')

Expand All @@ -37,16 +39,13 @@ cli
process.env.DEBUG = `vue-compile:${options.debug}`
}

const vueCompile = require('../lib')(options)

const vueCompile = VueCompile(options);
if (!vueCompile.options.input) {
return cli.outputHelp()
}

vueCompile.on('normalized', (input, output) => {
vueCompile.on('normalized', (input: string, output: string) => {
if (!vueCompile.options.debug) {
const { humanlizePath } = require('../lib/utils')

console.log(
`${chalk.magenta(humanlizePath(input))} ${chalk.dim(
'->'
Expand Down Expand Up @@ -79,7 +78,7 @@ cli.help()

cli.parse()

function handleError(error) {
function handleError(error: Error) {
console.error(error.stack)
process.exit(1)
}
14 changes: 8 additions & 6 deletions lib/babel/preset.js → lib/babel/preset.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { cssExtensionsRe } = require('../utils')
import { cssExtensionsRe } from '../utils';

module.exports = (_, { modern } = {}) => {
export default (_: any, { modern }: { modern: string}) => {
return {
presets: [
[
Expand All @@ -11,23 +11,25 @@ module.exports = (_, { modern } = {}) => {
}
]
],
plugins: [replaceExtensionInImports]
plugins: [_replaceExtensionInImports]
}
}

function replaceExtensionInImports({ types: t }) {
function _replaceExtensionInImports({ types: t }: { types: {
stringLiteral: (value: string) => string;
}}) {
return {
name: 'replace-extension-in-imports',
visitor: {
ImportDeclaration(path) {
ImportDeclaration(path: any) {
if (cssExtensionsRe.test(path.node.source.value)) {
path.node.source.value = path.node.source.value.replace(
cssExtensionsRe,
'.css'
)
}
},
CallExpression(path) {
CallExpression(path: any) {
if (path.node.callee.name === 'require') {
const arg = path.get('arguments.0')
if (arg) {
Expand Down
17 changes: 0 additions & 17 deletions lib/compileScript.js

This file was deleted.

25 changes: 25 additions & 0 deletions lib/compileScript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { notSupportedLang } from './utils'
import SFCDescriptor from '@vue/component-compiler-utils'
import { TCtx } from './types'
import babelCompiler from './script-compilers/babel'
import tsCompiler from './script-compilers/ts'

export default async (script: SFCDescriptor.SFCBlock, ctx: TCtx) => {
if (!script) return script

const code = script.content.replace(/^\/\/$/gm, '')

if (script.lang === 'ts' || script.lang === 'typescript') {
script.content = await tsCompiler(code, ctx)
} else if (
!script.lang ||
script.lang === 'esnext' ||
script.lang === 'babel'
) {
script.content = await babelCompiler(code, ctx)
} else {
throw new Error(notSupportedLang(script.lang, 'script'))
}

return script
}
14 changes: 9 additions & 5 deletions lib/compileStyles.js → lib/compileStyles.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,28 @@
const { notSupportedLang } = require('./utils')
import { notSupportedLang } from './utils';
import stylus from './style-compilers/stylus';
import postcss from './style-compilers/postcss';
import sass from './style-compilers/sass';
import { SFCBlock } from '@vue/component-compiler-utils';

module.exports = (styles, { filename }) => {
export default (styles: SFCBlock[], { filename } : { filename: string }) => {
return Promise.all(
styles.map(async style => {
// Do not handle "src" import
// Until we figure out how to handle it
if (style.src) return style

if (style.lang === 'stylus') {
style.content = await require('./style-compilers/stylus')(
style.content = await stylus(
style.content,
{ filename }
)
} else if (!style.lang || style.lang === 'postcss') {
style.content = await require('./style-compilers/postcss')(
style.content = await postcss(
style.content,
{ filename }
)
} else if (style.lang === 'scss' || style.lang === 'sass') {
style.content = await require('./style-compilers/sass')(style.content, {
style.content = await sass(style.content, {
filename,
indentedSyntax: style.lang === 'sass'
})
Expand Down
3 changes: 0 additions & 3 deletions lib/compileTemplate.js

This file was deleted.

5 changes: 5 additions & 0 deletions lib/compileTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { SFCBlock } from '@vue/component-compiler-utils';

export default (template: SFCBlock) => {
return template
}
9 changes: 7 additions & 2 deletions lib/importLocal.js → lib/importLocal.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const importFrom = require('import-from')

module.exports = (dir, name, fallback) => {
interface ImportLocal {
dir: string,
name: string,
fallback?: string
}
export default (locals: ImportLocal) => {
const { dir, name, fallback } = locals;
const found = importFrom.silent(dir, name) || importFrom.silent(dir, fallback)
if (!found) {
throw new Error(
Expand Down
Loading