Skip to content

Commit

Permalink
Use verdaccio registry
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Jul 24, 2023
1 parent 80552da commit e774bc0
Showing 1 changed file with 28 additions and 4 deletions.
32 changes: 28 additions & 4 deletions scripts/run-registry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { exec } from 'child_process';
import { remove, pathExists, readJSON } from 'fs-extra';
import { remove, pathExists, readJSON, readFileSync, writeFileSync } from 'fs-extra';
import chalk from 'chalk';
import path from 'path';
import program from 'commander';
Expand Down Expand Up @@ -70,7 +70,7 @@ const publish = (packages: { name: string; location: string }[], url: string) =>
'.'
)})`
);
const command = `cd ${location} && yarn npm publish --registry ${url} --force --access restricted --ignore-scripts`;
const command = `cd ${location} && yarn npm publish --access restricted`;
exec(command, (e) => {
if (e) {
rej(e);
Expand Down Expand Up @@ -99,9 +99,28 @@ const addUser = (url: string) =>
});
});

const run = async () => {
const verdaccioUrl = `http://localhost:6001`;
const yarnrcPath = path.join(__dirname, '..', 'code', '.yarnrc.yml');
const verdaccioUrl = `http://localhost:6001`;

const addLocalRegistry = () => {
logger.log(`📦 adding local registry to yarn config`);

const data = readFileSync(yarnrcPath, 'utf8');
const newData = `${data}\nnpmPublishRegistry: ${verdaccioUrl}`;

writeFileSync(yarnrcPath, newData);
};

const removeLocalRegistry = () => {
logger.log(`📦 removing local registry from yarn config`);

const data = readFileSync(yarnrcPath, 'utf8');
const newData = data.replace(`\nnpmPublishRegistry: ${verdaccioUrl}`, '');

writeFileSync(yarnrcPath, newData);
};

const run = async () => {
logger.log(`📐 reading version of storybook`);
logger.log(`🚛 listing storybook packages`);

Expand Down Expand Up @@ -133,16 +152,21 @@ const run = async () => {

logger.log(`📦 found ${packages.length} storybook packages at version ${chalk.blue(version)}`);

addLocalRegistry();

if (program.publish) {
await publish(packages, verdaccioUrl);
}

removeLocalRegistry();

if (!program.open) {
verdaccioServer.close();
}
};

run().catch((e) => {
logger.error(e);
removeLocalRegistry();
process.exit(1);
});

0 comments on commit e774bc0

Please sign in to comment.