This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
223 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,44 @@ | ||
# UNDER DEVELOPMENT | ||
|
||
# mass-publish | ||
|
||
A barebones bulk NPM publisher. | ||
|
||
## Getting Started | ||
|
||
You can install the CLI from NPM as a devDependency for your project. | ||
|
||
```bash | ||
npm install mass-publish -D | ||
``` | ||
|
||
Then automatically generate `mass-publish.json` which will be used as the main configuration. It will also keep track of the last published commit for detecting changes. | ||
|
||
```bash | ||
npx mass-publish init | ||
``` | ||
|
||
## Configuration | ||
|
||
```js | ||
{ | ||
packages: ["packages/"], // Directories to check for changes | ||
ignoreExtension: [".json"], // Ignore differneces with file extension of a certain type (Optional) | ||
commitMessage: "chore: release new versions", // Commit message on publish | ||
commitFrom: "fullsha", // Commit SHA to compare differences from. This is automatically updated on every publish. | ||
commitTo: "fullsha", // Commit SHA to compare differences to. Default is the head commit (Optional) | ||
noVerify: false, // Refer to changed command flag | ||
autobump: false, // Refer to bump command flag | ||
yes: false, // Refer to bump command flag | ||
} | ||
``` | ||
|
||
Reference: [`config.ts`](https://github.com/fontsource/mass-publish/blob/main/src/changed/interfaces/config.ts) | ||
|
||
## Commands | ||
|
||
## How It Works | ||
|
||
1. Use Nodegit to compare the last known mass-publish commit (or custom hash) with the latest commits and determine the changes from the diff. | ||
1. Use isomorphic-git to compare the last known mass-publish commit (or custom hash) with the latest commits and determine the changes from the diff. | ||
2. Bump packages and validate they are publishable by comparing versions on the NPM registry using package-json. | ||
3. Use pacote and libnpmpublish to pack and publish the packages using an async queue. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,9 @@ | ||
import async from "async"; | ||
import chalk from "chalk"; | ||
import latestVersion from "latest-version"; | ||
import path from "path"; | ||
import jsonfile from "jsonfile"; | ||
import semver from "semver"; | ||
import { bumpCheck } from "./bump-check"; | ||
import { bumpValue } from "./bump-value"; | ||
import { bumpWrite } from "./bump-write"; | ||
import { createBumpObject } from "./create-bump"; | ||
|
||
import log from "../utils/log"; | ||
import { pathToPackage } from "../utils/path-to-package"; | ||
import type { BumpObject } from "./interfaces/bump-object"; | ||
|
||
import { PackageJson } from "../utils/interfaces/package-json"; | ||
import { QueueObject } from "./interfaces/queue-object"; | ||
import { BumpObject } from "./interfaces/bump-object"; | ||
|
||
const processQueue = async ({ | ||
packagePath, | ||
packageFile, | ||
bumpArg, | ||
verify, | ||
}: QueueObject) => { | ||
let npmVersion: string | false; | ||
// Get latest version from NPM registry | ||
try { | ||
npmVersion = await latestVersion(packageFile.name); | ||
} catch { | ||
// Assume package isn't published | ||
npmVersion = false; | ||
} | ||
|
||
// Bump current package.json | ||
const currentVersion = packageFile.version; | ||
const bumpedVersion = bumpValue(currentVersion, bumpArg); | ||
|
||
if (bumpedVersion && npmVersion) { | ||
// Compare if bumped version is greater than version on NPM | ||
if (semver.gt(bumpedVersion, npmVersion)) { | ||
await writeUpdate(packageFile, packagePath, bumpedVersion); | ||
} else { | ||
// Try bumping one more time this time | ||
const newBumpedVersion = bumpValue(bumpedVersion, "patch"); | ||
if (newBumpedVersion && semver.gt(newBumpedVersion, npmVersion)) { | ||
await writeUpdate(packageFile, packagePath, newBumpedVersion); | ||
} else { | ||
log( | ||
chalk.red( | ||
`${packageFile.name} failed to bump. Specified bump version is less than NPM version.` | ||
) | ||
); | ||
} | ||
} | ||
} else { | ||
log( | ||
chalk.red( | ||
`${packageFile.name} failed to bump. Possible failure due to bump value or incompatible existing package.json value.` | ||
) | ||
); | ||
} | ||
}; | ||
export { bumpCheck, bumpValue, bumpWrite, createBumpObject }; | ||
export type { BumpObject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { mocked } from "ts-jest/utils"; | ||
import { createBumpObject } from "./create-bump"; | ||
import { pathToPackage } from "../utils/path-to-package"; | ||
|
||
jest.mock("../utils/path-to-package"); | ||
|
||
describe("Create bump object", () => { | ||
test("Success", () => { | ||
const mockedPathPackage = mocked(pathToPackage); | ||
mockedPathPackage.mockReturnValue([ | ||
{ name: "test-1", version: "1.0.0" }, | ||
{ name: "test-2", version: "1.1.1" }, | ||
]); | ||
|
||
const diffExample = ["packages/test-1", "packages/test-2"]; | ||
const result = createBumpObject(diffExample, "patch"); | ||
|
||
const validResult = [ | ||
{ | ||
packageFile: { name: "test-1", version: "1.0.0" }, | ||
packagePath: "packages/test-1", | ||
bumpedVersion: "1.0.1", | ||
}, | ||
{ | ||
packageFile: { name: "test-2", version: "1.1.1" }, | ||
packagePath: "packages/test-2", | ||
bumpedVersion: "1.1.2", | ||
}, | ||
]; | ||
|
||
expect(result).toEqual(validResult); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { bumpValue } from "./bump-value"; | ||
import { pathToPackage } from "../utils/path-to-package"; | ||
|
||
import { BumpObject } from "./interfaces/bump-object"; | ||
|
||
const createBumpObject = (diff: string[], bumpArg: string): BumpObject[] => { | ||
const bumpObjectArr: BumpObject[] = []; | ||
const packageJsons = pathToPackage(diff); | ||
|
||
diff.forEach((filePath, index) => { | ||
const bumpedVersion = bumpValue(packageJsons[index].version, bumpArg); | ||
if (bumpedVersion) { | ||
const bumpObject: BumpObject = { | ||
packageFile: packageJsons[index], | ||
packagePath: filePath, | ||
bumpedVersion, | ||
}; | ||
|
||
bumpObjectArr.push(bumpObject); | ||
} else { | ||
const bumpObject: BumpObject = { | ||
packageFile: packageJsons[index], | ||
packagePath: filePath, | ||
bumpedVersion, | ||
failedValidation: true, | ||
}; | ||
|
||
bumpObjectArr.push(bumpObject); | ||
} | ||
}); | ||
|
||
return bumpObjectArr; | ||
}; | ||
|
||
export { createBumpObject }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { readConfig } from "./read-config"; | ||
import { findDiff } from "./find-diff"; | ||
|
||
export { findDiff, readConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import chalk from "chalk"; | ||
import path from "path"; | ||
import { mocked } from "ts-jest/utils"; | ||
|
||
import Bump from "./bump"; | ||
import { bumpWrite } from "../bump/bump-write"; | ||
|
||
jest.mock("../bump/bump-write.ts"); | ||
|
||
describe("Bump command", () => { | ||
let result: any; | ||
|
||
beforeEach(() => { | ||
result = []; | ||
jest | ||
.spyOn(process.stdout, "write") | ||
.mockImplementation(val => result.push(String(val).trim())); | ||
|
||
const mockedBumpWrite = mocked(bumpWrite); | ||
mockedBumpWrite.mockResolvedValue([]); | ||
}); | ||
|
||
afterEach(() => jest.restoreAllMocks()); | ||
|
||
test("Success", async () => { | ||
await Bump.run(["patch"]); | ||
}); | ||
}); |
Oops, something went wrong.