-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: add script to fetch plugin types (#711)
PR-URL: #711
- Loading branch information
Showing
7 changed files
with
95 additions
and
14 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 |
---|---|---|
|
@@ -6,3 +6,5 @@ npm-debug.log | |
.vscode/ | ||
build/ | ||
*.tgz | ||
src/plugins/types/* | ||
!src/plugins/types/index.d.ts |
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,41 @@ | ||
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 async function getPluginTypes() { | ||
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; | ||
} | ||
console.log(matches); | ||
const [, 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