Skip to content

Commit

Permalink
update build
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 5, 2021
1 parent a31d7fb commit 70cd265
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 60 deletions.
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
.cache/
.DS_Store
node_modules/
/dist/
/integration/
/lib/
/react/
/tests/~partytown/
/tests/videos/
/tsc/
/tsc/
/index.js
23 changes: 21 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,35 @@
{
"name": "@builder.io/partytown",
"version": "0.0.7",
"version": "0.0.8",
"description": "Relocate resource intensive 3rd-party scripts off of the main thread and into a web worker.",
"license": "MIT",
"main": "index.js",
"exports": {
"./integration": {
"import": "./integration/index.mjs",
"require": "./integration/index.cjs"
},
"./react": {
"import": "./react/index.mjs",
"require": "./react/index.cjs"
},
".": {
"require": "./index.js"
}
},
"files": [
"integration/",
"lib/",
"react/"
],
"scripts": {
"build": "tsc && rollup -c scripts/rollup.config.js",
"build.prod": "tsc && rollup -c scripts/rollup.config.js --configApi",
"build.watch": "rollup -c scripts/rollup.config.js -w --configDev",
"dev": "tsc && concurrently \"npm:build.watch\" \"npm:tsc.watch\" -n build,tsc -c magenta,yellow",
"playwright": "playwright test --browser=chromium",
"playwright.webkit": "playwright test --browser=webkit",
"release": "npm run build && npm test && cd dist && np --no-2fa --no-tests ",
"release": "npm run build && npm test && np --no-2fa --no-tests",
"serve": "sirv tests --port 4000 --dev",
"serve.test": "sirv tests --port 5000 --dev --quiet",
"test": "start-server-and-test serve.test http://localhost:5000/ playwright",
Expand Down
61 changes: 14 additions & 47 deletions scripts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { buildMainSnippet } from './build-main-snippet';
import { buildIntegration } from './build-integration';
import { buildReact } from './build-react';
import { buildServiceWorker } from './build-service-worker';
import { emptyDir, ensureDir, readJsonSync, writeFile, writeJson } from 'fs-extra';
import { emptyDir, ensureDir, readJsonSync, writeFile } from 'fs-extra';
import { join } from 'path';

export async function runBuild(rootDir: string, isDev: boolean, generateApi: boolean) {
Expand All @@ -30,65 +30,33 @@ export async function runBuild(rootDir: string, isDev: boolean, generateApi: boo

async function createRootPackage(opts: BuildOptions) {
if (opts.isDev) {
await ensureDir(opts.distDir);
await ensureDir(opts.distTestsDir);
await ensureDir(opts.distIntegrationDir);
await ensureDir(opts.distLibDir);
await ensureDir(opts.distLibDebugDir);
await ensureDir(opts.distReactDir);
} else {
await emptyDir(opts.distDir);
await emptyDir(opts.distTestsDir);
await emptyDir(opts.distIntegrationDir);
await emptyDir(opts.distLibDir);
await emptyDir(opts.distLibDebugDir);
await emptyDir(opts.distReactDir);
}

await ensureDir(opts.distIntegrationDir);
await ensureDir(opts.distLibDir);
await ensureDir(opts.distLibDebugDir);
await ensureDir(opts.distReactDir);

const indexJsCode = `// @builder.io/partytown`;
const indexJsPath = join(opts.distDir, 'index.js');
await writeFile(indexJsPath, indexJsCode);

const rootPkg = opts.packageJson;
const packageJson = {
name: rootPkg.name,
version: rootPkg.version,
description: rootPkg.description,
license: rootPkg.license,
author: rootPkg.author,
main: './index.js',
exports: {
'./integration': {
import: './integration/index.mjs',
require: './integration/index.cjs',
},
'./react': {
import: './react/index.mjs',
require: './react/index.cjs',
},
'.': {
require: './index.js',
},
},
files: ['./integration/', './lib/', './react/', './index.js'],
homepage: rootPkg.homepage,
keywords: rootPkg.keywords,
repository: rootPkg.repository,
publishConfig: rootPkg.publishConfig,
};

if (opts.isDev) {
const version = `dev.0.${Date.now()}`;
rootPkg.version = packageJson.version = version;
}

const packageJsonPath = join(opts.distDir, 'package.json');
await writeJson(packageJsonPath, packageJson, { spaces: 2 });
const indexJsPath = join(opts.rootDir, 'index.js');
await writeFile(indexJsPath, `// @builder.io/partytown\n`);
}

function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolean) {
const distDir = join(rootDir, 'dist');
const distIntegrationDir = join(distDir, 'integration');
const distLibDir = join(distDir, 'lib');
const distIntegrationDir = join(rootDir, 'integration');
const distLibDir = join(rootDir, 'lib');
const distLibDebugDir = join(distLibDir, 'debug');
const distReactDir = join(distDir, 'react');
const distReactDir = join(rootDir, 'react');

const srcDir = join(rootDir, 'src');
const srcIntegrationDir = join(srcDir, 'integration');
Expand All @@ -112,7 +80,6 @@ function createBuildOptions(rootDir: string, isDev: boolean, generateApi: boolea
isDev,
generateApi,
rootDir,
distDir,
distIntegrationDir,
distLibDir,
distLibDebugDir,
Expand Down
1 change: 0 additions & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export interface BuildOptions {
isDev: boolean;
generateApi: boolean;
rootDir: string;
distDir: string;
distIntegrationDir: string;
distLibDir: string;
distLibDebugDir: string;
Expand Down
2 changes: 1 addition & 1 deletion src/integration/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/integration/index.d.ts"
"untrimmedFilePath": "<projectFolder>/integration/index.d.ts"
},
"docModel": {
"enabled": false
Expand Down
6 changes: 3 additions & 3 deletions src/integration/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/partytown-integration",
"main": "./index.cjs",
"module": "./index.mjs",
"types": "./index.d.ts"
"main": "index.cjs",
"module": "index.mjs",
"types": "index.d.ts"
}
2 changes: 1 addition & 1 deletion src/react/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "<projectFolder>/dist/react/index.d.ts"
"untrimmedFilePath": "<projectFolder>/react/index.d.ts"
},
"docModel": {
"enabled": false
Expand Down
6 changes: 3 additions & 3 deletions src/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@builder.io/partytown-react",
"main": "./index.cjs",
"module": "./index.mjs",
"types": "./index.d.ts"
"main": "index.cjs",
"module": "index.mjs",
"types": "index.d.ts"
}

1 comment on commit 70cd265

@vercel
Copy link

@vercel vercel bot commented on 70cd265 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.