Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
pooya parsa committed May 10, 2019
0 parents commit bd215fa
Show file tree
Hide file tree
Showing 30 changed files with 9,978 additions and 0 deletions.
38 changes: 38 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2
jobs:
build:
docker:
- image: circleci/node
steps:
# Checkout repository
- checkout

# Restore cache
- restore_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}

# Install dependencies
- run:
name: Install Dependencies
command: NODE_ENV=dev yarn

# Keep cache
- save_cache:
key: yarn-cache-{{ checksum "yarn.lock" }}
paths:
- "node_modules"

# Lint
- run:
name: Lint
command: yarn lint

# Tests
# - run:
# name: Tests
# command: yarn jest

# Coverage
- run:
name: Coverage
command: yarn codecov
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org
root = true

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

[*.md]
trim_trailing_whitespace = false
4 changes: 4 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
dist
.nuxt
coverage
10 changes: 10 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
root: true,
parserOptions: {
parser: 'babel-eslint',
sourceType: 'module'
},
extends: [
'@nuxtjs'
]
}
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node_modules
*.iml
.idea
*.log
.nuxt
.vscode
.DS_Store
coverage
dist
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Nuxt Typescript



## 📑 License

[MIT License](./LICENSE)

Copyright (c) Nuxt.js Team
32 changes: 32 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
testEnvironment: 'node',

expand: true,

forceExit: true,

setupFilesAfterEnv: ['./test/utils/setup'],

coverageDirectory: './coverage',

collectCoverageFrom: [
'**/packages/*/src/**/*.js'
],

transformIgnorePatterns: [
'node_modules/(?!(@nuxt|nuxt))'
],

transform: {
'^.+\\.ts$': 'ts-jest',
'^.+\\.js$': 'babel-jest',
'^.+\\.vue$': 'vue-jest'
},

moduleFileExtensions: [
'ts',
'js',
'json'
]
}
#!/usr/bin/env node
18 changes: 18 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true,
"conventionalCommits": true,
"exact": true,
"packages": [
"packages/*"
],
"command": {
"publish": {
"npmClient": "npm"
},
"init": {
"exact": true
}
}
}
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"nuxt-ts": "node ./packages/nuxt-ts/bin/nuxt-ts.js",
"lint": "eslint packages",
"test": "yarn lint"
},
"devDependencies": {
"@babel/core": "latest",
"@babel/preset-env": "latest",
"@nuxtjs/eslint-config": "latest",
"babel-eslint": "latest",
"babel-jest": "latest",
"codecov": "latest",
"core-js": "2",
"eslint": "latest",
"eslint-config-standard": "latest",
"eslint-plugin-import": "latest",
"eslint-plugin-jest": "latest",
"eslint-plugin-node": "latest",
"eslint-plugin-promise": "latest",
"eslint-plugin-standard": "latest",
"eslint-plugin-vue": "latest",
"jest": "^24.8.0",
"nuxt-edge": "^2.7.0-25953129.a88e8b60"
}
}
20 changes: 20 additions & 0 deletions packages/nuxt-ts/bin/nuxt-ts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/usr/bin/env node

const path = require('path')
const { getNuxtBin, getRootdirFromArgv, registerTSNode, setupTSConfig } = require('..')

async function main() {
const rootDir = getRootdirFromArgv()
const tsConfigPath = path.resolve(rootDir, 'tsconfig.json')

await setupTSConfig(tsConfigPath)

registerTSNode(tsConfigPath)

require(getNuxtBin())
}

main().catch((error) => {
require('consola').error(error)
process.exit(1)
})
5 changes: 5 additions & 0 deletions packages/nuxt-ts/lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
...require('./utils'),
registerTSNode: require('./register'),
setupTSConfig: require('./setup')
}
13 changes: 13 additions & 0 deletions packages/nuxt-ts/lib/register.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const { register } = require('ts-node')

function registerTSNode(tsconfigPath) {
// https://github.com/TypeStrong/ts-node
register({
project: tsconfigPath,
compilerOptions: {
module: 'commonjs'
}
})
}

module.exports = registerTSNode
18 changes: 18 additions & 0 deletions packages/nuxt-ts/lib/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { exists, readFile, writeJSON } = require('fs-extra')
const consola = require('consola')
const defaultTsJsonConfig = require('./tsconfig')

async function setupTSConfig(tsConfigPath) {
let contents = ''

if (await exists(tsConfigPath)) {
contents = await readFile(tsConfigPath, 'utf-8')
}

if (!contents || contents === '{}') {
consola.info(`Generating ${tsConfigPath.replace(process.cwd(), '')}`)
await writeJSON(tsConfigPath, defaultTsJsonConfig, { spaces: 2 })
}
}

module.exports = setupTSConfig
32 changes: 32 additions & 0 deletions packages/nuxt-ts/lib/tsconfig.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = {
compilerOptions: {
target: 'esnext',
module: 'esnext',
moduleResolution: 'node',
lib: [
'esnext',
'esnext.asynciterable',
'dom'
],
esModuleInterop: true,
experimentalDecorators: true,
allowJs: true,
sourceMap: true,
strict: true,
noImplicitAny: false,
noEmit: true,
baseUrl: '.',
paths: {
'~/*': [
'./*'
],
'@/*': [
'./*'
]
},
types: [
'@types/node',
'@nuxt/vue-app'
]
}
}
35 changes: 35 additions & 0 deletions packages/nuxt-ts/lib/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const path = require('path')

function getNuxtBin() {
const binPath = [
'nuxt-edge/bin/nuxt.js',
'nuxt/bin/nuxt.js',
'nuxt-start-edge/bin/nuxt.js',
'nuxt-start/bin/nuxt.js'
]

for (const bin of binPath) {
try {
return require.resolve(bin)
} catch {}
}
}

function getRootdirFromArgv() {
const validCommands = ['dev', 'build', 'generate', 'start']

let rootDir = process.argv[2]
if (validCommands.includes(rootDir)) {
rootDir = process.argv[3]
}
if (!rootDir) {
rootDir = '.'
}

return path.resolve(process.cwd(), rootDir)
}

module.exports = {
getNuxtBin,
getRootdirFromArgv
}
20 changes: 20 additions & 0 deletions packages/nuxt-ts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "nuxt-ts",
"version": "0.0.0",
"repository": "nuxt/typescript",
"license": "MIT",
"files": [
"bin",
"lib"
],
"main": "lib/index.js",
"dependencies": {
"consola": "^2.6.1",
"fs-extra": "^7.0.1",
"ts-node": "^8.1.0",
"typescript": "^3.4.5"
},
"publishConfig": {
"access": "public"
}
}
23 changes: 23 additions & 0 deletions packages/typescript/lib/module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module.exports = function () {
// TODO: Migrate from packages/webpack/src/config/base.js
// if (_typescript.build && buildOptions.typescript && buildOptions.typescript.ignoreNotFoundWarnings) {
// filters.push(
// warn => warn.name === 'ModuleDependencyWarning' &&
// /export .* was not found in /.test(warn.message)
// )
// }

// TODO: Migrate from packages/webpack/src/config/client.js
// TypeScript type checker
// Only performs once per client compilation and only if `ts-loader` checker is not used (transpileOnly: true)
// if (_typescript.build && buildOptions.typescript && buildOptions.typescript.typeCheck && !this.isModern && this.loaders.ts.transpileOnly) {
// const ForkTsCheckerWebpackPlugin = require(this.buildContext.nuxt.resolver.resolveModule('fork-ts-checker-webpack-plugin'))
// plugins.push(new ForkTsCheckerWebpackPlugin(Object.assign({
// vue: true,
// tsconfig: path.resolve(rootDir, 'tsconfig.json'),
// tslint: false, // We recommend using ESLint so we set this option to `false` by default
// formatter: 'codeframe',
// logger: consola
// }, buildOptions.typescript.typeCheck)))
// }
}
37 changes: 37 additions & 0 deletions packages/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "@nuxt/typescript",
"version": "0.0.0",
"repository": "nuxt/typescript",
"license": "MIT",
"files": [
"lib"
],
"dependencies": {
"@types/babel__core": "^7.1.1",
"@types/chokidar": "^2.1.3",
"@types/compression": "^0.0.36",
"@types/etag": "^1.8.0",
"@types/express": "^4.16.1",
"@types/html-minifier": "^3.5.3",
"@types/node": "^11.13.10",
"@types/optimize-css-assets-webpack-plugin": "^1.3.4",
"@types/serve-static": "^1.13.2",
"@types/terser-webpack-plugin": "^1.2.1",
"@types/webpack": "^4.4.31",
"@types/webpack-bundle-analyzer": "^2.13.1",
"@types/webpack-dev-middleware": "^2.0.2",
"@types/webpack-hot-middleware": "^2.16.5",
"consola": "^2.6.1",
"fork-ts-checker-webpack-plugin": "^1.3.1",
"fs-extra": "^7.0.1",
"ts-loader": "^6.0.0",
"typescript": "^3.4.5",
"vue-property-decorator": "^8.1.1"
},
"publishConfig": {
"access": "public"
},
"engines": {
"node": ">=8.6.0"
}
}
12 changes: 12 additions & 0 deletions test/fixture/layouts/default.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<template>
<Nuxt />
</template>

<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
@Component({
middleware: 'test'
})
export default class DefaultLayout extends Vue {}
</script>
1 change: 1 addition & 0 deletions test/fixture/middleware/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default () => {}
Loading

0 comments on commit bd215fa

Please sign in to comment.