File: mjs2cjs

package info (click to toggle)
pkg-js-tools 0.16.0
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,992 kB
  • sloc: perl: 4,975; sh: 840; makefile: 36; javascript: 22
file content (73 lines) | stat: -rwxr-xr-x 1,524 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/bash

set -e

function usage()
{
cat <<EOF
Usage: mjs2cjs <start_file>

mjs2cjs uses a generic rollup.config.mjs to generate a commonjs file in
dist subdirectory.

Output name is extracted from package.json (field "main") or fallback to
index.cjs

Options:
 -b ("bundle"): build a bundle file
 -o ("out"): outfile
 -a ("auto"): automatically transform "type:module" package into mix cjs/mjs

Note for "-a" option:
This option not only build commonjs file but also modify package.json. And if
a debian/index.cjs exists, it is installed and used in
"package.json->exports->require" field. This permits one to write a wrapper
when API change.
Option "-a" is usable if and only if module is a pure ES module (declared as
type:module in package.json).

Copyright (C) Yadd <yadd@debian.org>

Licensed under GPL-2+ (see /usr/share/common-licenses/GPL-2)
EOF
}

ROLLUPCONFIG=/usr/share/pkg-js-tools/mjs2cjs.mjs
DEST_FILE=''
AUTO=''

if test "$1" = "--version"; then
	echo `perl -MDebian::PkgJs::Version -e 'print $VERSION'`
	exit
fi
while getopts 'ahbo:' opt; do
	case $opt in
		h)
			usage
			exit
			;;
		b)
			ROLLUPCONFIG=/usr/share/pkg-js-tools/mjs2cjs-bundle.mjs
			;;
		o)
			DEST_FILE=$OPTARG
			;;
		a)
			AUTO=yes
			;;
		*)
			echo "Unknown option $opt" >&2
			exit 1
			;;
	esac
done
shift $((OPTIND-1))
export START_FILE=$1
if [ "$AUTO" == "yes" ]; then
	ENTRY_POINT=${ENTRY_POINT:-${START_FILE}}
	export ENTRY_POINT
	perl -MDebian::PkgJs::AutoTransform -e run
else
	export DEST_FILE
	rollup -c $ROLLUPCONFIG
fi