Skip to content

Commit

Permalink
export Components, Parameters, Properties and ValueTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
filecage committed Jul 31, 2023
1 parent cffa771 commit a4fe429
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
node-version: latest
registry-url: 'https://registry.npmjs.org'
- run: npm i
- run: npm run prepare:build
- run: npm run build
- name: Prepare Release
run: npm run prepare:release ${{ github.ref_name }}
Expand Down
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@ node_modules
.idea
coverage/
dist/
.DS_Store
.DS_Store

# These files are created for builds and releases, we don't want to track them in GitHub
src/Components.ts
src/Parameters.ts
src/Properties.ts
src/ValueTypes.ts
39 changes: 39 additions & 0 deletions bin/prepare-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// This file compiles export files for all calendar components, properties, parameters and value types
import fs from 'fs/promises';
import {dirname, basename, resolve, parse, format} from 'path';
import {fileURLToPath} from 'url';

await exportBundle('Parser/Components', 'src/Components.ts');
await exportBundle('Parser/Properties', 'src/Properties.ts');
await exportBundle('Parser/Parameters', 'src/Parameters.ts');
await exportBundle('Parser/ValueTypes', 'src/ValueTypes.ts');

console.log('All OK');

async function exportBundle (dirFromAppSrc) {
dirFromAppSrc = dirFromAppSrc.trimEnd('/');
const files = (await fs.readdir(buildAppPath(`src/${dirFromAppSrc}`)))
.filter(file => !file.startsWith('.')) // no hidden files
.map(async file => {
let exports;
const path = parse(file);

// Check if keyword `export default` exists in file to see whether we have to map the default
if ((await fs.readFile(buildAppPath(`src/${dirFromAppSrc}/${file}`), 'utf8')).includes('export default')) {
exports = `default as ${path.name}`;
} else {
exports = path.name;
}

return `export { ${exports} } from '${format({...path, ext: undefined, base: undefined, dir: `./${dirFromAppSrc}`})}';`;
});

const target = buildAppPath(`src/${basename(dirFromAppSrc)}.ts`)
await fs.writeFile(target, (await Promise.all(files)).join("\n"), 'utf8');

console.log(`OK: ${target}`);
}

function buildAppPath (path) {
return resolve(dirname(fileURLToPath(import.meta.url)), '../' + path);
}
15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,25 @@
"types": "./dist/index.d.ts",
"exports": {
".": "./dist/index.js",
"./parser": "./dist/parser.js"
"./parser": "./dist/parser.js",
"./Components": "./dist/Components.js",
"./Parameters": "./dist/Parameters.js",
"./Properties": "./dist/Properties.js",
"./ValueTypes": "./dist/ValueTypes.js"
},
"typesVersions": {
"*": {
"parser": [
"dist/parser.d.ts"
]
"parser": ["dist/parser.d.ts"],
"Components": ["dist/Components.d.ts"],
"Parameters": ["dist/Parameters.d.ts"],
"Properties": ["dist/Properties.d.ts"],
"ValueTypes": ["dist/ValueTypes.d.ts"]
}
},
"scripts": {
"build": "tsup",
"lint": "eslint src/**",
"prepare:build": "node bin/prepare-build.js",
"prepare:release": "node bin/prepare-release.js",
"compile:parameters": "node --loader=./loader.js compiler/parameters.ts",
"compile:properties": "node --loader=./loader.js compiler/properties.ts",
Expand Down
9 changes: 8 additions & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ import { defineConfig } from 'tsup';
import { resolve, join } from 'path';

export default defineConfig({
entry: ['src/index.ts', 'src/parser.ts'],
entry: [
'src/index.ts',
'src/parser.ts',
'src/Components.ts',
'src/Parameters.ts',
'src/Properties.ts',
'src/ValueTypes.ts',
],
splitting: true,
sourcemap: false,
clean: true,
Expand Down

0 comments on commit a4fe429

Please sign in to comment.