-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use dts-bundle-generator to generate bundled ts files
- Loading branch information
Showing
4 changed files
with
87 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
const path = require('path') | ||
const fs = require('fs') | ||
|
||
const NGX_META_DIR = path.join('.', 'projects', 'ngx-meta') | ||
const NGX_META_SRC_DIR = path.join(NGX_META_DIR, 'src') | ||
|
||
const entrypoints = [] | ||
const getDirectories = (source) => | ||
fs | ||
.readdirSync(source, { withFileTypes: true }) | ||
.filter((dirent) => dirent.isDirectory()) | ||
.map((dirent) => dirent.name) | ||
const getFiles = (source) => fs.readdirSync(source) | ||
|
||
console.info('ℹ️ Looking for entry points') | ||
const NG_PACKAGE_JSON_FILENAME = 'ng-package.json' | ||
const ngxMetaSrcSubdirectories = getDirectories(NGX_META_SRC_DIR) | ||
const ngxMetaEntrypoints = ngxMetaSrcSubdirectories.filter((subDirectory) => { | ||
const ngxMetaSrcSubdirectory = path.join(NGX_META_SRC_DIR, subDirectory) | ||
const files = getFiles(ngxMetaSrcSubdirectory) | ||
return files.includes(NG_PACKAGE_JSON_FILENAME) | ||
}) | ||
ngxMetaEntrypoints.forEach((entrypoint) => { | ||
console.info('- ', entrypoint) | ||
}) | ||
|
||
const entries = ngxMetaEntrypoints.map((entrypoint) => ({ | ||
filePath: path.join(NGX_META_DIR, 'out', entrypoint, 'index.d.ts'), | ||
outFile: path.join(NGX_META_DIR, 'dist', entrypoint, 'bundled.d.ts'), | ||
output: { | ||
exportReferencedTypes: false, | ||
}, | ||
})) | ||
|
||
const config = { | ||
compilationOptions: { | ||
preferredConfigPath: path.join(NGX_META_SRC_DIR, 'tsconfig.lib.prod.json'), | ||
}, | ||
entries, | ||
} | ||
|
||
module.exports = config |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env sh | ||
# Commands to run after building | ||
set -eu | ||
|
||
# ngx-meta Typescript definitions rollup | ||
echo "ℹ️ Bundling Typescript definitions" | ||
dts-bundle-generator --config dts-config.js | ||
|
||
# Replace `index.d.ts` with bundled definitions | ||
echo "ℹ️ Replacing Typescript index files with bundled definitions" | ||
NGX_META_DIST_DIR="projects/ngx-meta/dist" | ||
for dist_file_entry in "$NGX_META_DIST_DIR"/*; do | ||
BUNDLED_DEFINITIONS_FILENAME="bundled.d.ts" | ||
INDEX_DEFINITIONS_FILENAME="index.d.ts" | ||
bundled_definitions_file="$dist_file_entry/$BUNDLED_DEFINITIONS_FILENAME" | ||
index_definitions_file="$dist_file_entry/$INDEX_DEFINITIONS_FILENAME" | ||
if [ -f "$bundled_definitions_file" ]; then | ||
echo "- $bundled_definitions_file -> $index_definitions_file" | ||
mv "$bundled_definitions_file" "$index_definitions_file" | ||
fi | ||
done | ||
|
||
# Remove Typescript source directories | ||
echo "ℹ️ Removing Typescript source directories" | ||
for dist_file_entry in "$NGX_META_DIST_DIR"/*; do | ||
entrypoint_src_dir="$dist_file_entry/src" | ||
if [ -d "$entrypoint_src_dir" ]; then | ||
echo "- $entrypoint_src_dir" | ||
rm -rf "$entrypoint_src_dir" | ||
fi | ||
done |