@pnpm/meta-updater
Advanced tools
Comparing version 0.0.0 to 0.0.1
#!/usr/bin/env node | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const meow = require("meow"); | ||
const _1 = require("."); | ||
const path = require("path"); | ||
_1.default(path.resolve(process.argv[2])).catch((err) => { | ||
const cli = meow(` | ||
Usage | ||
$ meta-updater <path to js> | ||
Options | ||
--test Do not update the files. Fail if updates are needed. | ||
Examples | ||
$ meta-updater update.js | ||
$ meta-updater update.js --test | ||
`, { | ||
flags: { | ||
test: { | ||
type: 'boolean', | ||
}, | ||
}, | ||
}); | ||
_1.default(path.resolve(cli.input[0]), cli.flags).catch((err) => { | ||
console.error(err); | ||
@@ -8,0 +26,0 @@ process.exit(1); |
@@ -1,1 +0,3 @@ | ||
export default function (updaterFilePath: string): Promise<void>; | ||
export default function (updaterFilePath: string, opts: { | ||
test?: boolean; | ||
}): Promise<void>; |
@@ -8,13 +8,17 @@ "use strict"; | ||
const exists = require("path-exists"); | ||
const R = require("ramda"); | ||
const writeJsonFile = require("write-json-file"); | ||
async function default_1(updaterFilePath) { | ||
const printDiff = require("print-diff"); | ||
async function default_1(updaterFilePath, opts) { | ||
var _a; | ||
const workspaceDir = await find_workspace_dir_1.default(updaterFilePath); | ||
if (!workspaceDir) | ||
throw new Error(`${updaterFilePath} is not inside a workspace`); | ||
const { default: updater } = await Promise.resolve().then(() => require(updaterFilePath)); | ||
const updaterLib = await Promise.resolve().then(() => require(updaterFilePath)); | ||
const updater = (_a = updaterLib.default) !== null && _a !== void 0 ? _a : updaterLib; | ||
const updateOptions = await updater(workspaceDir); | ||
await performUpdates(workspaceDir, updateOptions); | ||
await performUpdates(workspaceDir, updateOptions, opts); | ||
} | ||
exports.default = default_1; | ||
async function performUpdates(workspaceDir, update) { | ||
async function performUpdates(workspaceDir, update, opts) { | ||
let pkgs = await find_workspace_packages_1.default(workspaceDir, { engineStrict: false }); | ||
@@ -24,4 +28,13 @@ for (const { dir, manifest, writeProjectManifest } of pkgs) { | ||
if (p === 'package.json') { | ||
await writeProjectManifest(await updateFn(manifest, dir, manifest)); | ||
continue; | ||
const updatedManifest = await updateFn(manifest, dir, manifest); | ||
const needsUpdate = !R.equals(manifest, updatedManifest); | ||
if (!needsUpdate) | ||
continue; | ||
if (!opts.test) { | ||
await writeProjectManifest(updatedManifest); | ||
continue; | ||
} | ||
console.log(`ERROR: package.json file in ${dir} is not up-to-date`); | ||
printJsonDiff(manifest, updatedManifest); | ||
process.exit(1); | ||
} | ||
@@ -35,6 +48,19 @@ if (!p.endsWith('.json')) | ||
const obj = await loadJsonFile(fp); | ||
await writeJsonFile(fp, await updateFn(obj, dir, manifest), { detectIndent: true }); | ||
const updatedObj = await updateFn(obj, dir, manifest); | ||
const needsUpdate = !R.equals(obj, updatedObj); | ||
if (!needsUpdate) | ||
continue; | ||
if (!opts.test) { | ||
await writeJsonFile(fp, updatedObj, { detectIndent: true }); | ||
continue; | ||
} | ||
console.log(`ERROR: ${fp} is not up-to-date`); | ||
printJsonDiff(obj, updatedObj); | ||
process.exit(1); | ||
} | ||
} | ||
} | ||
function printJsonDiff(actual, expected) { | ||
printDiff(JSON.stringify(actual, null, 2), JSON.stringify(expected, null, 2)); | ||
} | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@pnpm/meta-updater", | ||
"version": "0.0.0", | ||
"description": "Keeps meta files up-to-date in a monorepo", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"bin": "lib/cli.js", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"scripts": { | ||
"prepublishOnly": "npm run tsc", | ||
"tsc": "rimraf lib && tsc", | ||
"test": "pnpm run tsc" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pnpm/meta-updater.git" | ||
}, | ||
"keywords": [], | ||
"engines": { | ||
"node": ">=10.12" | ||
}, | ||
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/meta-updater/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/meta-updater#readme", | ||
"dependencies": { | ||
"@pnpm/find-workspace-dir": "^2.0.0", | ||
"@pnpm/find-workspace-packages": "^2.3.30", | ||
"@pnpm/logger": "^3.2.3", | ||
"@pnpm/types": "^6.3.1", | ||
"load-json-file": "^6.2.0", | ||
"path-exists": "^4.0.0", | ||
"write-json-file": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^14.14.19", | ||
"rimraf": "^3.0.2", | ||
"typescript": "^4.1.3" | ||
} | ||
"name": "@pnpm/meta-updater", | ||
"version": "0.0.1", | ||
"description": "Keeps meta files up-to-date in a monorepo", | ||
"main": "lib/index.js", | ||
"typings": "lib/index.d.ts", | ||
"bin": "lib/cli.js", | ||
"files": [ | ||
"lib", | ||
"!*.map" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/pnpm/meta-updater.git" | ||
}, | ||
"keywords": [], | ||
"engines": { | ||
"node": ">=10.12" | ||
}, | ||
"author": "Zoltan Kochan <z@kochan.io> (https://www.kochan.io/)", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/pnpm/meta-updater/issues" | ||
}, | ||
"homepage": "https://github.com/pnpm/meta-updater#readme", | ||
"dependencies": { | ||
"@pnpm/find-workspace-dir": "^2.0.0", | ||
"@pnpm/find-workspace-packages": "^2.3.30", | ||
"@pnpm/logger": "^3.2.3", | ||
"@pnpm/types": "^6.3.1", | ||
"load-json-file": "^6.2.0", | ||
"meow": "9", | ||
"path-exists": "^4.0.0", | ||
"print-diff": "^1.0.0", | ||
"ramda": "^0.27.1", | ||
"write-json-file": "^4.3.0" | ||
}, | ||
"devDependencies": { | ||
"@types/fs-extra": "^9.0.11", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^14.14.19", | ||
"@types/ramda": "^0.27.41", | ||
"execa": "^5.1.1", | ||
"fs-extra": "^10.0.0", | ||
"jest": "^27.0.5", | ||
"rimraf": "^3.0.2", | ||
"tempy": "^1.0.1", | ||
"ts-jest": "^27.0.3", | ||
"typescript": "^4.1.3" | ||
}, | ||
"scripts": { | ||
"compile": "rimraf lib && tsc", | ||
"test": "pnpm run compile && jest" | ||
} | ||
} |
@@ -5,5 +5,3 @@ # @pnpm/meta-updater | ||
<!--@shields('npm', 'travis')--> | ||
[![npm version](https://img.shields.io/npm/v/@pnpm/meta-updater.svg)](https://www.npmjs.com/package/@pnpm/meta-updater) | ||
<!--/@--> | ||
@@ -16,4 +14,32 @@ ## Installation | ||
## Usage | ||
Create a JavaScript file that contains the updater functions. For instance, the next file will have updaters for `package.json` and `tsconfig.json` files: | ||
```js | ||
module.exports = (workspaceDir) => { | ||
return { | ||
'package.json': (manifest, dir) => { | ||
return { | ||
...manifest, | ||
author: 'Foo Bar', | ||
} | ||
}, | ||
'tsconfig.json': (tsConfig, dir) => { | ||
return { | ||
...tsConfig, | ||
compilerOptions: { | ||
outDir: 'lib', | ||
rootDir: 'src', | ||
}, | ||
} | ||
}, | ||
} | ||
} | ||
``` | ||
To perform the update on the affected config files, pass the path to the updater file to the CLI. For instance: `meta-updater ./update.js` | ||
## License | ||
[MIT](./LICENSE) © [Zoltan Kochan](https://www.kochan.io/) |
9594
9
92
44
10
11
+ Addedmeow@9
+ Addedprint-diff@^1.0.0
+ Addedramda@^0.27.1
+ Added@types/minimist@1.2.5(transitive)
+ Added@types/normalize-package-data@2.4.4(transitive)
+ Addedarrify@1.0.1(transitive)
+ Addedcamelcase@5.3.1(transitive)
+ Addedcamelcase-keys@6.2.2(transitive)
+ Addeddecamelize@1.2.0(transitive)
+ Addeddecamelize-keys@1.1.1(transitive)
+ Addeddiff@4.0.2(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedhard-rejection@2.1.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhosted-git-info@2.8.94.1.0(transitive)
+ Addedindent-string@4.0.0(transitive)
+ Addedis-core-module@2.13.1(transitive)
+ Addedis-plain-obj@1.1.0(transitive)
+ Addedkind-of@6.0.3(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addedmap-obj@1.0.14.3.0(transitive)
+ Addedmeow@9.0.0(transitive)
+ Addedmin-indent@1.0.1(transitive)
+ Addedminimist-options@4.1.0(transitive)
+ Addednormalize-package-data@2.5.03.0.3(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-parse@1.0.7(transitive)
+ Addedprint-diff@1.0.0(transitive)
+ Addedquick-lru@4.0.1(transitive)
+ Addedread-pkg@5.2.0(transitive)
+ Addedread-pkg-up@7.0.1(transitive)
+ Addedredent@3.0.0(transitive)
+ Addedresolve@1.22.8(transitive)
+ Addedsemver@5.7.2(transitive)
+ Addedspdx-correct@3.2.0(transitive)
+ Addedspdx-exceptions@2.5.0(transitive)
+ Addedspdx-expression-parse@3.0.1(transitive)
+ Addedspdx-license-ids@3.0.18(transitive)
+ Addedstrip-indent@3.0.0(transitive)
+ Addedsupports-preserve-symlinks-flag@1.0.0(transitive)
+ Addedtrim-newlines@3.0.1(transitive)
+ Addedtype-fest@0.18.10.8.1(transitive)
+ Addedvalidate-npm-package-license@3.0.4(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)