-
-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #784 from idyll-lang/compile-user-components
add functionality to compile JSX user components
- Loading branch information
Showing
50 changed files
with
160 additions
and
436 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
packages/idyll-cli/src/pipeline/compile-user-components.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const fs = require('fs'); | ||
const { readdir, writeFile } = fs.promises; | ||
const { ensureDir, pathExists } = require('fs-extra'); | ||
const path = require('path'); | ||
const babel = require('@babel/core'); | ||
|
||
module.exports = async paths => { | ||
let componentDirIndex = 0; | ||
const tempComponentDir = path.join(paths.TMP_DIR, 'components'); | ||
await ensureDir(tempComponentDir); | ||
for (const dir of paths.COMPONENT_DIRS) { | ||
const hasPath = await pathExists(dir); | ||
if (!hasPath) { | ||
continue; | ||
} | ||
const tempComponentSubdir = path.join( | ||
tempComponentDir, | ||
`${componentDirIndex}` | ||
); | ||
await ensureDir(tempComponentSubdir); | ||
const files = await readdir(dir); | ||
for (const file of files) { | ||
const { code } = await babel.transformFileAsync(path.join(dir, file), { | ||
presets: ['@babel/preset-react'] | ||
}); | ||
await writeFile( | ||
path.join(tempComponentSubdir, path.basename(file)), | ||
code, | ||
'utf-8' | ||
); | ||
} | ||
paths.COMPONENT_DIRS[componentDirIndex] = tempComponentSubdir; | ||
componentDirIndex++; | ||
} | ||
|
||
return paths; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
packages/idyll-cli/test/basic-project/src/components/CapitalPascal.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,11 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
class PascalComponent extends React.PureComponent { | ||
render() { | ||
const {hasError, updateProps, idyll, ...props} = this.props; | ||
const { hasError, updateProps, idyll, ...props } = this.props; | ||
|
||
return ( | ||
<div {...props}> | ||
This is a custom component | ||
</div> | ||
); | ||
return <div {...props}>This is a custom component</div>; | ||
} | ||
} | ||
|
||
module.exports = PascalComponent; | ||
export default PascalComponent; |
22 changes: 7 additions & 15 deletions
22
packages/idyll-cli/test/basic-project/src/components/custom-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,17 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
class CustomComponent extends React.PureComponent { | ||
render() { | ||
const {hasError, updateProps, idyll, ...props} = this.props; | ||
return ( | ||
<div {...props}> | ||
This is a custom component | ||
</div> | ||
); | ||
const { hasError, updateProps, idyll, ...props } = this.props; | ||
return <div {...props}>This is a custom component</div>; | ||
} | ||
} | ||
|
||
module.exports = CustomComponent; | ||
export default CustomComponent; | ||
|
||
module.exports.IndexedComponent = class extends React.PureComponent { | ||
CustomComponent.IndexedComponent = class extends React.PureComponent { | ||
render() { | ||
const {hasError, updateProps, idyll, ...props} = this.props; | ||
return ( | ||
<div {...props}> | ||
This is another custom component | ||
</div> | ||
); | ||
const { hasError, updateProps, idyll, ...props } = this.props; | ||
return <div {...props}>This is another custom component</div>; | ||
} | ||
}; |
8 changes: 4 additions & 4 deletions
8
packages/idyll-cli/test/basic-project/src/components/functional-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
module.exports = () => { | ||
return <div>Let's put the fun back in functional!</div> | ||
} | ||
export default () => { | ||
return <div>Let's put the fun back in functional!</div>; | ||
}; |
5 changes: 3 additions & 2 deletions
5
packages/idyll-cli/test/basic-project/src/components/functional-default-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
export default () => | ||
export default () => ( | ||
<div> | ||
This is some text | ||
<button>And a button</button> | ||
Then some more text | ||
</div> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/idyll-cli/test/custom-ast/src/components/functional-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
module.exports = () => { | ||
export default () => { | ||
return <div>Let's put the fun back in functional!</div>; | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/idyll-cli/test/custom-ast/src/components/functional-default-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
export default () => ( | ||
<div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
packages/idyll-cli/test/env-options/outer-project/components/functional-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
module.exports = () => { | ||
export default () => { | ||
return <div>Let's put the fun back in functional!</div>; | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/idyll-cli/test/env-options/outer-project/components/functional-default-component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
const React = require('react'); | ||
import React from 'react'; | ||
|
||
export default () => ( | ||
<div> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.