Skip to content
This repository was archived by the owner on Jun 11, 2022. It is now read-only.

Commit

Permalink
wip: create runner (transpiler) to allow for consumption of
Browse files Browse the repository at this point in the history
configuration
  • Loading branch information
hyperupcall committed Jun 6, 2020
1 parent 76be159 commit ec841df
Show file tree
Hide file tree
Showing 30 changed files with 269 additions and 129 deletions.
Empty file added .tabnine_root
Empty file.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"license": "MIT",
"devDependencies": {
"@types/babel-generator": "^6.25.3",
"@types/babel-types": "^7.0.7",
Expand All @@ -10,6 +11,7 @@
"@types/jest": "^25.2.1",
"@types/lodash": "^4.14.150",
"@types/lodash.merge": "^4.6.6",
"@types/lodash.throttle": "^4.1.6",
"@types/lodash.uniq": "^4.5.6",
"@types/minimist": "^1.2.0",
"@types/node": "^13.13.5",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint.config.js is non-standard (prefer .eslintrc.js)

/**
* @param {import("fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @param {import("../../../fox-transpiler/node_modules/fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @return {Record<string, any>}
*/
export default function(fox) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// (meaning only .htmlhintrc is usually valid)

/**
* @param {import("fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @param {import("../../../fox-transpiler/node_modules/fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @return {Record<string, any>}
*/
export default function(fox) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/**
* @param {import("fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @param {import("../../../fox-transpiler/node_modules/fox-suite/node_modules/fox-types/types").IFoxConfig} [fox] - `fox.config.js` configuration object
* @return {Record<string, any>}
*/
export default function(fox) {
Expand Down
14 changes: 0 additions & 14 deletions packages/fox-runner/input.js

This file was deleted.

18 changes: 0 additions & 18 deletions packages/fox-runner/output.js

This file was deleted.

23 changes: 0 additions & 23 deletions packages/fox-runner/src/index.ts

This file was deleted.

15 changes: 0 additions & 15 deletions packages/fox-suite/@types/index.d.ts

This file was deleted.

3 changes: 3 additions & 0 deletions packages/fox-suite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"fox": "./bin/fox.js"
},
"dependencies": {
"chokidar": "^3.4.0",
"colorette": "^1.2.0",
"debug": "^4.1.1",
"esm": "^3.2.25",
Expand All @@ -31,7 +32,9 @@
"fox-plugin-prettier": "workspace:^0.1.0",
"fox-plugin-stylelint": "workspace:^0.1.0",
"fox-runner": "workspace:^0.1.1",
"fox-transpiler": "workspace:^0.1.1",
"fox-utils": "^0.1.1",
"lodash.throttle": "^4.1.1",
"lodash.uniq": "^4.5.0",
"minimist": "^1.2.5",
"prompts": "^2.3.2"
Expand Down
42 changes: 31 additions & 11 deletions packages/fox-suite/src/action.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { IActionFunction } from '../@types/index'
import type { IAction } from 'fox-types'
import chokidar from 'chokidar'
import throttle from 'lodash.throttle'

/**
* @description bootstraps, formats, or lints a project
*/
export async function doAction({
action: actionFunctions,
actionFunctions,
projectData
}: IActionFunction): Promise<void> {
}: IAction): Promise<void> {
if (Array.isArray(actionFunctions)) {
for (const fixFunction of actionFunctions) {
if (!fixFunction) continue
Expand All @@ -15,20 +17,38 @@ export async function doAction({
}
} else if (actionFunctions) {
await actionFunctions(projectData.foxConfig)
} else {
throw new Error('passed parameter was not as expected')
}

process.exit(1)
}

export async function watchAndDoAction({
action: actionFunctions,
actionFunctions,
projectData
}: IActionFunction): Promise<void> {
}: IAction): Promise<void> {
// test for watchers and then do action
console.log('fake watching')
const watcher = await chokidar.watch('**/**', {
ignored: [
'**/node_modules/**',
'**/web_modules/**',
'**/.git/**',
'**/.hg/**'
],
persistent: true,
cwd: projectData.location
})

await doAction({
action: actionFunctions,
projectData
let totalFiles = 0
watcher.on('add', path => totalFiles++)
watcher.on('unlink', path => totalFiles--)
watcher.on('change', async path => {
console.log(`${path} of ${totalFiles} files changed. recompiling config files and executing fixers`)

await doAction({
actionFunctions,
projectData
})
})

console.log('starting watcher')
}
40 changes: 31 additions & 9 deletions packages/fox-suite/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as foxUtils from 'fox-utils'
import { transpileConfig } from 'fox-transpiler'
import * as util from './util'
import { doAction } from './action';
import { doAction, watchAndDoAction } from './action';
import type { ParsedArgs } from "minimist"
import { IPluginExportIndex } from 'fox-types';
import debug from './debug'
Expand All @@ -11,18 +12,18 @@ import * as c from 'colorette'
*/
export async function cli(argv: ParsedArgs): Promise<void> {
debug('activating cli. passed args: %o', argv)
const [projectData, foxPlugins] = await Promise.all([
const [projectData, foxPluginPaths] = await Promise.all([
foxUtils.getProjectData(), util.getInstalledFoxPlugins()
])

const promises: Promise<IPluginExportIndex>[] = []
for (const foxPluginPath of foxPlugins) {
for (const foxPluginPath of foxPluginPaths) {
promises.push(import(foxPluginPath))
}
const foxPluginModules = await Promise.all(promises)
const foxPlugins = await Promise.all(promises)

if (argv.help) {
const pluginName = 'fox-suite'
const pluginName = 'fox'
const helpText = `Usage:
${pluginName}
Expand All @@ -35,21 +36,42 @@ Options:
--lint Lint files with all linters
--help Show help
Notes:
Not passing any options opens the tui
Examples:
${pluginName}
${pluginName} --bootstrap
${pluginName} --help`;
console.info(helpText)
} else if(argv.bootstrap) {
await transpileConfig({
foxPluginPaths,
projectData
})
await doAction({
action: util.pickModuleProperty(foxPluginModules, "bootstrapFunction"),
actionFunctions: util.pickModuleProperty(foxPlugins, "bootstrapFunction"),
projectData
})
console.log(c.bold(c.green('bootstrap complete')))
} else if (argv.format) {
} else if (argv.fix) {
await transpileConfig({
foxPluginPaths,
projectData
})
await doAction({
action: util.pickModuleProperty(foxPluginModules, "fixFunction"),
actionFunctions: util.pickModuleProperty(foxPlugins, "fixFunction"),
projectData
})
console.log(c.bold(c.green('fix complete')))
} else if (argv.watch) {
await transpileConfig({
foxPluginPaths,
projectData
})
await watchAndDoAction({
actionFunctions: util.pickModuleProperty(foxPlugins, "fixFunction"),
projectData
})
console.log(c.bold(c.green('format complete')))
}
}
30 changes: 19 additions & 11 deletions packages/fox-suite/src/tui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { doAction, watchAndDoAction } from './action';
import * as util from './util'
import debug from './debug'
import * as c from 'colorette'
import { transpileConfig } from 'fox-transpiler'

/**
* @description if no command line arguments were given,
Expand Down Expand Up @@ -34,14 +35,13 @@ export async function tui(): Promise<void> {
const bootstrapChoices: prompts.Choice[] = []
const fixChoices: prompts.Choice[] = []

const foxPluginModules = (await Promise.all(promises)).filter(Boolean)
for (let i = 0; i < foxPluginModules.length; ++i) {
const foxPluginModule = foxPluginModules[i]
const foxPluginPath = foxPluginPaths[i]
const foxPlugins = (await Promise.all(promises)).filter(Boolean)

debug('processing foxPluginModule %s', foxPluginModule.info.name)
for (let i = 0; i < foxPlugins.length; ++i) {
const foxPlugin = foxPlugins[i]
const foxPluginPath = foxPluginPaths[i]

const foxPlugin: IPluginExportIndex = foxPluginModule
debug('processing foxPluginModule %s', foxPlugin.info.name)

if (!foxPlugin.info.name || !foxPlugin.info) {
throw new Error(
Expand Down Expand Up @@ -70,13 +70,13 @@ export async function tui(): Promise<void> {
if (bootstrapChoices.length > 2) bootstrapChoices.unshift({
title: 'All',
description: 'Bootstrap all configuration',
value: util.pickModuleProperty(foxPluginModules, "bootstrapFunction")
value: util.pickModuleProperty(foxPlugins, "bootstrapFunction")
})

if (fixChoices.length > 2) fixChoices.unshift({
title: 'All',
description: 'Format files from all config',
value: util.pickModuleProperty(foxPluginModules, "fixFunction")
value: util.pickModuleProperty(foxPlugins, "fixFunction")
})

const actionChoices: prompts.Choice[] = []
Expand Down Expand Up @@ -112,7 +112,7 @@ export async function tui(): Promise<void> {
})

await doAction({
action: bootstrap,
actionFunctions: bootstrap,
projectData
})

Expand All @@ -124,8 +124,12 @@ export async function tui(): Promise<void> {
choices: fixChoices
})

await transpileConfig({
foxPluginPaths,
projectData
})
await doAction({
action: fixFunctions,
actionFunctions: fixFunctions,
projectData
})
} else if (action === 'watch') {
Expand All @@ -136,8 +140,12 @@ export async function tui(): Promise<void> {
choices: fixChoices
})

await transpileConfig({
foxPluginPaths,
projectData
})
await watchAndDoAction({
action: fixFunctions,
actionFunctions: fixFunctions,
projectData
})
}
Expand Down
4 changes: 2 additions & 2 deletions packages/fox-suite/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { Dirent } from 'fs'
import * as foxUtils from 'fox-utils'
import { spawn } from 'child_process'
import { IPluginExportIndex } from "fox-types";
import type { IActionFunction } from '../@types/index'
import type { IAction } from 'fox-types'
import debug from './debug'

// HACK: this could be less dirty
Expand Down Expand Up @@ -119,7 +119,7 @@ export function run(script: string): void {
}

type actionFunctions = "bootstrapFunction" | "fixFunction"
type fns = IActionFunction["action"]
type fns = IAction["actionFunctions"]
export const pickModuleProperty = (foxPluginModules: IPluginExportIndex[], actionFunctions: actionFunctions): fns => {
const pickedFunctions: fns = []
for (const foxPluginModule of foxPluginModules) {
Expand Down
2 changes: 1 addition & 1 deletion packages/fox-suite/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"path": "../fox-test"
},
{
"path": "../fox-runner"
"path": "../fox-transpiler"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "fox-runner",
"name": "fox-transpiler",
"version": "0.1.1",
"description": "",
"main": "build",
Expand Down Expand Up @@ -27,6 +27,7 @@
"babel-plugin-fox-runner": "workspace:^1.0.0",
"esm": "^3.2.25",
"fox-esm": "workspace:^0.1.0",
"fox-utils": "workspace:^0.1.1",
"rollup": "^2.13.1"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit ec841df

Please sign in to comment.