copy-config
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -39,23 +39,41 @@ "use strict"; | ||
const run = async ({ fs = realFs, cwd = process.cwd(), argv = process.argv.slice(2), logger = console, } = {}) => { | ||
const args = (0, arg_1.default)({ | ||
const argSpec = { | ||
'--help': Boolean, | ||
'--repo': String, | ||
'--ref': String, | ||
'--path': String, | ||
'--output': String, | ||
'--config': String, | ||
'--ref': String, | ||
'--filter': String, | ||
'--purge': Boolean, | ||
'--aggressive': Boolean, | ||
}, { argv }); | ||
let repo = args['--repo']; | ||
assert.ok(repo, `--repo must be defined`); | ||
if (!repo.includes('://')) | ||
repo = `https://github.com/${repo}`; | ||
assert.ok(!/\s/.test(repo), `Invalid repo: ${repo}`); | ||
const tmpParent = '/tmp/copy-config/' + repo.split('://')[1]; | ||
fs.mkdirSync(tmpParent, { recursive: true }); | ||
const tempDir = fs.mkdtempSync(tmpParent + '/'); | ||
cp.execSync(`git clone ${repo}`, { cwd: tempDir }); | ||
const tempRepoDir = path.join(tempDir, fs.readdirSync(tempDir)[0]); | ||
}; | ||
const args = (0, arg_1.default)(argSpec, { argv }); | ||
if (args['--help']) { | ||
const options = Object.entries(argSpec).map(([k, v]) => `${k}: ${v.name}`); | ||
logger.info(`Available options: ${options.join(', ')}`); | ||
} | ||
const outputPath = path.resolve(cwd, args['--output'] || '.'); | ||
const getTempRepoDir = () => { | ||
let repo = args['--repo']; | ||
assert.ok(repo, `--repo must be defined`); | ||
if (!repo.includes('://')) | ||
repo = `https://github.com/${repo}`; | ||
assert.ok(!/\s/.test(repo), `Invalid repo: ${repo}`); | ||
const tmpParent = '/tmp/copy-config/' + repo.split('://')[1]; | ||
fs.mkdirSync(tmpParent, { recursive: true }); | ||
const tempDir = fs.mkdtempSync(tmpParent + '/'); | ||
cp.execSync(`git clone ${repo}`, { cwd: tempDir }); | ||
const tempRepoDir = path.join(tempDir, fs.readdirSync(tempDir)[0]); | ||
return tempRepoDir; | ||
}; | ||
const getLocalDir = () => { | ||
const inputPath = args['--path']; | ||
assert.ok(inputPath, '--path must be defined'); | ||
return path.resolve(cwd, inputPath); | ||
}; | ||
const copyFrom = args['--path'] ? getLocalDir() : getTempRepoDir(); | ||
if (args['--ref']) { | ||
cp.execSync(`git fetch`, { cwd: tempRepoDir }); | ||
cp.execSync(`git -c advice.detachedHead=false checkout ${args['--ref']}`, { cwd: tempRepoDir }); | ||
cp.execSync(`git fetch`, { cwd: copyFrom }); | ||
cp.execSync(`git -c advice.detachedHead=false checkout ${args['--ref']}`, { cwd: copyFrom }); | ||
} | ||
@@ -73,6 +91,6 @@ const config = args['--config'] | ||
.forEach(rule => { | ||
const files = globSync(rule.pattern, { cwd: tempRepoDir }); | ||
const filtered = args['--filter'] ? (0, lodash_1.intersection)(files, globSync(args['--filter'], { cwd: tempRepoDir })) : files; | ||
const files = globSync(rule.pattern, { cwd: copyFrom }); | ||
const filtered = args['--filter'] ? (0, lodash_1.intersection)(files, globSync(args['--filter'], { cwd: copyFrom })) : files; | ||
filtered.forEach(relPath => { | ||
const absPath = path.join(cwd, relPath); | ||
const absPath = path.join(outputPath, relPath); | ||
if (handled.has(absPath)) { | ||
@@ -82,3 +100,3 @@ logger.info(`skipping ${relPath} for pattern ${rule.pattern}, already handled`); | ||
} | ||
const remoteContent = fs.readFileSync(path.join(tempRepoDir, relPath)).toString(); | ||
const remoteContent = fs.readFileSync(path.join(copyFrom, relPath)).toString(); | ||
const localContent = fs.existsSync(absPath) ? fs.readFileSync(absPath).toString() : undefined; | ||
@@ -88,3 +106,3 @@ const newContent = rule.merge({ | ||
localContent, | ||
meta: { filepath: relPath, localCwd: cwd, remoteCwd: tempRepoDir }, | ||
meta: { filepath: relPath, localCwd: outputPath, remoteCwd: copyFrom }, | ||
}); | ||
@@ -100,2 +118,5 @@ if (newContent) { | ||
if (args['--purge']) { | ||
if (args['--path']) { | ||
throw new Error(`Can't purge if specifying local path`); | ||
} | ||
config.rules | ||
@@ -105,9 +126,11 @@ .slice() | ||
.forEach(rule => { | ||
const localFiles = globSync(rule.pattern, { cwd }); | ||
const filtered = args['--filter'] ? (0, lodash_1.intersection)(localFiles, globSync(args['--filter'], { cwd })) : localFiles; | ||
const localFiles = globSync(rule.pattern, { cwd: outputPath }); | ||
const filtered = args['--filter'] | ||
? (0, lodash_1.intersection)(localFiles, globSync(args['--filter'], { cwd: outputPath })) | ||
: localFiles; | ||
filtered.forEach(relPath => { | ||
const remoteFile = path.join(tempRepoDir, relPath); | ||
const absPath = path.join(cwd, relPath); | ||
const remoteFile = path.join(copyFrom, relPath); | ||
const absPath = path.join(outputPath, relPath); | ||
if (!fs.existsSync(remoteFile)) { | ||
logger.info(`Removing ${relPath} because it doesn't exist in ${repo}`); | ||
logger.info(`Removing ${relPath} because it doesn't exist in ${args['--repo']}`); | ||
fs.unlinkSync(absPath); | ||
@@ -114,0 +137,0 @@ } |
{ | ||
"name": "copy-config", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Copies another repo's configuration", | ||
"main": "dist/index.js", | ||
"bin": "dist/bin.js", | ||
"homepage": "https://github.com/mmkal/copy-config", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/mmkal/copy-config.git" | ||
}, | ||
"scripts": { | ||
@@ -11,3 +16,3 @@ "copy-config": "node dist/bin --repo mmkal/eslint-plugin-codegen", | ||
"lint": "tsc && eslint .", | ||
"build": "tsc -p tsconfig.lib.json", | ||
"build": "rm -rf dist && tsc -p tsconfig.lib.json", | ||
"test": "jest" | ||
@@ -20,3 +25,3 @@ }, | ||
"arg": "^5.0.2", | ||
"glob": "^9.0.0", | ||
"glob": "^10.0.0", | ||
"lodash": "^4.17.21", | ||
@@ -28,3 +33,3 @@ "type-fest": "^3.5.0" | ||
"@types/jest": "29.5.0", | ||
"@types/lodash": "4.14.192", | ||
"@types/lodash": "4.14.194", | ||
"eslint": "8.38.0", | ||
@@ -31,0 +36,0 @@ "eslint-plugin-mmkal": "0.0.1-2", |
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
37039
431
1
2
+ Added@isaacs/cliui@8.0.2(transitive)
+ Added@pkgjs/parseargs@0.11.0(transitive)
+ Addedansi-regex@5.0.16.1.0(transitive)
+ Addedansi-styles@4.3.06.2.1(transitive)
+ Addedcolor-convert@2.0.1(transitive)
+ Addedcolor-name@1.1.4(transitive)
+ Addedcross-spawn@7.0.6(transitive)
+ Addedeastasianwidth@0.2.0(transitive)
+ Addedemoji-regex@8.0.09.2.2(transitive)
+ Addedforeground-child@3.3.1(transitive)
+ Addedglob@10.4.5(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedisexe@2.0.0(transitive)
+ Addedjackspeak@3.4.3(transitive)
+ Addedminimatch@9.0.5(transitive)
+ Addedpackage-json-from-dist@1.0.1(transitive)
+ Addedpath-key@3.1.1(transitive)
+ Addedshebang-command@2.0.0(transitive)
+ Addedshebang-regex@3.0.0(transitive)
+ Addedsignal-exit@4.1.0(transitive)
+ Addedstring-width@4.2.35.1.2(transitive)
+ Addedstrip-ansi@6.0.17.1.0(transitive)
+ Addedwhich@2.0.2(transitive)
+ Addedwrap-ansi@7.0.08.1.0(transitive)
- Removedfs.realpath@1.0.0(transitive)
- Removedglob@9.3.5(transitive)
- Removedminimatch@8.0.4(transitive)
- Removedminipass@4.2.8(transitive)
Updatedglob@^10.0.0