-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
209 additions
and
7 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* @license Copyright 2024 w3ux authors & contributors | ||
SPDX-License-Identifier: GPL-3.0-only */ | ||
|
||
import { PACKAGE_OUTPUT } from "config"; | ||
import { prebuild } from "builders/common/prebuild"; | ||
import { | ||
gePackageDirectory, | ||
generatePackageJson, | ||
removePackageOutput, | ||
} from "builders/util"; | ||
import { promisify } from "util"; | ||
import { exec } from "child_process"; | ||
|
||
const execPromisify = promisify(exec); | ||
|
||
export const build = async () => { | ||
const folder = "factories"; | ||
const libDirectory = gePackageDirectory(folder); | ||
|
||
try { | ||
// Prebuild integrity checks. | ||
if (!(await prebuild(folder))) { | ||
throw `Prebuild failed.`; | ||
} | ||
|
||
// Call gump command to build dist folder. | ||
try { | ||
await execPromisify(`cd ../library/${folder} && yarn build`); | ||
} catch (e) { | ||
throw `Failed to generate dist. ${e}`; | ||
} | ||
|
||
// Generate package.json. | ||
if ( | ||
!(await generatePackageJson( | ||
libDirectory, | ||
`${libDirectory}/${PACKAGE_OUTPUT}`, | ||
"gulp" | ||
)) | ||
) { | ||
throw `Failed to generate package.json file.`; | ||
} | ||
|
||
console.log(`✅ Package successfully built.`); | ||
} catch (err) { | ||
// Handle on error. | ||
console.error(`❌ Error occurred while building the package.`, err); | ||
|
||
// Remove package output directory if it exists. | ||
if (!(await removePackageOutput(libDirectory, false))) { | ||
console.error(`❌ Failed to remove package output directory.`); | ||
} | ||
} | ||
}; |
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,43 @@ | ||
/* @license Copyright 2024 w3ux authors & contributors | ||
SPDX-License-Identifier: GPL-3.0-only */ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
|
||
import gulp from "gulp"; | ||
import ts from "gulp-typescript"; | ||
import sourcemaps from "gulp-sourcemaps"; | ||
import merge from "merge-stream"; | ||
|
||
const { dest, series } = gulp; | ||
|
||
// Buld CommonJS module. | ||
const buildCommonJs = () => | ||
doBuild( | ||
ts.createProject("tsconfig.json", { | ||
module: "commonjs", | ||
target: "es2015", | ||
removeComments: true, | ||
}), | ||
"cjs" | ||
); | ||
|
||
// Build ES module. | ||
const buildEsm = () => | ||
doBuild( | ||
ts.createProject("tsconfig.json", { | ||
module: "esnext", | ||
target: "esnext", | ||
removeComments: true, | ||
}), | ||
"mjs" | ||
); | ||
|
||
// Build package with provided Typescript project. | ||
const doBuild = (tsProject, outDir) => { | ||
var tsResult = tsProject.src().pipe(sourcemaps.init()).pipe(tsProject()); | ||
|
||
return merge(tsResult, tsResult.js) | ||
.pipe(sourcemaps.write(".")) | ||
.pipe(dest(`dist/${outDir}`)); | ||
}; | ||
|
||
export default series(buildCommonJs, buildEsm); |
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,23 @@ | ||
{ | ||
"name": "@w3ux/factories-source", | ||
"license": "GPL-3.0-only", | ||
"version": "1.0.0-beta.0", | ||
"type": "module", | ||
"scripts": { | ||
"clear": "rm -rf node_modules dist tsconfig.tsbuildinfo", | ||
"build": "gulp --silent" | ||
}, | ||
"peerDependencies": { | ||
"react": "^18" | ||
}, | ||
"devDependencies": { | ||
"@types/react": "^18", | ||
"@w3ux/types": "^0.2.0", | ||
"gulp": "^5.0.0", | ||
"gulp-sourcemaps": "^3.0.0", | ||
"gulp-strip-comments": "^2.6.0", | ||
"gulp-typescript": "^6.0.0-alpha.1", | ||
"react": "^18", | ||
"typescript": "^5.4.5" | ||
} | ||
} |
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,8 @@ | ||
directory: | ||
- name: Factories | ||
description: A collection of general purpose TypeScript factories. | ||
|
||
npm: | ||
title: Hooks | ||
contents: | ||
- item: A collection of general purpose TypeScript factories. |
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,4 @@ | ||
/* @license Copyright 2024 w3ux authors & contributors | ||
SPDX-License-Identifier: GPL-3.0-only */ | ||
|
||
export * from "./withProviders"; |
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,22 @@ | ||
/* @license Copyright 2024 w3ux authors & contributors | ||
SPDX-License-Identifier: GPL-3.0-only */ | ||
|
||
import type { FC } from "react"; | ||
|
||
// `providers` accepts standalone functional components or an array of a functional component and its props. | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Provider = FC<any> | [FC<any>, any]; | ||
|
||
// A pure function that applies an arbitrary amount of context providers to a wrapped component. | ||
export const withProviders = (providers: Provider[], Wrapped: FC) => | ||
providers.reduceRight( | ||
(acc, prov) => { | ||
if (Array.isArray(prov)) { | ||
const Provider = prov[0]; | ||
return <Provider {...prov[1]}>{acc}</Provider>; | ||
} | ||
const Provider = prov; | ||
return <Provider>{acc}</Provider>; | ||
}, | ||
<Wrapped /> | ||
); |
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,18 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": "./src", | ||
"rootDir": "./src", | ||
"outDir": "./dist", | ||
"module": "ESNext", | ||
"moduleResolution": "Node", | ||
"target": "es5", | ||
"lib": ["DOM", "DOM.Iterable", "ESNext"], | ||
"sourceMap": false, | ||
"jsx": "react-jsx", | ||
"allowSyntheticDefaultImports": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
}, | ||
"include": ["src/**/*"], | ||
} |
File renamed without changes.
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
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