Skip to content

Commit

Permalink
Swicth file names
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano-perez-rodriguez committed Jun 27, 2024
1 parent 66594be commit a2b8ae4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 56 deletions.
56 changes: 51 additions & 5 deletions etc/pack
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,61 @@ get_command_or_fail() {
builtin echo "${RESULT:?\'"${1}"\' command not found}"
}

THE_MKTEMP="$(get_command_or_fail mktemp)"
THE_NPM="$(get_command_or_fail npm)"
THE_TAR="$(get_command_or_fail tar)"
THE_NODE="$(get_command_or_fail node)"
THE_GZIP="$(get_command_or_fail gzip)"

# ---------------------------------------------------------------------------------------------------------------------

"${THE_NPM}" run prepublishOnly --ignore-scripts --if-present
TMP_DIR="$("${THE_MKTEMP}" -d 2> /dev/null || "${THE_MKTEMP}" -d -t 'tmp')"

THE_TGZ="$("${THE_NPM}" run pack:clean)"
if [[ ! "${TMP_DIR}" || ! -d "${TMP_DIR}" ]]; then
builtin echo "Could not create temporary directory"
builtin exit 1
fi

"${THE_NPM}" publish --ignore-scripts "${THE_TGZ}"
builtin trap 'rm -rf "${TMP_DIR}"' EXIT

"${THE_NPM}" run publish --ignore-scripts --if-present
"${THE_NPM}" run postpublish --ignore-scripts --if-present
# ---------------------------------------------------------------------------------------------------------------------

THE_DIR="$(builtin pwd)"

THE_TGZ="$("${THE_NPM}" pack --pack-destination "${TMP_DIR}" --json | "${THE_NODE}" -e "process.stdout.write(JSON.parse(require('fs').readFileSync(0))[0].filename);")"

builtin pushd "${TMP_DIR}" > /dev/null || exit 1

"${THE_TAR}" xzf "${THE_TGZ}"

"${THE_NODE}" -e "
const fs = require('fs');
const package = JSON.parse(fs.readFileSync('package/package.json'));
delete package.devDependencies;
delete package.files;
if ('scripts' in package) {
package.scripts = [
'preinstall',
'install',
'postinstall',
'prepublish',
'preprepare',
'prepare',
'postprepare',
].reduce(
(obj, key) => key in package.scripts ? ({ ...obj, [key]: package.scripts[key] }) : obj,
{},
);
}
fs.writeFileSync('package/package.json', JSON.stringify(package, null, 2) + '\n');
"

"${THE_TAR}" c package | "${THE_GZIP}" -9 > "${THE_DIR}/${THE_TGZ}"

builtin popd > /dev/null || exit 1

builtin echo "${THE_TGZ}"
56 changes: 5 additions & 51 deletions etc/publish
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,15 @@ get_command_or_fail() {
builtin echo "${RESULT:?\'"${1}"\' command not found}"
}

THE_MKTEMP="$(get_command_or_fail mktemp)"
THE_NPM="$(get_command_or_fail npm)"
THE_TAR="$(get_command_or_fail tar)"
THE_NODE="$(get_command_or_fail node)"
THE_GZIP="$(get_command_or_fail gzip)"

# ---------------------------------------------------------------------------------------------------------------------

TMP_DIR="$("${THE_MKTEMP}" -d 2> /dev/null || "${THE_MKTEMP}" -d -t 'tmp')"
"${THE_NPM}" run prepublishOnly --ignore-scripts --if-present

if [[ ! "${TMP_DIR}" || ! -d "${TMP_DIR}" ]]; then
builtin echo "Could not create temporary directory"
builtin exit 1
fi
THE_TGZ="$("${THE_NPM}" run pack:clean)"

builtin trap 'rm -rf "${TMP_DIR}"' EXIT
"${THE_NPM}" publish --ignore-scripts "${THE_TGZ}"

# ---------------------------------------------------------------------------------------------------------------------

THE_DIR="$(builtin pwd)"

THE_TGZ="$("${THE_NPM}" pack --pack-destination "${TMP_DIR}" --json | "${THE_NODE}" -e "process.stdout.write(JSON.parse(require('fs').readFileSync(0))[0].filename);")"

builtin pushd "${TMP_DIR}" > /dev/null || exit 1

"${THE_TAR}" xzf "${THE_TGZ}"

"${THE_NODE}" -e "
const fs = require('fs');
const package = JSON.parse(fs.readFileSync('package/package.json'));
delete package.devDependencies;
delete package.files;
if ('scripts' in package) {
package.scripts = [
'preinstall',
'install',
'postinstall',
'prepublish',
'preprepare',
'prepare',
'postprepare',
].reduce(
(obj, key) => key in package.scripts ? ({ ...obj, [key]: package.scripts[key] }) : obj,
{},
);
}
fs.writeFileSync('package/package.json', JSON.stringify(package, null, 2) + '\n');
"

"${THE_TAR}" c package | "${THE_GZIP}" -9 > "${THE_DIR}/${THE_TGZ}"

builtin popd > /dev/null || exit 1

builtin echo "${THE_TGZ}"
"${THE_NPM}" run publish --ignore-scripts --if-present
"${THE_NPM}" run postpublish --ignore-scripts --if-present

0 comments on commit a2b8ae4

Please sign in to comment.