-
-
Notifications
You must be signed in to change notification settings - Fork 32
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
Showing
27 changed files
with
1,043 additions
and
533 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { task, desc, option, strict } from 'foy' | ||
import * as globby from 'globby' | ||
|
||
type Options = { | ||
readonly runTests: boolean | ||
} | ||
|
||
type DevOptions = { | ||
readonly namespace: string | ||
readonly test: string | ||
} | ||
|
||
desc('Build dist') | ||
option('-t, --run-tests', 'run tests') | ||
strict() | ||
task<Options>('dist', async ctx => { | ||
await ctx.exec([ | ||
'yarn clean', | ||
'yarn re:clean', | ||
'yarn re:build', | ||
'yarn transform all', | ||
'yarn generate docs', | ||
'node esbuild.config.js', | ||
]) | ||
|
||
const files = await globby('dist/**/index.js') | ||
const js = files.join(' ') | ||
|
||
await ctx.exec( | ||
`node node_modules/.bin/jscodeshift --run-in-band -t tools/javascript-codemods/post/index.ts ${js}`, | ||
) | ||
|
||
await ctx.exec(['yarn generate tsc --esm --cjs', 'yarn generate flow']) | ||
|
||
if (ctx.options.runTests) { | ||
await ctx.exec('yarn test run -c') | ||
} | ||
}) | ||
|
||
desc('Build for development purposes') | ||
option('-t, --test <name>', 'run tests for a single file') | ||
option('-n, --namespace <name>', 'namespace') | ||
strict() | ||
task<DevOptions>('dev', async ctx => { | ||
if (!ctx.options.namespace) { | ||
throw new Error('-n is required') | ||
} | ||
|
||
await ctx.exec([ | ||
`yarn transform all -r -n ${ctx.options.namespace}`, | ||
'node esbuild.config.js', | ||
]) | ||
|
||
const files = await globby(`dist/**/${ctx.options.namespace}/index.js`) | ||
const js = files.join(' ') | ||
|
||
await ctx.exec( | ||
`node node_modules/.bin/jscodeshift --run-in-band -t tools/javascript-codemods/post/index.ts ${js}`, | ||
) | ||
|
||
await ctx.exec('yarn generate tsc --cjs') | ||
|
||
if (ctx.options.test) { | ||
await ctx.exec( | ||
`yarn test run -n ${ctx.options.namespace} -f ${ctx.options.test}`, | ||
) | ||
} | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,81 @@ | ||
import { task, desc, option, strict } from 'foy' | ||
import { compiler, beautify } from 'flowgen' | ||
|
||
import * as globby from 'globby' | ||
import * as path from 'path' | ||
|
||
type Options = { | ||
readonly rebuild: boolean | ||
} | ||
type TSCOptions = { | ||
readonly esm: boolean | ||
readonly cjs: boolean | ||
} | ||
|
||
const defaultEncoding = { encoding: 'utf8' } as const | ||
|
||
desc('Generate docs') | ||
option('-r, --rebuild', 'rebuild rescript files') | ||
strict() | ||
task<Options>('docs', async ctx => { | ||
const files = await globby('src/**/index.ts') | ||
const ts = files.join(' ') | ||
|
||
ctx.fs.mkdirp('docs/api/generated') | ||
|
||
if (ctx.options.rebuild) { | ||
await ctx.exec('yarn transform typescript -r') | ||
} | ||
|
||
await ctx.exec( | ||
`node node_modules/.bin/jscodeshift --run-in-band --extensions=ts --parser=ts -t tools/generate-docs/index.ts ${ts}`, | ||
) | ||
}) | ||
|
||
desc('Generate Flow types') | ||
task('flow', async ctx => { | ||
const entryFile = await ctx.fs.readFile('index.js.flow', defaultEncoding) | ||
const content = entryFile.replace(/.\/dist\//g, './') | ||
const files = await globby('dist/esm/**/*.d.ts') | ||
|
||
await ctx.fs.writeFile('dist/index.js.flow', content, defaultEncoding) | ||
await ctx.fs.writeFile('dist/index.mjs.flow', content, defaultEncoding) | ||
|
||
const defs = files.map(filename => { | ||
const fullpath = path.resolve(__dirname, '..', filename) | ||
const flowdef = beautify(compiler.compileDefinitionFile(fullpath)) | ||
const basename = path.basename(fullpath, '.d.ts') | ||
const filepath = path.dirname(fullpath) | ||
const definition = flowdef.replace(/import\s/g, 'import type ') | ||
|
||
return ctx.fs.writeFile( | ||
path.join(filepath, `${basename}.js.flow`), | ||
['// @flow', definition].join('\n\n'), | ||
defaultEncoding, | ||
) | ||
}) | ||
|
||
await Promise.all(defs) | ||
}) | ||
|
||
desc('Generate contributors in README.md') | ||
task('contributors', async ctx => { | ||
await ctx.exec('yarn all-contributors generate') | ||
}) | ||
|
||
desc('Generate tsc') | ||
option('--esm', 'esm') | ||
option('--cjs', 'cjs') | ||
strict() | ||
task<TSCOptions>('tsc', async ctx => { | ||
if (!ctx.options.esm && !ctx.options.cjs) { | ||
throw new Error('at least one param is required: --esm or --cjs') | ||
} | ||
|
||
await ctx.exec( | ||
[ | ||
ctx.options.cjs && 'yarn tsc --outDir ./dist/cjs', | ||
ctx.options.esm && 'yarn tsc --outDir ./dist/esm', | ||
].filter(Boolean), | ||
) | ||
}) |
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 @@ | ||
import { task, desc, option, strict } from 'foy' | ||
import * as globby from 'globby' | ||
|
||
type Options = { | ||
readonly namespace: string | ||
readonly file: string | ||
readonly coverage: boolean | ||
} | ||
|
||
desc('Run tests') | ||
option('-n, --namespace <name>', 'namespace') | ||
option('-f, --file <name>', 'file') | ||
option('-c, --coverage', 'coverage') | ||
strict() | ||
task<Options>('run', async ctx => { | ||
const coverage = ctx.options.coverage ? '--coverage' : '' | ||
|
||
const cmd = ['yarn', 'jest', coverage] | ||
|
||
if (ctx.options.namespace || ctx.options.file) { | ||
const namespace = ctx.options.namespace || '**' | ||
const file = ctx.options.file ? `${ctx.options.file}.test.ts` : '*.test.ts' | ||
|
||
const files = await globby(`__tests__/${namespace}/${file}`) | ||
|
||
cmd.push(...files) | ||
|
||
await ctx.exec(cmd.join(' ')) | ||
return | ||
} | ||
|
||
await ctx.exec(cmd.join(' ')) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.