-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Package the build_bundle.js script alongside ccfapp (#6704)
- Loading branch information
1 parent
f54c0f8
commit c85da08
Showing
7 changed files
with
90 additions
and
58 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/*.tgz | ||
/*.d.ts | ||
/*.js | ||
/html | ||
/html | ||
/scripts |
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,81 @@ | ||
#!/usr/bin/env node | ||
|
||
import { | ||
readdirSync, | ||
statSync, | ||
readFileSync, | ||
writeFileSync, | ||
existsSync, | ||
} from "fs"; | ||
import { join, resolve, sep } from "path"; | ||
|
||
function getAllFiles(dirPath: string): string[] { | ||
const toSearch = [dirPath]; | ||
const agg = []; | ||
|
||
for (const filePath of toSearch) { | ||
if (statSync(filePath).isDirectory()) { | ||
for (const subfile of readdirSync(filePath)) { | ||
toSearch.push(join(filePath, subfile)); | ||
} | ||
} else { | ||
agg.push(filePath); | ||
} | ||
} | ||
return agg; | ||
} | ||
|
||
function removePrefix(s: string, prefix: string): string { | ||
if (s.startsWith(prefix)) { | ||
return s.slice(prefix.length).split(sep).join(sep); | ||
} | ||
console.log("Warn: tried to remove invalid prefix", s, prefix); | ||
return s; | ||
} | ||
|
||
const args = process.argv.slice(2); | ||
|
||
if (args.length < 1) { | ||
console.log("Usage: build_bundle <root_directory>"); | ||
process.exit(1); | ||
} | ||
|
||
function assertFileExists(path: string) { | ||
if (!existsSync(path)) { | ||
console.log("File not found: %s", path); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
const argRootDirPath = args[0]; | ||
assertFileExists(argRootDirPath); | ||
const rootDirPath = resolve(argRootDirPath); | ||
const metadataPath = join(rootDirPath, "app.json"); | ||
assertFileExists(metadataPath); | ||
const srcDirPath = join(rootDirPath, "src"); | ||
assertFileExists(srcDirPath); | ||
|
||
const metadata = JSON.parse(readFileSync(metadataPath, "utf-8")); | ||
const allFiles = getAllFiles(srcDirPath); | ||
|
||
// The trailing / is included so that it is trimmed in removePrefix. | ||
// This produces "foo/bar.js" rather than "/foo/bar.js" | ||
const toTrim = srcDirPath + "/"; | ||
|
||
const modules = allFiles.map(function (filePath) { | ||
return { | ||
name: removePrefix(filePath, toTrim), | ||
module: readFileSync(filePath, "utf-8"), | ||
}; | ||
}); | ||
|
||
const bundlePath = join(args[0], "bundle.json"); | ||
const bundle = { | ||
metadata: metadata, | ||
modules: modules, | ||
}; | ||
|
||
console.log( | ||
`Writing bundle containing ${modules.length} modules to ${bundlePath}`, | ||
); | ||
writeFileSync(bundlePath, JSON.stringify(bundle)); |
This file was deleted.
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