Skip to content

Commit ccf97e1

Browse files
ktsnyyx990803
authored andcommitted
Move source code to src (#27)
* move source files to src * fix import in example * update prepublish script * update main and typings field
1 parent bd52a14 commit ccf97e1

File tree

8 files changed

+31
-29
lines changed

8 files changed

+31
-29
lines changed

.gitignore

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@ node_modules
22
example/build.js
33
example/build.js.map
44
test/test.build.js
5-
6-
/index.js
7-
/index.d.ts
5+
lib

example/example.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Vue from 'vue'
2-
import Component from '../index'
2+
import Component from '../lib/index'
33

44
@Component({
55
props: {

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@
22
"name": "vue-class-component",
33
"version": "4.2.0",
44
"description": "ES201X/TypeScript class decorator for Vue components",
5-
"main": "index.js",
6-
"typings": "index.d.ts",
5+
"main": "lib/index.js",
6+
"typings": "lib/index.d.ts",
77
"files": [
8-
"index.js",
9-
"index.d.ts",
8+
"lib",
109
"tsconfig.json"
1110
],
1211
"scripts": {
1312
"build": "tsc -p .",
13+
"clean": "rm -rf lib",
1414
"example": "npm run build && webpack --config example/webpack.config.js",
1515
"dev": "webpack --config example/webpack.config.js --watch",
1616
"test": "npm run build && webpack --config test/webpack.config.js && mocha test/test.build.js",
17-
"prepublish": "npm run build"
17+
"prepublish": "npm run clean && npm run build"
1818
},
1919
"repository": {
2020
"type": "git",

index.ts renamed to src/component.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as Vue from 'vue'
2+
import { VueClass } from './declarations'
23

34
const internalHooks = [
45
'data',
@@ -15,9 +16,7 @@ const internalHooks = [
1516
'render'
1617
]
1718

18-
export type VueClass = { new (): Vue } & typeof Vue
19-
20-
function componentFactory (
19+
export function componentFactory (
2120
Component: VueClass,
2221
options: Vue.ComponentOptions<any> = {}
2322
): VueClass {
@@ -52,15 +51,3 @@ function componentFactory (
5251
: Vue
5352
return Super.extend(options)
5453
}
55-
56-
export default function decorator <U extends Vue>(options: Vue.ComponentOptions<U>): <V extends VueClass>(target: V) => V
57-
export default function decorator <V extends VueClass>(target: V): V
58-
export default function decorator <V extends VueClass>(options: Vue.ComponentOptions<any> | V): any {
59-
if (typeof options === 'function') {
60-
return componentFactory(options)
61-
}
62-
return function (Component: any) {
63-
return componentFactory(Component, options)
64-
}
65-
}
66-

src/declarations.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import * as Vue from 'vue'
2+
3+
export type VueClass = { new (): Vue } & typeof Vue

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as Vue from 'vue'
2+
import { VueClass } from './declarations'
3+
4+
import { componentFactory } from './component'
5+
6+
export default function Component <U extends Vue>(options: Vue.ComponentOptions<U>): <V extends VueClass>(target: V) => V
7+
export default function Component <V extends VueClass>(target: V): V
8+
export default function Component <V extends VueClass>(options: Vue.ComponentOptions<any> | V): any {
9+
if (typeof options === 'function') {
10+
return componentFactory(options)
11+
}
12+
return function (Component: V) {
13+
return componentFactory(Component, options)
14+
}
15+
}

test/test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import Component from '../index'
1+
import Component from '../lib/index'
22
import { expect } from 'chai'
33
import * as Vue from 'vue'
44

tsconfig.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
],
88
"module": "commonjs",
99
"moduleResolution": "node",
10+
"outDir": "lib",
1011
"isolatedModules": false,
1112
"experimentalDecorators": true,
1213
"declaration": true,
@@ -16,10 +17,8 @@
1617
"removeComments": true,
1718
"suppressImplicitAnyIndexErrors": true
1819
},
19-
"exclude": [
20-
"node_modules",
21-
"test",
22-
"example"
20+
"include": [
21+
"src/**/*.ts"
2322
],
2423
"compileOnSave": false
2524
}

0 commit comments

Comments
 (0)