Skip to content

Commit

Permalink
📦 Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
chasingmaxwell committed Apr 15, 2019
0 parents commit 3a1f177
Show file tree
Hide file tree
Showing 10 changed files with 2,626 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
37 changes: 37 additions & 0 deletions README.md
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.
36 changes: 36 additions & 0 deletions package.json
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"
}
}
75 changes: 75 additions & 0 deletions pkg/dist-node/index.js
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;
13 changes: 13 additions & 0 deletions pkg/dist-src/index.js
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');
}
29 changes: 29 additions & 0 deletions pkg/package.json
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"
}
}
29 changes: 29 additions & 0 deletions src/index.js
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);
}
};
});
16 changes: 16 additions & 0 deletions src/index.ts
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');
}
7 changes: 7 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"target": "es2018",
"module": "system",
"moduleResolution": "node"
}
}
Loading

0 comments on commit 3a1f177

Please sign in to comment.