Skip to content

Commit 53e376a

Browse files
authored
feat: annotate command (#33)
* feat: annotate command * change to chai assertion * api implementation * update lock file * fix cli * add snapshoting * update lock file * remove * implement annotate command * updates * add playground samples * updates * fix
1 parent 6f26343 commit 53e376a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+2374
-434
lines changed

.eslintignore

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
./lib
2-
./test/fixtures
3-
./playground
1+
lib
2+
test/fixtures
3+
playground
4+
temp
5+
__snapshots__

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ module.exports = {
2525
'@typescript-eslint/no-use-before-define': 'off',
2626
'@typescript-eslint/explicit-module-boundary-types': 'off',
2727
'@typescript-eslint/ban-ts-comment': 'off',
28-
'@typescript-eslint/no-non-null-assertion': 'off'
28+
'@typescript-eslint/no-non-null-assertion': 'off',
29+
'@typescript-eslint/triple-slash-reference': 'off'
2930
}
3031
}

.prettierignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ coverage
33
tsconfig.json
44
__generated__
55
./playground
6-
.nyc_output
6+
.nyc_output
7+
temp
8+
__snapshots__

api.md

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,42 @@
33
## Table Of Contents
44

55
- [Function](#function)
6+
- [annotate](#annotate)
67
- [compile](#compile)
8+
- [TypeAlias](#typealias)
9+
- [AnnotateOptions](#annotateoptions)
710
- [Enum](#enum)
11+
- [AnnotateWarningCodes](#annotatewarningcodes)
812
- [CompileErrorCodes](#compileerrorcodes)
913
- [Interface](#interface)
1014
- [CompileOptions](#compileoptions)
15+
- [SFCParseError](#sfcparseerror)
16+
- [Class](#class)
17+
- [SFCAnnotateError](#sfcannotateerror)
1118

1219
## Function
1320

21+
### annotate
22+
23+
Annoate the Vue SFC block
24+
25+
**Signature:**
26+
```typescript
27+
declare function annotate(source: string, filepath: string, options?: AnnotateOptions): string;
28+
```
29+
30+
#### Parameters
31+
32+
| Parameter | Type | Description |
33+
| --- | --- | --- |
34+
| source | string | The source code of the Vue SFC |
35+
| filepath | string | The file path of the Vue SFC |
36+
| options | AnnotateOptions | The [options](#annotateoptions) of the annotate function |
37+
38+
#### Returns
39+
40+
The annotated source code of the Vue SFC
41+
1442
### compile
1543

1644
Compile i18n resources
@@ -37,8 +65,47 @@ declare function compile(source: string, output: string, options?: CompileOption
3765
This functoin is **asyncronous** function. If you want to get about error details, use the handler of [CompileOptions](#compileoptions) and [CompileErrorCodes](#compileerrorcodes)
3866

3967

68+
## TypeAlias
69+
70+
### AnnotateOptions
71+
72+
Annotate options of [annotate](#annotate) function
73+
74+
**Signature:**
75+
```typescript
76+
declare type AnnotateOptions = {
77+
type?: string;
78+
force?: boolean;
79+
attrs?: Record<string, any>;
80+
onWarn?: (code: number, args: Record<string, any>, block: SFCBlock) => void;
81+
};
82+
```
83+
84+
4085
## Enum
4186

87+
### AnnotateWarningCodes
88+
89+
Annotate Warning Codes
90+
91+
**Signature:**
92+
```typescript
93+
declare const enum AnnotateWarningCodes
94+
```
95+
96+
#### Members
97+
98+
| Member | Value| Description |
99+
| --- | --- | --- |
100+
| LANG_MISMATCH_IN_ATTR_AND_CONTENT | 4 | Lang mismatch `lang` and block content |
101+
| LANG_MISMATCH_IN_OPTION_AND_CONTENT | 3 | Lang mismatch option and block content |
102+
| LANG_MISMATCH_IN_SRC_AND_CONTENT | 2 | Lang mismatch block `src` and block content |
103+
| NOT_SUPPORTED_TYPE | 1 | Not supported type |
104+
105+
#### Remarks
106+
107+
The warning codes of [annotate](#annotate) function
108+
42109
### CompileErrorCodes
43110

44111
Compile Error Codes
@@ -111,4 +178,81 @@ onError?: (code: number, source: string, output: string, msg?: string) => void;
111178
```
112179

113180

181+
### SFCParseError
182+
183+
Vue SFC compiler error
184+
185+
**Signature:**
186+
```typescript
187+
interface SFCParseError extends SyntaxError
188+
```
189+
190+
#### Remarks
191+
192+
This is the error wrapping the error that occurred in Vue SFC compiler
193+
194+
195+
#### Properties
196+
197+
##### erorrs
198+
199+
The error that occurred in Vue SFC compiler
200+
201+
**Signature:**
202+
```typescript
203+
erorrs: CompilerError[];
204+
```
205+
206+
##### filepath
207+
208+
The filepath of the source file
209+
210+
**Signature:**
211+
```typescript
212+
filepath: string;
213+
```
214+
215+
216+
217+
## Class
218+
219+
### SFCAnnotateError
220+
221+
The Annocation error
222+
223+
**Signature:**
224+
```typescript
225+
declare class SFCAnnotateError extends Error
226+
```
227+
228+
229+
#### Constructor
230+
231+
Constructor
232+
233+
**Signature:**
234+
```typescript
235+
constructor(message: string, filepath: string);
236+
```
237+
238+
*Parameters*
239+
240+
| Parameter | Type | Description |
241+
| --- | --- | --- |
242+
| message | string | The error message |
243+
| filepath | string | The filepath of the target file at annotate processing |
244+
245+
246+
#### Properties
247+
248+
##### filepath
249+
250+
The filepath of the target file at annotate processing
251+
252+
**Signature:**
253+
```typescript
254+
filepath: string;
255+
```
256+
257+
114258

bin/run.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
require('../lib/cli.cjs')

locales/en.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@
99
"Warning compilation: {source} -> {output}, {msg}": "Warning compilation: {source} -> {output}, {msg}",
1010
"Error compilation: {source} -> {output}, {msg}": "Error compilation: {source} -> {output}, {msg}",
1111
"annotate the attributes": "annotate the attributes",
12-
"the target path": "the target path",
13-
"the annotation mode": "the annotation mode",
14-
"the attributes to annotate": "the attributes to annotate"
12+
"the source path": "the source path",
13+
"the annotation type": "the annotation type",
14+
"forced applying of attributes": "forced applying of attributes",
15+
"annotated result detail options": "annotated result detail options",
16+
"the attributes to annotate": "the attributes to annotate",
17+
"'--type' is not supported except for 'custom-block'": "'--type' is not supported except for 'custom-block'",
18+
"there is a parse error in {filename}": "there is a parse error in {filename}",
19+
"Unsupported '{type}' block content type: {actual}": "Unsupported '{type}' block content type: {actual}",
20+
"Detected lang mismatch in block `src` ('{src}') and block content ('{content}')": "Detected lang mismatch in block `src` ('{src}') and block content ('{content}')",
21+
"Detected lang mismatch in `lang` option ('{lang}') and block content ('{content}')": "Detected lang mismatch in `lang` option ('{lang}') and block content ('{content}')",
22+
"Detected lang mismatch in `lang` attr ('{lang}') and block content ('{content}')": "Detected lang mismatch in `lang` attr ('{lang}') and block content ('{content}')",
23+
"{count} annotateable files ": "{count} annotateable files ",
24+
"{count} annotates": "{count} annotates",
25+
"{count} pass": "{count} pass",
26+
"{count} warnings": "{count} warnings",
27+
"{count} forces": "{count} forces",
28+
"{count} ignores": "{count} ignores",
29+
"{count} errors": "{count} errors"
1530
}

package.json

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"email": "kawakazu80@gmail.com"
88
},
99
"bin": {
10-
"intlify": "./bin/run.mjs"
10+
"intlify": "./bin/run.cjs"
1111
},
1212
"bugs": {
1313
"url": "https://github.com/intlify/cli/issues"
@@ -30,18 +30,23 @@
3030
"@intlify/bundle-utils": "^0.3.0",
3131
"@intlify/core": "^9.1.9",
3232
"@intlify/shared": "^9.1.9",
33+
"@vue/compiler-sfc": "^3.2.20",
3334
"chalk": "^4.1.0",
3435
"debug": "^4.3.2",
36+
"diff": "^5.0.0",
3537
"fast-glob": "^3.2.7",
38+
"jsonc-eslint-parser": "^1.4.1",
3639
"pathe": "^0.2.0",
40+
"yaml-eslint-parser": "^0.4.1",
3741
"yargs": "^17.2.0"
3842
},
3943
"devDependencies": {
4044
"@kazupon/lerna-changelog": "^4.3.0",
4145
"@microsoft/api-extractor": "^7.18.2",
4246
"@secretlint/secretlint-rule-preset-recommend": "^3.3.0",
43-
"@sinonjs/referee": "^9.1.1",
47+
"@types/chai": "^4.2.22",
4448
"@types/debug": "^4.1.7",
49+
"@types/diff": "^5.0.1",
4550
"@types/eslint": "^7.2.6",
4651
"@types/eslint-visitor-keys": "^1.0.0",
4752
"@types/glob": "^7.1.3",
@@ -52,6 +57,7 @@
5257
"@typescript-eslint/eslint-plugin": "^5.0.0",
5358
"@typescript-eslint/parser": "^5.0.0",
5459
"api-docs-gen": "^0.3.0",
60+
"chai": "^4.3.4",
5561
"eslint": "^8.0.0",
5662
"eslint-config-prettier": "^8.3.0",
5763
"eslint-plugin-prettier": "^4.0.0",
@@ -83,7 +89,7 @@
8389
"./package.json": "./package.json"
8490
},
8591
"files": [
86-
"bin/*.mjs",
92+
"bin/",
8793
"locales/*.json",
8894
"dist/*.d.ts",
8995
"lib/"
@@ -134,8 +140,9 @@
134140
"release:trigger": "shipjs trigger",
135141
"test": "npm run test:type && npm run test:cover",
136142
"test:type": "tsc -p . --noEmit",
137-
"test:cover": "nyc mocha -r jiti/register test/**/*.test.ts",
138-
"test:unit": "mocha -r jiti/register test/**/*.test.ts"
143+
"test:cover": "nyc mocha -r jiti/register -r ./test/setup.ts 'test/**/*.test.ts'",
144+
"test:unit": "mocha -r jiti/register -r ./test/setup.ts 'test/**/*.test.ts'",
145+
"test:snap": "UPDATE_SNAPSHOT=* mocha -r jiti/register -r ./test/setup.ts 'test/**/*.test.ts'"
139146
},
140147
"types": "dist/cli.d.ts"
141148
}

playground/annotate/App.vue

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<template>
2+
<p>This is App</p>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'App'
8+
}
9+
</script>
10+
11+
<style scoped>
12+
#app {
13+
color: red;
14+
}
15+
</style>
16+
17+
<i18n>
18+
{
19+
"en": {
20+
"title": "The application"
21+
}
22+
}
23+
</i18n>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<template>
2+
<p>This is Attrs component</p>
3+
</template>
4+
5+
<script setup lang="ts">
6+
import { ref } from 'vue'
7+
8+
const count = ref(0)
9+
</script>
10+
11+
<i18n>
12+
{
13+
ja: {
14+
hello: "hello"
15+
}
16+
}
17+
</i18n>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<template>
2+
<p>This is Boo component</p>
3+
</template>
4+
5+
<script>
6+
export default {
7+
name: 'Bar'
8+
}
9+
</script>

0 commit comments

Comments
 (0)