Skip to content

Commit

Permalink
move shell.js to root and implement project scripts/* - fix rollup.co…
Browse files Browse the repository at this point in the history
…nfig and package.json dist file location
  • Loading branch information
michael-gee committed Jan 14, 2024
1 parent 4ba8194 commit 57dd35f
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 33 deletions.
10 changes: 6 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
{
"name": "communitils",
"description": "Breaking into open-source with a TypeScript utility package while inviting others to do the same.",
"version": "0.4.1",
"version": "0.4.2",
"main": "dist/index.cjs",
"module": "dist/index.js",
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"workspaces": [
"src",
"site"
],
"scripts": {
"build": "npm run build -w src",
"clean": "rm -rf dist",
"clean": "node scripts/clean.js",
"clean:build": "npm run clean && npm run build -w src",
"reinstall": "rm -rf node_modules && npm run reinstall -w src -w site && npm ci",
"reinstall": "node scripts/reinstall.js && npm ci",
"test": "npm run test -w src",
"test:watch": "npm run test:watch -w src",
"*": "************************************",
"site:dev": "npm run start -w site",
"site:build": "npm run build -w site"
},
"devDependencies": {
"shelljs": "^0.8.5"
},
"files": [
"dist"
],
Expand Down
4 changes: 4 additions & 0 deletions scripts/clean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const shell = require('shelljs');
shell.rm('-rf', '../dist');
shell.rm('-rf', '../site/build');
shell.rm('-rf', '../site/.docusaurus');
4 changes: 4 additions & 0 deletions scripts/concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const shell = require('shelljs');
shell.rm('-f', '../src/main.d.ts');
shell.rm('-rf', '../dist');
shell.cat('../src/**/*.d.ts').to('../src/main.d.ts');
4 changes: 4 additions & 0 deletions scripts/reinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const shell = require('shelljs');
shell.rm('-rf', 'src/node_modules');
shell.rm('-rf', 'site/node_modules');
shell.rm('-rf', 'node_modules');
1 change: 0 additions & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"serve": "docusaurus serve",
"write-translations": "docusaurus write-translations",
"write-heading-ids": "docusaurus write-heading-ids",
"reinstall": "rm -rf node_modules",
"typecheck": "tsc"
},
"dependencies": {
Expand Down
3 changes: 0 additions & 3 deletions src/concat.cjs

This file was deleted.

13 changes: 3 additions & 10 deletions src/package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
{
"name": "@communitils/src",
"version": "*",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"browser": "dist/index.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "npm run dts && rollup -c",
"dev": "rollup -c -w",
"dts": "tsc && node concat.cjs",
"reinstall": "rm -rf node_modules",
"build": "npm run dts && rollup -c --bundleConfigAsCjs",
"dev": "rollup -c --bundleConfigAsCjs -w",
"dts": "tsc && node ../scripts/concat.js",
"test": "npm run dts && vitest run",
"test:watch": "vitest"
},
Expand All @@ -21,7 +15,6 @@
"rollup-plugin-dts": "^6.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-typescript": "^1.0.0",
"shelljs": "^0.8.5",
"ts-node": "^10.9.2",
"tslib": "^2.6.2",
"typescript": "^5.3.3",
Expand Down
18 changes: 6 additions & 12 deletions src/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import commonjs from 'rollup-plugin-commonjs';
import terser from '@rollup/plugin-terser';
import typescript from 'rollup-plugin-typescript';
import { dts } from 'rollup-plugin-dts';
import pkg from './package.json' assert { type: 'json' };
import pkg from '../package.json' assert { type: 'json' };

export default [
// browser-friendly UMD build
Expand All @@ -12,25 +12,19 @@ export default [
output: {
name: 'main',
file: `../${pkg.browser}`,
format: 'umd',
sourcemap: true
format: 'umd'
},
plugins: [
terser({ compress: true, format: { comments: false } }),
resolve(),
commonjs(),
typescript({ tsconfig: './tsconfig.json' })
]
plugins: [terser({ compress: true, format: { comments: false } }), resolve(), commonjs(), typescript()]
},

// CommonJS (for Node) and ES module (for bundlers) build.
{
input: 'main.ts',
external: [],
plugins: [terser({ compress: true, format: { comments: false } }), typescript({ tsconfig: './tsconfig.json' })],
plugins: [terser({ compress: true, format: { comments: false } }), typescript()],
output: [
{ file: `../${pkg.main}`, format: 'cjs', sourcemap: true },
{ file: `../${pkg.module}`, format: 'es', sourcemap: true }
{ file: `../${pkg.main}`, format: 'cjs' },
{ file: `../${pkg.module}`, format: 'es' }
]
},
{
Expand Down

0 comments on commit 57dd35f

Please sign in to comment.