@teambit/formatter 0.0.117 → 0.0.121
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/formatter.service.tsx +71 -0
- package/package-tar/teambit-formatter-0.0.121.tgz +0 -0
- package/package.json +10 -25
- package/types/asset.d.ts +29 -0
- package/types/style.d.ts +42 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { defaults } from 'lodash';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { EnvService, ExecutionContext, EnvDefinition } from '@teambit/envs';
|
|
4
|
+
import { Text, Newline } from 'ink';
|
|
5
|
+
import highlight from 'cli-highlight';
|
|
6
|
+
import { Formatter, FormatResults } from './formatter';
|
|
7
|
+
import { FormatterContext, FormatterOptions } from './formatter-context';
|
|
8
|
+
import { FormatterConfig } from './formatter.main.runtime';
|
|
9
|
+
|
|
10
|
+
export type FormatterServiceOptions = FormatterOptions & {
|
|
11
|
+
check?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export class FormatterService implements EnvService<FormatResults> {
|
|
15
|
+
name = 'formatter';
|
|
16
|
+
|
|
17
|
+
constructor(private formatterConfig: FormatterConfig) {}
|
|
18
|
+
|
|
19
|
+
async run(context: ExecutionContext, options: FormatterServiceOptions): Promise<FormatResults> {
|
|
20
|
+
const mergedOpts = this.optionsWithDefaults(options);
|
|
21
|
+
const formatterContext: FormatterContext = this.mergeContext(mergedOpts, context);
|
|
22
|
+
const formatter: Formatter = context.env.getFormatter(formatterContext);
|
|
23
|
+
|
|
24
|
+
const results = options.check ? await formatter.check(formatterContext) : await formatter.format(formatterContext);
|
|
25
|
+
return results;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
private optionsWithDefaults(options: FormatterServiceOptions): FormatterServiceOptions {
|
|
29
|
+
return defaults(options, this.formatterConfig);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private mergeContext(options: FormatterServiceOptions, context?: ExecutionContext): FormatterContext {
|
|
33
|
+
const formatterContext: FormatterContext = Object.assign({}, options, context);
|
|
34
|
+
return formatterContext;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
render(env: EnvDefinition) {
|
|
38
|
+
const descriptor = this.getDescriptor(env);
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<Text key={descriptor?.id}>
|
|
42
|
+
<Text color="cyan">configured formatter: </Text>
|
|
43
|
+
<Text>
|
|
44
|
+
{descriptor?.id} ({descriptor?.displayName} @ {descriptor?.version})
|
|
45
|
+
</Text>
|
|
46
|
+
<Newline />
|
|
47
|
+
<Text color="cyan">formatter config:</Text>
|
|
48
|
+
<Newline />
|
|
49
|
+
<Text>
|
|
50
|
+
{descriptor?.config && highlight(descriptor?.config, { language: 'javascript', ignoreIllegals: true })}
|
|
51
|
+
</Text>
|
|
52
|
+
<Newline />
|
|
53
|
+
</Text>
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
getDescriptor(env: EnvDefinition) {
|
|
58
|
+
if (!env.env.getFormatter) return undefined;
|
|
59
|
+
const mergedOpts = this.optionsWithDefaults({});
|
|
60
|
+
const formatterContext = this.mergeContext(mergedOpts);
|
|
61
|
+
const formatter = env.env.getFormatter(formatterContext);
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
id: formatter.id,
|
|
65
|
+
icon: formatter.icon,
|
|
66
|
+
config: formatter.displayConfig ? formatter.displayConfig() : undefined,
|
|
67
|
+
version: formatter.version ? formatter.version() : '?',
|
|
68
|
+
displayName: formatter.displayName ? formatter.displayName : '?',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teambit/formatter",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.121",
|
|
4
4
|
"homepage": "https://bit.dev/teambit/defender/formatter",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"componentId": {
|
|
7
7
|
"scope": "teambit.defender",
|
|
8
8
|
"name": "formatter",
|
|
9
|
-
"version": "0.0.
|
|
9
|
+
"version": "0.0.121"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"chalk": "2.4.2",
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"ink": "3.0.8",
|
|
18
18
|
"@babel/runtime": "7.12.18",
|
|
19
19
|
"core-js": "^3.0.0",
|
|
20
|
-
"@teambit/cli": "0.0.
|
|
21
|
-
"@teambit/component": "0.0.
|
|
22
|
-
"@teambit/envs": "0.0.
|
|
23
|
-
"@teambit/workspace": "0.0.
|
|
24
|
-
"@teambit/builder": "0.0.
|
|
25
|
-
"@teambit/logger": "0.0.
|
|
20
|
+
"@teambit/cli": "0.0.395",
|
|
21
|
+
"@teambit/component": "0.0.570",
|
|
22
|
+
"@teambit/envs": "0.0.570",
|
|
23
|
+
"@teambit/workspace": "0.0.570",
|
|
24
|
+
"@teambit/builder": "0.0.570",
|
|
25
|
+
"@teambit/logger": "0.0.482"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@types/lodash": "4.14.165",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"@types/node": "12.20.4"
|
|
35
35
|
},
|
|
36
36
|
"peerDependencies": {
|
|
37
|
-
"@teambit/legacy": "1.0.
|
|
37
|
+
"@teambit/legacy": "1.0.181",
|
|
38
38
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
39
39
|
"react": "^16.8.0 || ^17.0.0"
|
|
40
40
|
},
|
|
@@ -62,27 +62,12 @@
|
|
|
62
62
|
"react": "-"
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
|
-
"@teambit/legacy": "1.0.
|
|
65
|
+
"@teambit/legacy": "1.0.181",
|
|
66
66
|
"react-dom": "^16.8.0 || ^17.0.0",
|
|
67
67
|
"react": "^16.8.0 || ^17.0.0"
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
},
|
|
71
|
-
"files": [
|
|
72
|
-
"dist",
|
|
73
|
-
"!dist/tsconfig.tsbuildinfo",
|
|
74
|
-
"**/*.md",
|
|
75
|
-
"**/*.mdx",
|
|
76
|
-
"**/*.js",
|
|
77
|
-
"**/*.json",
|
|
78
|
-
"**/*.sass",
|
|
79
|
-
"**/*.scss",
|
|
80
|
-
"**/*.less",
|
|
81
|
-
"**/*.css",
|
|
82
|
-
"**/*.css",
|
|
83
|
-
"**/*.jpeg",
|
|
84
|
-
"**/*.gif"
|
|
85
|
-
],
|
|
86
71
|
"private": false,
|
|
87
72
|
"engines": {
|
|
88
73
|
"node": ">=12.22.0"
|
package/types/asset.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
declare module '*.png' {
|
|
2
|
+
const value: any;
|
|
3
|
+
export = value;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.svg' {
|
|
6
|
+
import type { FunctionComponent, SVGProps } from 'react';
|
|
7
|
+
|
|
8
|
+
export const ReactComponent: FunctionComponent<SVGProps<SVGSVGElement> & { title?: string }>;
|
|
9
|
+
const src: string;
|
|
10
|
+
export default src;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
// @TODO Gilad
|
|
14
|
+
declare module '*.jpg' {
|
|
15
|
+
const value: any;
|
|
16
|
+
export = value;
|
|
17
|
+
}
|
|
18
|
+
declare module '*.jpeg' {
|
|
19
|
+
const value: any;
|
|
20
|
+
export = value;
|
|
21
|
+
}
|
|
22
|
+
declare module '*.gif' {
|
|
23
|
+
const value: any;
|
|
24
|
+
export = value;
|
|
25
|
+
}
|
|
26
|
+
declare module '*.bmp' {
|
|
27
|
+
const value: any;
|
|
28
|
+
export = value;
|
|
29
|
+
}
|
package/types/style.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
declare module '*.module.css' {
|
|
2
|
+
const classes: { readonly [key: string]: string };
|
|
3
|
+
export default classes;
|
|
4
|
+
}
|
|
5
|
+
declare module '*.module.scss' {
|
|
6
|
+
const classes: { readonly [key: string]: string };
|
|
7
|
+
export default classes;
|
|
8
|
+
}
|
|
9
|
+
declare module '*.module.sass' {
|
|
10
|
+
const classes: { readonly [key: string]: string };
|
|
11
|
+
export default classes;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare module '*.module.less' {
|
|
15
|
+
const classes: { readonly [key: string]: string };
|
|
16
|
+
export default classes;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare module '*.less' {
|
|
20
|
+
const classes: { readonly [key: string]: string };
|
|
21
|
+
export default classes;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '*.css' {
|
|
25
|
+
const classes: { readonly [key: string]: string };
|
|
26
|
+
export default classes;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
declare module '*.sass' {
|
|
30
|
+
const classes: { readonly [key: string]: string };
|
|
31
|
+
export default classes;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '*.scss' {
|
|
35
|
+
const classes: { readonly [key: string]: string };
|
|
36
|
+
export default classes;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
declare module '*.mdx' {
|
|
40
|
+
const component: any;
|
|
41
|
+
export default component;
|
|
42
|
+
}
|