@teleporthq/teleport-project-plugin-styled-components 0.21.9
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/LICENSE +21 -0
- package/Readme.md +14 -0
- package/dist/cjs/constant.d.ts +1 -0
- package/dist/cjs/constant.js +7 -0
- package/dist/cjs/constant.js.map +1 -0
- package/dist/cjs/gatsby.d.ts +3 -0
- package/dist/cjs/gatsby.js +104 -0
- package/dist/cjs/gatsby.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +98 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/next.d.ts +3 -0
- package/dist/cjs/next.js +110 -0
- package/dist/cjs/next.js.map +1 -0
- package/dist/cjs/react.d.ts +3 -0
- package/dist/cjs/react.js +87 -0
- package/dist/cjs/react.js.map +1 -0
- package/dist/cjs/tsconfig.tsbuildinfo +1 -0
- package/dist/esm/constant.d.ts +1 -0
- package/dist/esm/constant.js +4 -0
- package/dist/esm/constant.js.map +1 -0
- package/dist/esm/gatsby.d.ts +3 -0
- package/dist/esm/gatsby.js +96 -0
- package/dist/esm/gatsby.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +95 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/next.d.ts +3 -0
- package/dist/esm/next.js +102 -0
- package/dist/esm/next.js.map +1 -0
- package/dist/esm/react.d.ts +3 -0
- package/dist/esm/react.js +79 -0
- package/dist/esm/react.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +35 -0
- package/src/constant.ts +3 -0
- package/src/gatsby.ts +57 -0
- package/src/index.ts +52 -0
- package/src/next.ts +96 -0
- package/src/react.ts +31 -0
- package/tsconfig.json +9 -0
package/src/next.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FileType,
|
|
3
|
+
ProjectPluginStructure,
|
|
4
|
+
ReactNativeStyleVariation,
|
|
5
|
+
} from '@teleporthq/teleport-types'
|
|
6
|
+
import { createStyleSheetPlugin } from '@teleporthq/teleport-plugin-react-styled-components'
|
|
7
|
+
import importStatementsPlugin from '@teleporthq/teleport-plugin-import-statements'
|
|
8
|
+
import prettierJS from '@teleporthq/teleport-postprocessor-prettier-js'
|
|
9
|
+
import MagicString from 'magic-string'
|
|
10
|
+
import { STYLED_DEPENDENCIES } from './constant'
|
|
11
|
+
|
|
12
|
+
export const nextBeforeModifier = async (structure: ProjectPluginStructure) => {
|
|
13
|
+
const { strategy } = structure
|
|
14
|
+
|
|
15
|
+
if (strategy.id !== 'teleport-project-next') {
|
|
16
|
+
throw new Error('Plugin can be used only with teleport-project-next')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
strategy.style = ReactNativeStyleVariation.StyledComponents
|
|
20
|
+
if (strategy?.projectStyleSheet?.generator) {
|
|
21
|
+
strategy.projectStyleSheet.plugins = [createStyleSheetPlugin(), importStatementsPlugin]
|
|
22
|
+
strategy.projectStyleSheet.postprocessors = [prettierJS]
|
|
23
|
+
strategy.framework.config.isGlobalStylesDependent = false
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const nextAfterModifier = async (structure: ProjectPluginStructure) => {
|
|
28
|
+
const { files, dependencies } = structure
|
|
29
|
+
|
|
30
|
+
if (!files.get('entry')) {
|
|
31
|
+
throw new Error(`Entry File is missing from the generated project, _document file not found`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const fileContent = files.get('entry').files[0].content
|
|
35
|
+
const magicString = new MagicString(fileContent.replace('/n', '//n'))
|
|
36
|
+
|
|
37
|
+
magicString.appendRight(70, `\nimport { ServerStyleSheet } from 'styled-components' \n`)
|
|
38
|
+
magicString.appendRight(
|
|
39
|
+
114,
|
|
40
|
+
`\nstatic getInitialProps({ renderPage }) {
|
|
41
|
+
const sheet = new ServerStyleSheet();
|
|
42
|
+
const page = renderPage((App) => (props) =>
|
|
43
|
+
sheet.collectStyles(<App {...props} />),
|
|
44
|
+
);
|
|
45
|
+
const styleTags = sheet.getStyleElement();
|
|
46
|
+
|
|
47
|
+
return { ...page, styleTags };
|
|
48
|
+
}\n\n`
|
|
49
|
+
)
|
|
50
|
+
magicString.appendRight(175, `\n{this.props.styleTags}`)
|
|
51
|
+
|
|
52
|
+
const formattedCode = prettierJS({
|
|
53
|
+
[FileType.JS]: magicString.toString(),
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const babelRc = `{
|
|
57
|
+
"presets": [
|
|
58
|
+
"next/babel"
|
|
59
|
+
],
|
|
60
|
+
"plugins": [
|
|
61
|
+
[
|
|
62
|
+
"styled-components",
|
|
63
|
+
{
|
|
64
|
+
"ssr": true,
|
|
65
|
+
"displayName": true,
|
|
66
|
+
"preprocess": false
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
]
|
|
70
|
+
}`
|
|
71
|
+
|
|
72
|
+
files.set('entry', {
|
|
73
|
+
path: ['pages'],
|
|
74
|
+
files: [
|
|
75
|
+
{
|
|
76
|
+
name: '_document',
|
|
77
|
+
fileType: FileType.JS,
|
|
78
|
+
content: formattedCode[FileType.JS],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
files.set('.babelrc', {
|
|
84
|
+
path: [],
|
|
85
|
+
files: [
|
|
86
|
+
{
|
|
87
|
+
name: '.babelrc',
|
|
88
|
+
content: babelRc,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
Object.keys(STYLED_DEPENDENCIES).forEach((dep: string) => {
|
|
94
|
+
dependencies[dep] = STYLED_DEPENDENCIES[dep]
|
|
95
|
+
})
|
|
96
|
+
}
|
package/src/react.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ProjectPluginStructure, ReactStyleVariation } from '@teleporthq/teleport-types'
|
|
2
|
+
import {
|
|
3
|
+
createStyleSheetPlugin,
|
|
4
|
+
createReactStyledComponentsPlugin,
|
|
5
|
+
} from '@teleporthq/teleport-plugin-react-styled-components'
|
|
6
|
+
import importStatementsPlugin from '@teleporthq/teleport-plugin-import-statements'
|
|
7
|
+
import reactAppRoutingPlugin from '@teleporthq/teleport-plugin-react-app-routing'
|
|
8
|
+
import { STYLED_DEPENDENCIES } from './constant'
|
|
9
|
+
|
|
10
|
+
export const reactBeforeModifier = async (structure: ProjectPluginStructure) => {
|
|
11
|
+
const { strategy } = structure
|
|
12
|
+
|
|
13
|
+
strategy.style = ReactStyleVariation.StyledComponents
|
|
14
|
+
if (strategy?.projectStyleSheet?.generator) {
|
|
15
|
+
strategy.projectStyleSheet.plugins = [createStyleSheetPlugin(), importStatementsPlugin]
|
|
16
|
+
strategy.router = {
|
|
17
|
+
...strategy.router,
|
|
18
|
+
plugins: [createReactStyledComponentsPlugin(), reactAppRoutingPlugin, importStatementsPlugin],
|
|
19
|
+
}
|
|
20
|
+
if (strategy.framework?.config) {
|
|
21
|
+
strategy.framework.config.isGlobalStylesDependent = false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const reactAfterModifier = async (structure: ProjectPluginStructure) => {
|
|
27
|
+
const { dependencies } = structure
|
|
28
|
+
Object.keys(STYLED_DEPENDENCIES).forEach((dep: string) => {
|
|
29
|
+
dependencies[dep] = STYLED_DEPENDENCIES[dep]
|
|
30
|
+
})
|
|
31
|
+
}
|