Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Apr 8, 2022
1 parent 78eda85 commit 234e289
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
8 changes: 4 additions & 4 deletions packages/docusaurus/bin/docusaurus.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,14 @@ cli
});

cli
.command('upgrade')
.description('Upgrades @docusaurus packages')
.command('upgrade [siteDir]')
.description('Upgrade @docusaurus packages.')
.option(
'-t, --tag <tag>',
'Tag of npm to look for upgrading. This option accepts any of: <alpha, beta, next, latest>',
)
.action(({tag = undefined}) => {
wrapCommand(upgrade)({tag});
.action(async (siteDir, {tag = undefined}) => {
upgrade(await resolveDir(siteDir), {tag});
});

cli
Expand Down
27 changes: 16 additions & 11 deletions packages/docusaurus/src/commands/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,37 +18,42 @@ async function hasYarn() {

type CommonNpmTags = 'alpha' | 'beta' | 'latest' | 'next';

export async function upgrade(opts: {tag: CommonNpmTags}): Promise<void> {
const [npmClient, npmCommand] = await hasYarn()
export async function upgrade(
siteDir: string,
{tag}: {tag: CommonNpmTags},
): Promise<void> {
const [npmClient, npmCommand] = (await hasYarn())
? ['yarn', 'upgrade']
: ['npm', 'install'];

const {dependencies = {}, devDependencies = {}} = await fs.readJSON(path.join(process.cwd(), './package.json'), 'utf8');
const {dependencies = {}, devDependencies = {}} = await fs.readJSON(
path.join(siteDir, 'package.json'),
);

let packageNames = Array.from(
const packageNames = Array.from(
new Set(
[...Object.keys(dependencies), ...Object.keys(devDependencies)].filter(
(pkg) => pkg.startsWith('@docusaurus'),
),
),
).sort();
)
.sort()
.map((name) => (tag ? `${name}@${tag}` : name));

if (!packageNames.length) {
logger.error(`Found 0 packages with scope @docusaurus`);
return;
}

if (opts.tag) {
packageNames = packageNames.map((_) => `${_}@${opts.tag}`);
}

logger.info`Found number=${packageNames.length} to update: name=${packageNames}`;
logger.info`Executing code=${`${npmClient} ${npmCommand} ${packageNames.join(' ')}`}`;
logger.info`Executing code=${`${npmClient} ${npmCommand} ${packageNames.join(
' ',
)}`}`;

childProcess.spawnSync(npmClient, [npmCommand, ...packageNames], {
stdio: 'inherit',
shell: os.platform() === 'win32',
});

await clear(path.resolve('.'));
await clear(siteDir);
}

0 comments on commit 234e289

Please sign in to comment.