-
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.
- Loading branch information
0 parents
commit 3a1f177
Showing
10 changed files
with
2,626 additions
and
0 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 @@ | ||
node_modules |
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 @@ | ||
# plugin-build-flowgen | ||
|
||
> A [@pika/pack](https://github.com/pikapkg/pack) build plugin. | ||
> Adds Flow type definitions generated from TypeScript definitions. | ||
|
||
## Install | ||
|
||
```sh | ||
# npm: | ||
npm install plugin-build-flowgen --save-dev | ||
# yarn: | ||
yarn add plugin-build-flowgen --dev | ||
``` | ||
|
||
|
||
## Usage | ||
|
||
```js | ||
{ | ||
"name": "example-package-json", | ||
"version": "1.0.0", | ||
"@pika/pack": { | ||
"pipeline": [ | ||
/* Generates the TypeScript definition files: */ | ||
["@pika/plugin-ts-standard-pkg"] | ||
/* Generates the Flow definition files: */ | ||
["@pika/plugin-build-flowgen"] | ||
] | ||
} | ||
} | ||
``` | ||
|
||
|
||
## Result | ||
|
||
Generate a corresponding `*.js.flow` file for every `*.d.ts` file inside the `dist-types` directory. |
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,36 @@ | ||
{ | ||
"name": "plugin-build-flowgen", | ||
"version": "0.0.0", | ||
"description": "A @pika/pack build plugin. Adds Flow type definitions generated from TypeScript definitions.", | ||
"main": "pkg/dist-node/index.js", | ||
"author": "Peter Sieg <[email protected]>", | ||
"license": "MIT", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"scripts": { | ||
"build": "pika-pack build" | ||
}, | ||
"@pika/pack": { | ||
"pipeline": [ | ||
[ | ||
"@pika/plugin-standard-pkg" | ||
], | ||
[ | ||
"@pika/plugin-build-node" | ||
] | ||
] | ||
}, | ||
"dependencies": { | ||
"fast-glob": "^2.2.6", | ||
"flowgen": "^1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@pika/pack": "^0.3.7", | ||
"@pika/plugin-build-node": "^0.3.14", | ||
"@pika/plugin-standard-pkg": "^0.3.14", | ||
"@pika/types": "^0.3.15", | ||
"@types/node": "^11.13.4", | ||
"typescript": "^3.4.3" | ||
} | ||
} |
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,75 @@ | ||
'use strict'; | ||
|
||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
|
||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
|
||
var fs = require('fs'); | ||
var fastGlob = _interopDefault(require('fast-glob')); | ||
var util = require('util'); | ||
var path = require('path'); | ||
var flowgen = require('flowgen'); | ||
|
||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { | ||
try { | ||
var info = gen[key](arg); | ||
var value = info.value; | ||
} catch (error) { | ||
reject(error); | ||
return; | ||
} | ||
|
||
if (info.done) { | ||
resolve(value); | ||
} else { | ||
Promise.resolve(value).then(_next, _throw); | ||
} | ||
} | ||
|
||
function _asyncToGenerator(fn) { | ||
return function () { | ||
var self = this, | ||
args = arguments; | ||
return new Promise(function (resolve, reject) { | ||
var gen = fn.apply(self, args); | ||
|
||
function _next(value) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); | ||
} | ||
|
||
function _throw(err) { | ||
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); | ||
} | ||
|
||
_next(undefined); | ||
}); | ||
}; | ||
} | ||
|
||
const writeFile = util.promisify(fs.writeFile); | ||
function build(_x) { | ||
return _build.apply(this, arguments); | ||
} | ||
|
||
function _build() { | ||
_build = _asyncToGenerator(function* ({ | ||
out, | ||
reporter | ||
}) { | ||
yield Promise.all((yield fastGlob([`${path.join(out, 'dist-types')}/**/*.d.ts`])).map( | ||
/*#__PURE__*/ | ||
function () { | ||
var _ref = _asyncToGenerator(function* (file) { | ||
return writeFile(path.join(file.replace(/.d.ts$/, '.js.flow')), flowgen.compiler.compileDefinitionFile(file)); | ||
}); | ||
|
||
return function (_x2) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}())); | ||
reporter.created(path.join(out, 'dist-types', 'index.js.flow'), 'types'); | ||
}); | ||
return _build.apply(this, arguments); | ||
} | ||
|
||
exports.build = build; |
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,13 @@ | ||
import * as fs from 'fs'; | ||
import fastGlob from 'fast-glob'; | ||
import { promisify } from 'util'; | ||
import { join } from 'path'; | ||
import { compiler } from 'flowgen'; | ||
const writeFile = promisify(fs.writeFile); | ||
export async function build({ | ||
out, | ||
reporter | ||
}) { | ||
await Promise.all((await fastGlob([`${join(out, 'dist-types')}/**/*.d.ts`])).map(async file => writeFile(join(file.replace(/.d.ts$/, '.js.flow')), compiler.compileDefinitionFile(file)))); | ||
reporter.created(join(out, 'dist-types', 'index.js.flow'), 'types'); | ||
} |
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,29 @@ | ||
{ | ||
"name": "plugin-build-flowgen", | ||
"description": "A @pika/pack build plugin. Adds flow type definitions generated from typescript definitions.", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"files": [ | ||
"dist-*/", | ||
"bin/" | ||
], | ||
"esnext": "dist-src/index.js", | ||
"main": "dist-node/index.js", | ||
"pika": true, | ||
"sideEffects": false, | ||
"dependencies": { | ||
"fast-glob": "^2.2.6", | ||
"flowgen": "^1.8.0" | ||
}, | ||
"devDependencies": { | ||
"@pika/pack": "^0.3.7", | ||
"@pika/plugin-build-node": "^0.3.14", | ||
"@pika/plugin-standard-pkg": "^0.3.14", | ||
"@pika/types": "^0.3.15", | ||
"@types/node": "^11.13.4", | ||
"typescript": "^3.4.3" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
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,29 @@ | ||
System.register(["fs", "fast-glob", "util", "path"], function (exports_1, context_1) { | ||
"use strict"; | ||
var fs, fast_glob_1, util_1, path_1, writeFile; | ||
var __moduleName = context_1 && context_1.id; | ||
async function afterBuild({ out, reporter }) { | ||
await Promise.all((await fast_glob_1.default([`${path_1.join(out, 'dist-types')}/**/*.d.ts`])).map(async (file) => writeFile(path_1.join(file.replace(/.d.ts$/, '.js.flow')), compiler.compileDefinitionFile(file)))); | ||
reporter.created(path_1.join(out, 'dist-types', 'index.js.flow'), 'types'); | ||
} | ||
exports_1("afterBuild", afterBuild); | ||
return { | ||
setters: [ | ||
function (fs_1) { | ||
fs = fs_1; | ||
}, | ||
function (fast_glob_1_1) { | ||
fast_glob_1 = fast_glob_1_1; | ||
}, | ||
function (util_1_1) { | ||
util_1 = util_1_1; | ||
}, | ||
function (path_1_1) { | ||
path_1 = path_1_1; | ||
} | ||
], | ||
execute: function () { | ||
writeFile = util_1.promisify(fs.writeFile); | ||
} | ||
}; | ||
}); |
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,16 @@ | ||
import { BuilderOptions } from '@pika/types'; | ||
import * as fs from 'fs'; | ||
import fastGlob from 'fast-glob'; | ||
import { promisify } from 'util'; | ||
import { join } from 'path'; | ||
import { compiler } from 'flowgen'; | ||
|
||
const writeFile = promisify(fs.writeFile); | ||
|
||
export async function build({ out, reporter }: BuilderOptions): Promise<void> { | ||
await Promise.all((await fastGlob([`${join(out, 'dist-types')}/**/*.d.ts`])).map(async (file: string): Promise<void> => writeFile( | ||
join(file.replace(/.d.ts$/, '.js.flow')), | ||
compiler.compileDefinitionFile(file) | ||
))); | ||
reporter.created(join(out, 'dist-types', 'index.js.flow'), 'types'); | ||
} |
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,7 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es2018", | ||
"module": "system", | ||
"moduleResolution": "node" | ||
} | ||
} |
Oops, something went wrong.