Skip to content

Commit d4d3e28

Browse files
authored
Merge pull request #6 from razor-x/v2
Version 2
2 parents 535c145 + 731e1a8 commit d4d3e28

File tree

16 files changed

+100
-120
lines changed

16 files changed

+100
-120
lines changed

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [2.0.0] / 2022-09-14
9+
10+
### Changed
11+
12+
- (**Breaking**) Rename npm package to config-curator.
13+
- (**Breaking**) Require Node.js v14.15.0 or higher.
14+
- (**Breaking**) Convert to pure ES module.
15+
816
## [1.1.0] / 2020-11-19
917

1018
### Changed
@@ -37,7 +45,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3745

3846
- Initial release.
3947

40-
[Unreleased]: https://github.com/razor-x/config-curator/compare/v1.1.0...HEAD
48+
[Unreleased]: https://github.com/razor-x/config-curator/compare/v2.0.0...HEAD
49+
[2.0.0]: https://github.com/razor-x/config-curator/compare/v1.1.0...v2.0.0
4150
[1.1.0]: https://github.com/razor-x/config-curator/compare/v1.0.3...v1.1.0
4251
[1.0.3]: https://github.com/razor-x/config-curator/compare/v1.0.2...v1.0.3
4352
[1.0.2]: https://github.com/razor-x/config-curator/compare/v1.0.1...v1.0.2

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# ☄️ Config Curator
22

3-
[![npm](https://img.shields.io/npm/v/@rxrc/curator.svg)](https://www.npmjs.com/package/@rxrc/curator)
4-
[![github](https://img.shields.io/badge/github-razor-x/config-curator-blue.svg)](https://github.com/razor-x/config-curator)
3+
[![npm](https://img.shields.io/npm/v/config-curator.svg)](https://www.npmjs.com/package/config-curator)
4+
[![main](https://github.com/razor-x/config-curator/actions/workflows/main.yml/badge.svg)](https://github.com/razor-x/config-curator/actions/workflows/main.yml)
55

66
**CLI tool for installing static configuration or dotfiles.**
77

@@ -52,7 +52,7 @@
5252
1. Add this as a development dependency to your project using [npm] with
5353

5454
```
55-
$ npm install --save-dev @rxrc/curator
55+
$ npm install --save-dev config-curator
5656
```
5757
5858
2. Add a [script][npm scripts] to your `package.json` with `"curator": "curator"`
@@ -86,9 +86,7 @@ and run the `curator` command to install the configuration.
8686
```js
8787
/* manifest.js */
8888
89-
'use strict'
90-
91-
const os = require('os')
89+
import os from 'os'
9290
9391
const targetRoot = os.homedir()
9492
@@ -135,35 +133,39 @@ const symlinks = [
135133
}
136134
]
137135
138-
module.exports = { targetRoot, unlinks, directories, files, symlinks }
136+
export default {
137+
targetRoot,
138+
unlinks,
139+
directories,
140+
files,
141+
symlinks
142+
}
139143
```
140144

141145
#### Complete manifest API
142146

143147
```js
144148
/* manifest.js */
145149

146-
'use strict'
150+
import os from 'os'
147151

148152
/* Prefix for all source paths
149153
* except for unlinks and symlinks which use targetRoot below.
150154
*
151-
* Use __dirname to refer to the location of this file
152-
* and process.cwd() for the current working directory.
155+
* Use process.cwd() for the current working directory.
153156
*
154157
* Default: the current working directory.
155158
*/
156-
const originRoot = require('os').homedir()
159+
const originRoot = os.homedir()
157160

158161
/* Prefix for all destination paths.
159162
* For unlinks and symlinks, the source is also prefixed.
160163
*
161-
* Use __dirname to refer to the location of this file
162-
* and process.cwd() for the current working directory.
164+
* Use process.cwd() for the current working directory.
163165
*
164166
* Default: a ./dest folder under the current working directory.
165167
*/
166-
const targetRoot = require('os').homedir()
168+
const targetRoot = os.homedir()
167169

168170
/* Package lookup backend to use:
169171
* pacman, dpkg, homebrew, pkgng, or noop.
@@ -334,7 +336,7 @@ const symlinks = [
334336
* or async function that returns the plain object.
335337
* Simply do not export an option to use the default.
336338
*/
337-
module.exports = {
339+
export default {
338340
unlinks,
339341
directories,
340342
files,

bin/curator.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,13 @@
11
#!/usr/bin/env node
22

3-
'use strict'
3+
import path from 'path'
44

5-
const path = require('path')
5+
import curator from '../lib/index.js'
66

7-
const curator = require('../lib')
7+
const manifestPath = process.argv[2]
8+
? path.resolve(process.argv[2])
9+
: path.resolve(process.cwd(), 'manifest.js')
810

9-
if (require.main === module) {
10-
const manifest = process.argv[2]
11-
? path.resolve(process.argv[2])
12-
: path.resolve(process.cwd(), 'manifest.js')
11+
const manifest = await import(manifestPath)
1312

14-
curator(require(manifest))
15-
.then(() => {
16-
process.exit()
17-
})
18-
.catch((err) => {
19-
console.log()
20-
console.error(err)
21-
process.exit(1)
22-
})
23-
}
13+
await curator(manifest.default)

lib/exec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
'use strict'
1+
import { exec } from 'child_process'
22

3-
const { exec } = require('child_process')
4-
5-
module.exports = (cmd = 'echo') =>
3+
export default (cmd = 'echo') =>
64
new Promise((resolve, reject) => {
75
exec(cmd, (err, stdout, stderr) => {
86
if (err) return reject(err)

lib/index.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
'use strict'
1+
import os from 'os'
22

3-
const os = require('os')
3+
import createPackageChecker from './package-checker.js'
4+
import createIo from './io/index.js'
5+
import normalize from './normalize.js'
6+
import install from './install.js'
47

5-
const createPackageChecker = require('./package-checker')
6-
const createIo = require('./io')
7-
const normalize = require('./normalize')
8-
const install = require('./install')
9-
10-
module.exports = async (manifestOrFunction) => {
8+
export default async (manifestOrFunction) => {
119
const promiseForManifest =
1210
typeof manifestOrFunction === 'function'
1311
? manifestOrFunction()

lib/install.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
'use strict'
2-
31
const isEmpty = (x) => x.length === 0
42

53
const makeGroups = (key, items) => {
@@ -94,7 +92,7 @@ const installSymlink =
9492
}
9593
}
9694

97-
module.exports = async ({ unlinks, directories, files, symlinks, io }) => {
95+
export default async ({ unlinks, directories, files, symlinks, io }) => {
9896
await Promise.all([...directories, ...files].map(checkAccess(io)))
9997
console.log('>> Unlinking paths')
10098
if (isEmpty(unlinks)) console.log('Nothing to do')

lib/io/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
'use strict'
1+
import os from 'os'
22

3-
const os = require('os')
4-
5-
const linux = require('./linux')
6-
const noop = require('./noop')
3+
import linux from './linux.js'
4+
import noop from './noop.js'
75

86
const has = (obj, k) => Object.prototype.hasOwnProperty.call(obj, k)
97

@@ -19,7 +17,7 @@ const getDefaultType = () => {
1917
return 'noop'
2018
}
2119

22-
module.exports = (type) => {
20+
export default (type) => {
2321
const typeIsNotNil = type != null
2422
const typeIsCustomObject = typeIsNotNil && typeof type === 'object'
2523
const typeIsNotSupported = typeIsNotNil && !has(types, type)

lib/io/linux.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
'use strict'
1+
import path from 'path'
22

3-
const path = require('path')
3+
import exec from '../exec.js'
4+
import {
5+
checkAccess,
6+
chmod,
7+
copyFile as copyFileShared,
8+
makeSymlink as makeSymlinkShared
9+
} from './shared.js'
410

5-
const exec = require('../exec')
6-
const { checkAccess, chmod, copyFile, makeSymlink } = require('./shared')
11+
const makeDirRecursive = ({ target }) => exec(`mkdir -p ${target}`)
712

813
const unlink = ({ target }) => exec(`rm -rf ${target}`)
914

10-
const makeDirRecursive = ({ target }) => exec(`mkdir -p ${target}`)
11-
1215
const chmodRecursive = ({ fmode, dmode, target }) =>
1316
Promise.all([
1417
exec(`find ${target} -type f -exec chmod ${fmode.toString(8)} {} +`),
@@ -30,18 +33,18 @@ const overwriteDirectory = async ({ source, destination }) => {
3033
return exec(`rsync -rtc --del --links ${source}/ ${destination}`)
3134
}
3235

33-
const copyFileLiunx = async ({ source, destination }) => {
36+
const copyFile = async ({ source, destination }) => {
3437
await makeDirRecursive({ target: path.dirname(destination) })
35-
return copyFile({ source, destination })
38+
return copyFileShared({ source, destination })
3639
}
3740

38-
const makeSymlinkLinux = async ({ source, destination }) => {
41+
const makeSymlink = async ({ source, destination }) => {
3942
await makeDirRecursive({ target: path.dirname(source) })
4043
await unlink({ target: source })
41-
return makeSymlink({ source, destination })
44+
return makeSymlinkShared({ source, destination })
4245
}
4346

44-
module.exports = {
47+
export default {
4548
checkAccess,
4649
unlink,
4750
chmod,
@@ -51,6 +54,6 @@ module.exports = {
5154
chgrp,
5255
chgrpRecursive,
5356
overwriteDirectory,
54-
copyFile: copyFileLiunx,
55-
makeSymlink: makeSymlinkLinux
57+
copyFile,
58+
makeSymlink
5659
}

lib/io/noop.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
'use strict'
2-
3-
const path = require('path')
1+
import path from 'path'
42

53
const checkAccess = ({ target }) => {
64
console.log(`Access ok for ${target}`)
@@ -56,7 +54,7 @@ const makeSymlink = ({ source, destination }) => {
5654
console.log(`Make symlink from ${source} to ${destination}`)
5755
}
5856

59-
module.exports = {
57+
export default {
6058
checkAccess,
6159
unlink,
6260
chmod,

lib/io/shared.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
'use strict'
1+
import fs, { promises as fsPromises } from 'fs'
22

3-
const fs = require('fs')
4-
const { promisify } = require('util')
3+
export const checkAccess = ({ target }) =>
4+
fsPromises.access(target, fs.constants.R_OK)
55

6-
const fsAccessAsync = promisify(fs.access)
7-
const fsChmodAsync = promisify(fs.chmod)
8-
const fsCopyFileAsync = promisify(fs.copyFile)
9-
const fsSymlink = promisify(fs.symlink)
6+
export const chmod = ({ mode, target }) => fsPromises.chmod(target, mode)
107

11-
const checkAccess = ({ target }) => fsAccessAsync(target, fs.constants.R_OK)
12-
const chmod = ({ mode, target }) => fsChmodAsync(target, mode)
13-
const copyFile = ({ source, destination }) =>
14-
fsCopyFileAsync(source, destination)
15-
const makeSymlink = ({ source, destination }) => fsSymlink(destination, source)
8+
export const copyFile = ({ source, destination }) =>
9+
fsPromises.copyFile(source, destination)
1610

17-
module.exports = {
18-
checkAccess,
19-
chmod,
20-
copyFile,
21-
makeSymlink
22-
}
11+
export const makeSymlink = ({ source, destination }) =>
12+
fsPromises.symlink(destination, source)

0 commit comments

Comments
 (0)