-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add web framework plugin types and script to fetch plugin t…
…ypes
- Loading branch information
Showing
14 changed files
with
412 additions
and
216 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
node_modules | ||
node_modules/ | ||
npm-debug.log | ||
coverage | ||
.DS_Store | ||
.vscode | ||
build/ | ||
*.tgz | ||
src/plugins/types/* | ||
!src/plugins/types/index.d.ts |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,40 @@ | ||
import { flatten, globP, mkdirP, ncpP, readFileP, spawnP, tmpDirP, writeFileP } from './utils'; | ||
|
||
const TYPES_DIRECTORY = 'src/plugins/types'; | ||
|
||
async function mkdirSafeP(dir: string) { | ||
try { | ||
await mkdirP(dir); | ||
return true; | ||
} catch (e) { | ||
if (e.code !== 'EEXIST') { | ||
throw new Error(`Error creating directory ${dir}`); | ||
} | ||
return false; | ||
} | ||
} | ||
|
||
export default async function() { | ||
await mkdirSafeP(TYPES_DIRECTORY); | ||
|
||
const indexTs = (await readFileP(`${TYPES_DIRECTORY}/index.d.ts`, 'utf8') as string) | ||
.split('\n'); | ||
for (const line of indexTs) { | ||
const matches = line.match(/^import \* as .* from '\.\/(.*)';\s*\/\/\s*(.*)@(.*)$/); | ||
if (!matches) { | ||
continue; | ||
} | ||
const [_0, packageName, name, version] = matches; | ||
const installDir = `${TYPES_DIRECTORY}/${packageName}`; | ||
if (await mkdirSafeP(installDir)) { | ||
await spawnP('npm', ['init', '-y'], { | ||
cwd: installDir | ||
}); | ||
await spawnP('npm', ['install', `@types/${name}@${version}`], { | ||
cwd: installDir | ||
}); | ||
await writeFileP(`${installDir}/index.ts`, | ||
`import * as _ from '${name}'; export = _;\n`, 'utf8'); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.