Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make npm run build also trigger npm run build:types #5768

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { execSync } from 'node:child_process';
import { exec, execSync } from 'node:child_process';
import * as fs from 'node:fs';

// 1st party Rollup plugins
Expand All @@ -19,6 +19,7 @@ import { spacesToTabs } from './utils/rollup-spaces-to-tabs.mjs';

/** @typedef {import('rollup').RollupOptions} RollupOptions */
/** @typedef {import('rollup').OutputOptions} OutputOptions */
/** @typedef {import('rollup').ModuleFormat} ModuleFormat */
/** @typedef {import('@rollup/plugin-babel').RollupBabelInputPluginOptions} RollupBabelInputPluginOptions */
/** @typedef {import('@rollup/plugin-strip').RollupStripOptions} RollupStripOptions */

Expand Down Expand Up @@ -198,7 +199,7 @@ function buildTarget(buildType, moduleFormat) {
es6: '.mjs'
};

/** @type {Record<string, 'umd'|'es'>} */
/** @type {Record<string, ModuleFormat>} */
const outputFormat = {
es5: 'umd',
es6: 'es'
Expand Down Expand Up @@ -349,9 +350,19 @@ const target_types = {
]
};

function buildTypes() {
const start = Date.now();
const child = exec('npm run build:types');
child.on('exit', function () {
const end = Date.now();
const delta = (end - start) / 1000;
console.log(`created build/playcanvas.d.ts in ${delta}s`);
});
}

export default (args) => {
/** @type {RollupOptions[]} */
let targets = [];
const targets = [];

const envTarget = process.env.target ? process.env.target.toLowerCase() : null;

Expand All @@ -363,7 +374,7 @@ export default (args) => {
if (envTarget === 'types') {
targets.push(target_types);
} else if (envTarget === 'extras') {
targets = targets.concat(target_extras);
targets.push(...target_extras);
} else {
['release', 'debug', 'profiler', 'min'].forEach((t) => {
['es5', 'es6'].forEach((m) => {
Expand All @@ -375,7 +386,8 @@ export default (args) => {

if (envTarget === null) {
// no targets specified, build them all
targets = targets.concat(target_extras);
buildTypes();
targets.push(...target_extras);
}
}

Expand Down