Skip to content

Commit

Permalink
refactor: move publish to directory
Browse files Browse the repository at this point in the history
  • Loading branch information
privatenumber committed Aug 4, 2024
1 parent 4484bc8 commit 5df3f28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 36 deletions.
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { cli } from 'cleye';
import outdent from 'outdent';
import { linkPackage, linkFromConfig } from './link-package';
import { loadConfig } from './utils/load-config';
import publish from './commands/publish';
import { publishCommand, publishHandler } from './commands/publish';

(async () => {
const argv = cli({
Expand Down Expand Up @@ -34,7 +34,7 @@ import publish from './commands/publish';
},
},
commands: [
publish.command,
publishCommand,
],
});

Expand Down Expand Up @@ -77,7 +77,7 @@ import publish from './commands/publish';
},
);
} else if (argv.command === 'publish') {
await publish.handler(cwdProjectPath, argv._);
await publishHandler(cwdProjectPath, argv._);
}
})().catch((error) => {
console.error('Error:', error.message);

Check warning on line 83 in src/cli.ts

View workflow job for this annotation

GitHub Actions / Test (ubuntu-latest)

Unexpected console statement
Expand Down
64 changes: 31 additions & 33 deletions src/commands/publish.ts → src/commands/publish/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import outdent from 'outdent';
import {
green, magenta, cyan, bold, dim,
} from 'kolorist';
import { readPackageJson } from '../utils/read-package-json.js';
import { hardlink } from '../utils/symlink.js';
import { cwdPath } from '../utils/cwd-path.js';
import { readPackageJson } from '../../utils/read-package-json.js';
import { hardlink } from '../../utils/symlink.js';
import { cwdPath } from '../../utils/cwd-path.js';

const linkPackage = async (
basePackagePath: string,
Expand Down Expand Up @@ -106,35 +106,33 @@ const linkPackage = async (
);
};

export default {
command: command({
name: 'publish',
parameters: ['<package paths...>'],
flags: {
// watch: {
// type: Boolean,
// alias: 'w',
// description: 'Watch for changes in the package and automatically relink',
// },
},
help: {
description: 'Link a package to simulate an environment similar to `npm install`',
},
}),

handler: async (
cwdProjectPath: string,
packagePaths: string[],
) => {
if (packagePaths.length > 0) {
await Promise.all(
packagePaths.map(
linkPackagePath => linkPackage(
cwdProjectPath,
linkPackagePath,
),
),
);
}
export const publishCommand = command({
name: 'publish',
parameters: ['<package paths...>'],
flags: {
// watch: {
// type: Boolean,
// alias: 'w',
// description: 'Watch for changes in the package and automatically relink',
// },
},
help: {
description: 'Link a package to simulate an environment similar to `npm install`',
},
});

export const publishHandler = async (
cwdProjectPath: string,
packagePaths: string[],
) => {
if (packagePaths.length > 0) {
await Promise.all(
packagePaths.map(
linkPackagePath => linkPackage(
cwdProjectPath,
linkPackagePath,
),
),
);
}
};

0 comments on commit 5df3f28

Please sign in to comment.