Skip to content

Commit

Permalink
🎨 Migrate loadPresets to a single file
Browse files Browse the repository at this point in the history
  • Loading branch information
robb-j committed May 7, 2019
1 parent 46247ee commit 55faaed
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/cli.ts
Expand Up @@ -21,6 +21,6 @@ const message = trimInlineTemplate`

await Puggle.runFromEnvironment(process.argv[2])
} catch (error) {
console.log(error.message)
console.log(error)
}
})()
17 changes: 1 addition & 16 deletions src/utils/index.ts
@@ -1,10 +1,8 @@
import { join } from 'path'

import { StringKeyed } from '../types'
import { exec, glob } from './promisified'

export * from './promisified'
export * from './trimInlineTemplate'
export * from './loadPresets'

/**
* Get the last directory in a path
Expand Down Expand Up @@ -36,16 +34,3 @@ export function sortObjectKeys<T extends StringKeyed>(input: T): T {

return output
}

export async function loadPresets() {
const { stdout } = await exec('npm root -g')

let cwd = stdout.trim()

const matches = await glob('*/puggle-preset-*', { cwd })

return matches.map(name => {
const Preset = require(join(cwd, name))
return new Preset()
})
}
27 changes: 27 additions & 0 deletions src/utils/loadPresets.ts
@@ -0,0 +1,27 @@
// import Module from 'module'
import { join, relative } from 'path'

import { exec, glob } from './promisified'

export async function loadPresets() {
const { stdout } = await exec('npm root -g')

let cwd = stdout.trim()

// const relativeRequire = Module.createRequireFromPath(cwd)

const matches = await glob('*/puggle-preset-*', { cwd })

return Promise.all(
matches.map(async name => {
let path = join(cwd, name)

// console.log(path)
// console.log(require.resolve(path))
// console.log(require.resolve.paths(path))

const Preset = require(path)
return new Preset()
})
)
}

0 comments on commit 55faaed

Please sign in to comment.