Skip to content

Commit 111f475

Browse files
committed
✨ Add useAckeeFelaPackage config option
1 parent b2e170f commit 111f475

5 files changed

Lines changed: 53 additions & 39 deletions

File tree

README.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,34 @@ A set of usefull snippets and commands we use at Ackee for web apps development.
66

77
## Features
88

9-
* Commands for project scaffolding (typescript supported)
10-
* React/Fela snippets
9+
- Commands for project scaffolding (typescript supported)
10+
- React/Fela snippets
1111

1212
## Contents
1313

14-
- [Commands](#commands)
15-
- [Settings](#settings)
16-
- [Snippets](#snippets)
14+
- [Commands](#commands)
15+
- [Settings](#settings)
16+
- [Snippets](#snippets)
1717

1818
## Commands
1919

2020
### Create component
21-
* `Component.(j|t)sx` - React stateless component
22-
* `index.(j|t)s` - index file to export the React component
21+
22+
- `Component.(j|t)sx` - React stateless component
23+
- `index.(j|t)s` - index file to export the React component
2324

2425
### Create Fela component
2526

2627
Creates a folder with following structure:
27-
* `Component.(j|t)sx` - React stateless component with `styles` prop
28-
* `Component.styles.(j|t)s` - fela rules
29-
* `index.(j|t)s` - index file to export the React component and wrap it with `connectFela`
28+
29+
- `Component.(j|t)sx` - React stateless component with `styles` prop
30+
- `Component.styles.(j|t)s` - fela rules
31+
- `index.(j|t)s` - index file to export the React component and wrap it with `connectFela`
3032

3133
#### Usage
34+
3235
1. Right click to a folder where you want to create a component
33-
2. Select *"Ackee: create component"*
36+
2. Select _"Ackee: create component"_
3437
3. Type a name and press enter
3538

3639
![Create component example](images/create_component_example.jpg)
@@ -41,31 +44,30 @@ Creates a folder with following structure:
4144

4245
These settings can be changed in VS Code settings under `ackeeFrontend` namespace.
4346

44-
| Name | Default value | Description |
45-
|---|---|---|
46-
| `moduleDependencies` | `true` | If enabled it uses named imports from dependencies.js file of the module. |
47-
| `felaHooks` | `false` | If enabled, scaffolded components will use enhanced fela hooks instead of connect HOC. |
48-
| `typescript` | `false` | If enabled, scaffolded components will be in TypeScript. |
49-
| `typescriptFelaTheme` | `false` | If enabled, scaffolded styles of components will have `TRuleWithTheme` instead of simple `TRule` (`typescript` option must be enabled). |
50-
| `typescriptFelaExtendProp` | `false` | If enabled, scaffolded interfaces of components will have `extend` prop. (`typescript` option must enabled). |
51-
| `includeReactImport` | `false` | If enabled, a scaffolded component will include import of React. |
47+
| Name | Default value | Description |
48+
| -------------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------- |
49+
| `moduleDependencies` | `true` | If enabled it uses named imports from dependencies.js file of the module. |
50+
| `felaHooks` | `false` | If enabled, scaffolded components will use enhanced fela hooks instead of connect HOC. |
51+
| `typescript` | `false` | If enabled, scaffolded components will be in TypeScript. |
52+
| `typescriptFelaTheme` | `false` | If enabled, scaffolded styles of components will have `TRuleWithTheme` instead of simple `TRule` (`typescript` option must be enabled). |
53+
| `typescriptFelaExtendProp` | `false` | If enabled, scaffolded interfaces of components will have `extend` prop. (`typescript` option must enabled). |
54+
| `includeReactImport` | `false` | If enabled, a scaffolded component will include import of React. |
55+
| `useAckeeFelaPackage` | `false` | If enabled, useFelaEnhanced and related types will be imported from @ackee/fela package. |
5256

5357
## Snippets
5458

5559
Supported languages:
5660

57-
* JavaScript (.js)
58-
* JavaScript React (.jsx)
59-
60-
| Trigger | Content |
61-
|---|---|
62-
| `frd→` | Fela rule (default export) |
63-
| `frdt→` | Fela rule with theme (default export) |
64-
| `fr→` | Fela rule (named export) |
65-
| `frt→` | Fela rule with theme (named export) |
66-
| `imrd→` | Import React and PropTypes from dependencies |
67-
| `ed→` | Export for component indexes |
68-
| `rfc→` | React stateless component with FelaComponent |
69-
| `rfcc→` | React stateless component with connectFela HOC |
70-
71-
61+
- JavaScript (.js)
62+
- JavaScript React (.jsx)
63+
64+
| Trigger | Content |
65+
| ------- | ---------------------------------------------- |
66+
| `frd→` | Fela rule (default export) |
67+
| `frdt→` | Fela rule with theme (default export) |
68+
| `fr→` | Fela rule (named export) |
69+
| `frt→` | Fela rule with theme (named export) |
70+
| `imrd→` | Import React and PropTypes from dependencies |
71+
| `ed→` | Export for component indexes |
72+
| `rfc→` | React stateless component with FelaComponent |
73+
| `rfcc→` | React stateless component with connectFela HOC |

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
"type": "boolean",
9292
"default": false,
9393
"description": "If enabled, a scaffolded component will include import of React."
94+
},
95+
"ackeeFrontend.useAckeeFelaPackage": {
96+
"type": "boolean",
97+
"default": false,
98+
"description": "If enabled, useFelaEnhanced and related types will be imported from @ackee/fela package."
9499
}
95100
}
96101
}

src/template/component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ export const felaHookComponent = (name: string, config: Configuration) => `${
4141
? `import {${config.includeReactImport ? " React," : ""} PropTypes, useFelaEnhanced } from '../../dependencies';`
4242
: `${
4343
config.includeReactImport ? `import React from 'react';\n` : ""
44-
}import PropTypes from 'prop-types';\nimport { useFelaEnhanced } from 'hooks'`
44+
}import PropTypes from 'prop-types';\nimport { useFelaEnhanced } from '${
45+
config.useAckeeFelaPackage ? "@ackee/fela" : "hooks"
46+
}'`
4547
}
4648
4749
import * as felaRules from './${name}.rules';

src/template/componentsTypescript.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ const getExtendProp = (config: Configuration) =>
99
}`
1010
: "";
1111

12-
const getExtendPropImport = ({ typescriptFelaExtendProp, typescriptFelaTheme }: Configuration) => {
12+
const getExtendPropImport = ({ typescriptFelaExtendProp, typescriptFelaTheme, useAckeeFelaPackage }: Configuration) => {
1313
if (!typescriptFelaExtendProp) {
1414
return "";
1515
}
1616

1717
return typescriptFelaTheme
18-
? `import type { RulesExtend } from 'styles/theme';`
18+
? `import type { RulesExtend } from '${useAckeeFelaPackage ? "@ackee/fela" : "styles/theme"}';`
1919
: "import type { TRule } from 'fela';";
2020
};
2121

@@ -47,7 +47,9 @@ export const ${name} = ({ styles }: ${name}Props) => {
4747
export const felaHookComponent = (name: string, config: Configuration) => `${
4848
config.moduleDependencies
4949
? `import {${config.includeReactImport ? " React," : ""} useFelaEnhanced } from '../../dependencies';`
50-
: `${config.includeReactImport ? `import React from 'react';\n` : ""}import { useFelaEnhanced } from 'hooks';`
50+
: `${config.includeReactImport ? `import React from 'react';\n` : ""}import { useFelaEnhanced } from '${
51+
config.useAckeeFelaPackage ? "@ackee/fela" : "hooks"
52+
}';`
5153
}
5254
${getExtendPropImport(config)}
5355
@@ -70,7 +72,9 @@ export const ${name} = ({ ${config.typescriptFelaExtendProp ? "extend" : ""} }:
7072

7173
export const styles = (config: Configuration) => `${
7274
config.typescriptFelaTheme
73-
? `import type { TRuleWithTheme } from '${config.moduleDependencies ? "../../dependencies" : "styles/theme"}';\n`
75+
? `import type { TRuleWithTheme } from '${
76+
config.moduleDependencies ? "../../dependencies" : config.useAckeeFelaPackage ? "@ackee/fela" : "styles/theme"
77+
}';\n`
7478
: `import type { TRule } from '${config.moduleDependencies ? "../../dependencies" : "fela"}';`
7579
}
7680

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ export interface Configuration extends vscode.WorkspaceConfiguration {
77
typescriptFelaTheme: boolean;
88
typescriptFelaExtendProp: boolean;
99
includeReactImport: boolean;
10+
useAckeeFelaPackage: boolean;
1011
}

0 commit comments

Comments
 (0)