forked from fable-compiler/Fable
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Fable transformer for React Native
Fixes fable-compiler#804.
- Loading branch information
Showing
8 changed files
with
1,276 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env node | ||
|
||
const net = require('net'); | ||
const childProcess = require('child_process'); | ||
|
||
if (require.main === module) { | ||
const [, , port, msg] = process.argv; | ||
|
||
let buff = ''; | ||
|
||
const c = new net.Socket(); | ||
c.connect({ port }, () => c.write(msg)); | ||
|
||
c.on('data', x => (buff += x)); | ||
// eslint-disable-next-line no-console | ||
c.on('close', () => console.log(buff)); | ||
} | ||
|
||
module.exports = args => { | ||
const resp = childProcess.spawnSync('node', [ | ||
`${__dirname}/client.js`, | ||
args.port, | ||
JSON.stringify(args) | ||
]); | ||
|
||
resp.stderr = resp.stderr.toString(); | ||
resp.stdout = resp.stdout.toString(); | ||
|
||
if (resp.status !== 0) throw new Error(resp.stderr); | ||
|
||
return resp; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{ | ||
"plugins": [ | ||
"prettier" | ||
], | ||
"rules": { | ||
"no-var": 2, | ||
"linebreak-style": [ | ||
2, | ||
"unix" | ||
], | ||
"no-console": "off", | ||
"curly": [ | ||
2, | ||
"multi", | ||
"consistent" | ||
], | ||
"prefer-const": [ | ||
"error", | ||
{ | ||
"destructuring": "all", | ||
"ignoreReadBeforeAssign": false | ||
} | ||
], | ||
"prettier/prettier": [ | ||
"error", | ||
{ | ||
"singleQuote": true | ||
} | ||
] | ||
}, | ||
"env": { | ||
"es6": true, | ||
"node": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 6, | ||
"sourceType": "module" | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"prettier" | ||
] | ||
} |
Empty file.
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,33 @@ | ||
// react-native start --transformer ./smTransform.js | ||
|
||
const transformer = require('react-native/packager/transformer'); | ||
const client = require('fable-utils/client-sync'); | ||
const babelPlugins = require('fable-utils/babel-plugins'); | ||
const babel = require('babel-core'); | ||
|
||
const isFableFile = /\.(?:fs|fsx|fsproj)$/; | ||
const fableCoreVersion = null; | ||
const DEFAULT_PORT = process.env.FABLE_SERVER_PORT != null | ||
? parseInt(process.env.FABLE_SERVER_PORT, 10) | ||
: 61225; | ||
|
||
const customPlugins = [ | ||
babelPlugins.getRemoveUnneededNulls(), | ||
babelPlugins.getTransformMacroExpressions(babel.template) | ||
]; | ||
|
||
module.exports = (src, filename, options) => { | ||
options = options || {}; | ||
if (isFableFile.test(filename)) { | ||
if (babelOpts.sourceMaps) { | ||
fsCode = src; | ||
babelOpts.sourceMaps = true; | ||
babelOpts.sourceFileName = relative( | ||
process.cwd(), | ||
fileName.replace(/\\/g, '/') | ||
); | ||
} | ||
|
||
return babel.transformFromAst(data, fsCode, babelOpts).code; | ||
} else {return transformer.transform(src, filename, options);} | ||
}; |
38 changes: 38 additions & 0 deletions
38
src/typescript/react-native-fable-transformer/package.json
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,38 @@ | ||
{ | ||
"name": "react-native-fable-transformer", | ||
"version": "1.0.3", | ||
"description": "React Native transformer for Fable", | ||
"main": "index.js", | ||
"scripts": { | ||
"eslint": "eslint ./" | ||
}, | ||
"repository": "https://github.com/fable-compiler/Fable/tree/master/src/typescript/react-native-fable-transformer", | ||
"publishConfig": { | ||
"registry": " https://registry.npmjs.org" | ||
}, | ||
"keywords": [ | ||
"react native", | ||
"native", | ||
"F#", | ||
"transformer" | ||
], | ||
"author": "Joe Grund", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/fable-compiler/Fable/issues" | ||
}, | ||
"homepage": "https://github.com/fable-compiler/Fable/tree/master/src/typescript/react-native-fable-transformer#readme", | ||
"devDependencies": { | ||
"eslint": "3.19.0", | ||
"eslint-config-prettier": "1.7.0", | ||
"eslint-plugin-prettier": "2.0.1", | ||
"prettier": "1.3.1" | ||
}, | ||
"peerDependencies": { | ||
"babel-core": "^6.24.1", | ||
"fable-core": "^1.0.0-narumi-906" | ||
}, | ||
"dependencies": { | ||
"fable-utils": "^1.0.0" | ||
} | ||
} |
Oops, something went wrong.