Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🎨 Migrate loadPresets to a single file
- Loading branch information
Showing
3 changed files
with
29 additions
and
17 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
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,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() | ||
}) | ||
) | ||
} |