forked from hotwired/stimulus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dist-to-packages.js
43 lines (36 loc) · 1.4 KB
/
dist-to-packages.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fs = require("fs-extra")
const path = require("path")
const rootPath = path.resolve(__dirname, "..")
const tsconfigPath = path.join(rootPath, "tsconfig.json")
const tsconfig = require(tsconfigPath)
const { outDir, declarationDir, rootDir } = tsconfig.compilerOptions
const sourceModulesPath = path.join(rootPath, outDir)
const sourceTypesPath = path.join(rootPath, declarationDir)
const packagesPath = path.join(rootPath, rootDir)
// Copy compiled .js files to packages/*/**/dist/module
getPackageNames(sourceModulesPath).forEach(packageName => {
const srcPath = path.join(sourceModulesPath, packageName)
const destPath = path.join(packagesPath, packageName, "dist", "module")
fs.ensureDirSync(destPath)
fs.copySync(srcPath, destPath)
})
// Copy .d.ts files to packages/*/**/dist/types
getPackageNames(sourceModulesPath).forEach(packageName => {
const srcPath = path.join(sourceTypesPath, packageName)
const destPath = path.join(packagesPath, packageName, "dist", "types")
fs.ensureDirSync(destPath)
fs.copySync(srcPath, destPath)
})
function getPackageNames(rootPath) {
const names = []
fs.readdirSync(rootPath).forEach(name => {
if (name.startsWith("@")) {
const scopePath = path.join(rootPath, name)
const scopeNames = fs.readdirSync(scopePath).map(scopedName => `${name}/${scopedName}`)
names.push(...scopeNames)
} else {
names.push(name)
}
})
return names
}