iconoir/bin/prepublish.js

50 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

2022-07-05 16:24:49 +02:00
import { updateYamlKey } from '@atomist/yaml-updater';
import fs from 'node:fs';
import path from 'node:path';
2022-07-05 16:24:49 +02:00
import semver from 'semver';
const PACKAGE_BASE = '';
2022-07-05 16:24:49 +02:00
const newVersion = semver.valid(semver.coerce(process.env.TAG_NAME));
console.info('New version is %s', newVersion);
2023-10-29 00:33:17 +02:00
2022-07-05 16:24:49 +02:00
if (!newVersion) {
throw new Error(`Tag name ${process.env.TAG_NAME} is not valid.`);
}
2023-10-29 00:33:17 +02:00
publishNpmPackage('iconoir');
publishNpmPackage('iconoir-react');
publishNpmPackage('iconoir-react-native');
publishNpmPackage('iconoir-vue');
publishPubPackage('iconoir-flutter');
2022-07-05 16:24:49 +02:00
function publishNpmPackage(name) {
console.info('Publishing %s', name);
const packageJsonPath =
name === 'iconoir'
? 'package.json'
: path.join('packages', name, 'package.json');
const contents = JSON.parse(fs.readFileSync(packageJsonPath).toString());
contents.version = newVersion;
2023-10-29 00:33:17 +02:00
if (PACKAGE_BASE) {
contents.name = `${PACKAGE_BASE}/${name}`;
}
2023-10-29 00:33:17 +02:00
fs.writeFileSync(packageJsonPath, JSON.stringify(contents, undefined, 2));
console.info('package.json updated');
}
2022-07-05 16:24:49 +02:00
function publishPubPackage(name) {
const pubspecFilepath = path.join('packages', name, 'pubspec.yaml');
const pubspecContents = fs.readFileSync(pubspecFilepath).toString();
fs.writeFileSync(
pubspecFilepath,
updateYamlKey('version', newVersion, pubspecContents),
2022-07-05 16:24:49 +02:00
);
console.info('pubspec.yaml updated');
}