Streamline package
This commit is contained in:
@@ -23,6 +23,15 @@ npm install git+https://git.maze.io/maze/cyberduck.git#main
|
||||
|
||||
Note: when installing from a git repository, npm will clone the source. For consumers to get built artifacts (the `dist` bundle and compiled types) the repository must either include the `dist` output or provide a `prepare`/build step that runs on install. If you prefer not to publish, using `npm pack` from the repo owner (tarball) ensures the built `dist` is included.
|
||||
|
||||
Git install prerequisites
|
||||
|
||||
When a consumer installs the package directly from the Git repository, npm (and yarn) will run the package `prepare` script to produce the built `dist` and type artifacts. That means the consumer environment must be able to run the build:
|
||||
|
||||
- Have Node.js and npm installed (recommended Node 16+).
|
||||
- Have a working `npm install` that can fetch devDependencies so the build tools (`typescript`, `sass`, `vite`) are available.
|
||||
|
||||
If you don't want consumers to run the build during install, either include the `dist` output in the repository (not recommended) or distribute a tarball produced by `npm pack` from the author so consumers can install the built package without running `prepare`.
|
||||
|
||||
## Including styles (optional)
|
||||
|
||||
Styles are optional — CyberDuck does not automatically inject styles when you import components. Import styles only if you want the theme and utilities applied.
|
||||
|
||||
22
package.json
22
package.json
@@ -34,30 +34,16 @@
|
||||
"./styles": "./src/styles/cyberduck.scss",
|
||||
"./styles/*": "./src/styles/*",
|
||||
"./css": "./dist/cyberduck.css",
|
||||
"./Navbar": {
|
||||
"./*": {
|
||||
"import": "./dist/cyberduck.es.js",
|
||||
"require": "./dist/cyberduck.cjs.js",
|
||||
"types": "./dist/Navbar.d.ts"
|
||||
},
|
||||
"./Footer": {
|
||||
"import": "./dist/cyberduck.es.js",
|
||||
"require": "./dist/cyberduck.cjs.js",
|
||||
"types": "./dist/Footer.d.ts"
|
||||
},
|
||||
"./Layout": {
|
||||
"import": "./dist/cyberduck.es.js",
|
||||
"require": "./dist/cyberduck.cjs.js",
|
||||
"types": "./dist/Layout.d.ts"
|
||||
},
|
||||
"./Split": {
|
||||
"import": "./dist/cyberduck.es.js",
|
||||
"require": "./dist/cyberduck.cjs.js",
|
||||
"types": "./dist/Split.d.ts"
|
||||
"types": "./dist/*.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -p tsconfig.build.json && npm run styles:build && vite build",
|
||||
"build": "node ./scripts/build-if-needed.cjs",
|
||||
"prepack": "npm run build",
|
||||
"prepare": "npm run build",
|
||||
"lint": "eslint .",
|
||||
"lint:css": "stylelint \"src/**/*.{scss,css,sass}\"",
|
||||
|
||||
70
scripts/build-if-needed.cjs
Normal file
70
scripts/build-if-needed.cjs
Normal file
@@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env node
|
||||
const { execSync } = require('child_process')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
const cwd = process.cwd()
|
||||
const tsconfig = path.join(cwd, 'tsconfig.build.json')
|
||||
|
||||
function runIfAvailable(cmdCheck, cmdRun, desc) {
|
||||
try {
|
||||
execSync(cmdCheck, { stdio: 'ignore' })
|
||||
console.log(`Running ${desc}...`)
|
||||
execSync(cmdRun, { stdio: 'inherit' })
|
||||
return true
|
||||
} catch (e) {
|
||||
console.log(`Skipping ${desc} (tool not available or command failed).`)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 1) TypeScript declarations
|
||||
if (fs.existsSync(tsconfig)) {
|
||||
// try to use local tsc if available
|
||||
runIfAvailable('npx --no-install tsc -v', 'npx --no-install tsc -p tsconfig.build.json', 'TypeScript declaration build')
|
||||
} else {
|
||||
console.log('No tsconfig.build.json found — skipping TypeScript declaration build')
|
||||
}
|
||||
|
||||
// 2) Sass build (styles)
|
||||
runIfAvailable(
|
||||
'npx --no-install sass --version',
|
||||
'npx --no-install sass --no-source-map --style=compressed --load-path=node_modules src:dist',
|
||||
'Sass styles build',
|
||||
)
|
||||
|
||||
// 3) Vite build
|
||||
runIfAvailable('npx --no-install vite --version', 'npx --no-install vite build', 'Vite build')
|
||||
|
||||
// 4) Generate per-subpath declaration wrappers in `dist/` by scanning emitted types
|
||||
try {
|
||||
const distTypesRoot = path.join(cwd, 'dist', 'types')
|
||||
if (fs.existsSync(distTypesRoot)) {
|
||||
const collected = []
|
||||
const walk = (dir) => {
|
||||
for (const name of fs.readdirSync(dir)) {
|
||||
const full = path.join(dir, name)
|
||||
const stat = fs.statSync(full)
|
||||
if (stat.isDirectory()) walk(full)
|
||||
else if (stat.isFile() && name.endsWith('.d.ts')) collected.push(full)
|
||||
}
|
||||
}
|
||||
walk(distTypesRoot)
|
||||
|
||||
// Create one wrapper per top-level d.ts basename (skip index.d.ts)
|
||||
collected.forEach(full => {
|
||||
const rel = path.relative(path.join(cwd, 'dist'), full).replace(/\\/g, '/')
|
||||
const base = path.basename(full, '.d.ts')
|
||||
if (base === 'index') return
|
||||
const wrapperPath = path.join(cwd, 'dist', `${base}.d.ts`)
|
||||
const target = `./${rel.replace(/\.d\.ts$/, '')}`
|
||||
const content = `export { default } from '${target}';\n`
|
||||
fs.writeFileSync(wrapperPath, content)
|
||||
})
|
||||
console.log('Generated per-subpath .d.ts wrappers into dist/')
|
||||
} else {
|
||||
console.log('No dist/types found — skipping generation of per-subpath wrappers')
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to generate per-subpath wrappers:', e && e.message)
|
||||
}
|
||||
Reference in New Issue
Block a user