Skip to content

Commit

Permalink
refactor: code base
Browse files Browse the repository at this point in the history
  • Loading branch information
Airkro committed Dec 19, 2023
1 parent 17a1056 commit ac47cd1
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 60 deletions.
22 changes: 11 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions packages/cli/lib/bin.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import * as pack from './cmd/pack.mjs';

new Cheetor('../package.json', import.meta.url)
.command(pack)
.commandSafe('@bring-it/notify/dist/sub.mjs')
.commandSafe('@bring-it/npm/dist/sub.mjs')
.commandSafe('@bring-it/sample/dist/sub.mjs')
.commandSafe('@bring-it/sentry/dist/sub.mjs')
.commandSafe('@bring-it/sftp/dist/sub.mjs')
.commandSafe('@bring-it/notify')
.commandSafe('@bring-it/npm')
.commandSafe('@bring-it/sample')
.commandSafe('@bring-it/sentry')
.commandSafe('@bring-it/sftp')
.config((cli) => cli.wrap(null))
.setup();
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/cli",
"version": "0.8.1",
"version": "0.9.0",
"description": "Common command line interface of 'bring-it'",
"license": "MIT",
"author": {
Expand Down
5 changes: 3 additions & 2 deletions packages/notify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/notify",
"version": "0.1.4",
"version": "0.2.0",
"description": "Send releases notifications",
"license": "MIT",
"author": {
Expand All @@ -27,6 +27,7 @@
"bugs": {
"url": "https://github.com/airkro/bring-it/issues"
},
"main": "dist/sub.mjs",
"files": [
"dist"
],
Expand All @@ -40,7 +41,7 @@
"semver": "^7.5.4"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
"@bring-it/cli": "^0.9.0"
},
"engines": {
"node": "^18.0.0 || ^20.0.0",
Expand Down
4 changes: 1 addition & 3 deletions packages/npm/.best-shot/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ export const config = {
path: 'dist',
module: true,
},
entry: {
sub: './lib/cmd.mjs',
},
entry: './src/cmd.mjs',
};
5 changes: 3 additions & 2 deletions packages/npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/npm",
"version": "0.4.2",
"version": "0.5.0",
"description": "Publish npm packages when needed",
"license": "MIT",
"author": {
Expand Down Expand Up @@ -28,6 +28,7 @@
"bugs": {
"url": "https://github.com/airkro/bring-it/issues"
},
"main": "dist/main.mjs",
"files": [
"dist"
],
Expand All @@ -44,7 +45,7 @@
"validate-npm-package-name": "^5.0.0"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
"@bring-it/cli": "^0.9.0"
},
"engines": {
"node": "^18.0.0 || ^20.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/npm/lib/cmd.mjs → packages/npm/src/cmd.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export function builder(cli) {
}

export function handler(io) {
import('./npm/action.mjs')
import('./lib/action.mjs')
.then(({ action }) => action(io))
.catch((error) => {
process.exitCode = 1;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { check } from './check.mjs';
import { logger } from './logger.mjs';
import { scan } from './scan.mjs';
import { execX } from './utils.mjs';
import { execX, getPackageManager } from './utils.mjs';

export async function action({ preview = false, force = false } = {}) {
if (!(await check({ force }))) {
Expand All @@ -20,7 +20,11 @@ export async function action({ preview = false, force = false } = {}) {
logger.info("Won't publish in preview mode");
}

for (const { dir, name, packageManager } of list) {
const packageManager = await getPackageManager().catch(() => 'npm');

logger.info('Using', packageManager);

for (const { dir, name } of list) {
const label = preview ? '[Preview]' : '[Publish]';

logger.task(label, name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function check({ force }) {
return false;
}

if (!(await isGitClean())) {
if (!force && !(await isGitClean())) {
return false;
}
} catch (error) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 15 additions & 26 deletions packages/npm/lib/npm/scan.mjs → packages/npm/src/lib/scan.mjs
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
import { readFile } from 'node:fs/promises';
import { dirname } from 'node:path';

import { filter } from './filter.mjs';
import { getFileContentFromLastCommit, getLastCommitFiles } from './git.mjs';
import { logger } from './logger.mjs';
import { readNpmToken } from './token.mjs';

function readJSON(file) {
return readFile(file, 'utf8')
.then((raw) => JSON.parse(raw))
.then(
({
name,
version,
private: p = false,
engines,
publishConfig,
packageManager = 'npm',
}) => ({
pkg: file,
dir: dirname(file),
name,
version,
private: p,
publishConfig,
engines,
packageManager: packageManager.split('@')[0],
}),
)
import { readJSON } from './utils.mjs';

function readPkg(file) {
return readJSON(file)
.then(({ name, version, private: p = false, engines, publishConfig }) => ({
pkg: file,
dir: dirname(file),
name,
version,
private: p,
publishConfig,
engines,
}))
.catch(() => false);
}

Expand Down Expand Up @@ -60,7 +49,7 @@ async function publishReady(list) {
const io = [];

for (const item of list) {
const okay = await readJSON(item);
const okay = await readPkg(item);

if (okay && filter(okay)) {
io.push(okay);
Expand Down Expand Up @@ -115,7 +104,7 @@ export async function scan({ force }) {
const list1 = await getLastCommitFiles({ force });
const list2 = await publishReady(list1);
const list3 = force ? list2 : await versionChanged(list2);
const list4 = await publishable(list3);
const list4 = force ? list3 : await publishable(list3);
logger.info(
list4.length > 0 ? list4.length : 'No',
list4.length === 1 ? 'package' : 'packages',
Expand Down
File renamed without changes.
15 changes: 15 additions & 0 deletions packages/npm/lib/npm/utils.mjs → packages/npm/src/lib/utils.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';

import { execa } from 'execa';

function exec(exe, args, options) {
Expand All @@ -23,3 +26,15 @@ export function Exec(exe, args, options) {
return stdout?.trim();
});
}

export function readJSON(file) {
return readFile(file, 'utf8').then((raw) => JSON.parse(raw));
}

export async function getPackageManager() {
const pkg = resolve(process.cwd(), 'package.json');

return readJSON(pkg).then(
({ packageManager = 'npm' }) => packageManager.split('@')[0],
);
}
5 changes: 3 additions & 2 deletions packages/sample/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sample",
"version": "0.3.2",
"version": "0.4.0",
"description": "Generate code sample files",
"license": "MIT",
"author": {
Expand All @@ -26,6 +26,7 @@
"bugs": {
"url": "https://github.com/airkro/bring-it/issues"
},
"main": "dist/sub.mjs",
"files": [
"dist"
],
Expand All @@ -38,7 +39,7 @@
"globby": "^14.0.0"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
"@bring-it/cli": "^0.9.0"
},
"engines": {
"node": "^18.0.0 || ^20.0.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sentry",
"version": "0.3.2",
"version": "0.4.0",
"description": "Update sentry artifacts",
"license": "MIT",
"author": {
Expand All @@ -26,6 +26,7 @@
"bugs": {
"url": "https://github.com/airkro/bring-it/issues"
},
"main": "dist/sub.mjs",
"files": [
"dist"
],
Expand All @@ -41,7 +42,7 @@
"@npmcli/promise-spawn": "^7.0.0"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
"@bring-it/cli": "^0.9.0"
},
"engines": {
"node": "^18.0.0 || ^20.0.0"
Expand Down
5 changes: 3 additions & 2 deletions packages/sftp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bring-it/sftp",
"version": "0.2.2",
"version": "0.3.0",
"description": "SFTP deployment tool for frontend",
"license": "MIT",
"author": {
Expand All @@ -27,6 +27,7 @@
"bugs": {
"url": "https://github.com/airkro/bring-it/issues"
},
"main": "dist/sub.mjs",
"files": [
"dist"
],
Expand All @@ -49,7 +50,7 @@
"ssh-config": "^4.4.1"
},
"peerDependencies": {
"@bring-it/cli": "^0.8.0"
"@bring-it/cli": "^0.9.0"
},
"engines": {
"node": "^18.0.0 || ^20.0.0"
Expand Down

0 comments on commit ac47cd1

Please sign in to comment.