Skip to content

Commit

Permalink
Rename all filename extensions from .mjs to .js
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Sep 3, 2021
1 parent e3096b3 commit 83e3385
Show file tree
Hide file tree
Showing 37 changed files with 59 additions and 59 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ class Suffix {
export default Suffix
```

Save the above as `suffix.mjs` then process all files in the current directory using the above plugin as the replace chain.
Save the above as `suffix.js` then process all files in the current directory using the above plugin as the replace chain.

```
$ renamer --dry-run --chain suffix.mjs *
$ renamer --dry-run --chain suffix.js *
Dry run
Expand Down
2 changes: 1 addition & 1 deletion bin/cli.mjs → bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env node
import CliApp from '../lib/cli-app.mjs'
import CliApp from '../lib/cli-app.js'

const cliApp = new CliApp()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Renamer from '../../index.mjs'
import Renamer from '../../index.js'

const renamer = new Renamer()
const results = await renamer.rename({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Renamer from '../../index.mjs'
import Renamer from '../../index.js'

const renamer = new Renamer()
const options = {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion example/make-sandbox.mjs → example/make-sandbox.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
import path from 'path'
import rimraf from 'rimraf'
import { createFixture } from '../test/lib/util.mjs'
import { createFixture } from '../test/lib/util.js'

rimraf.sync('sandbox')

Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions index.mjs → index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import renameFile from './lib/rename-file.mjs'
import ReplaceChain from './lib/replace-chain.mjs'
import renameFile from './lib/rename-file.js'
import ReplaceChain from './lib/replace-chain.js'
import FileSet from 'file-set'
import { depthFirstCompare } from './lib/util.mjs'
import { depthFirstCompare } from './lib/util.js'

/** ∆ Renamer
≈ A tool to rename files and folders in bulk.
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 8 additions & 8 deletions lib/cli-app.mjs → lib/cli-app.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { optionDefinitions, usageSections } from './cli-options.mjs'
import { optionDefinitions, usageSections } from './cli-options.js'
import streamReadAll from 'stream-read-all'
import Renamer from 'renamer'
import { regExpBuilder, loadPlugins } from './util.mjs'
import { regExpBuilder, loadPlugins } from './util.js'
import commandLineUsage from 'command-line-usage'
import commandLineArgs from 'command-line-args'
import FindReplace from './chain/find-replace.mjs'
import IndexReplace from './chain/index-replace.mjs'
import DefaultView from './view/default.mjs'
import LongView from './view/long.mjs'
import DiffView from './view/diff.mjs'
import OneLineView from './view/one-line.mjs'
import FindReplace from './chain/find-replace.js'
import IndexReplace from './chain/index-replace.js'
import DefaultView from './view/default.js'
import LongView from './view/long.js'
import DiffView from './view/diff.js'
import OneLineView from './view/one-line.js'
import { isString } from 'typical'
import { loadModule } from 'load-module'

Expand Down
4 changes: 2 additions & 2 deletions lib/cli-options.mjs → lib/cli-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ const optionDefinitions = [
type: String,
alias: 'c',
/*
Must be lazyMultiple else this command would parse all mjs files as chain plugins.
renamer --chain index-replace.mjs --chain ./test/lib/dummy-plugin.mjs *.mjs -d
Must be lazyMultiple else this command would parse all js files as chain plugins.
renamer --chain index-replace.js --chain ./test/lib/dummy-plugin.js *.js -d
*/
lazyMultiple: true,
description: 'One or more replace chain plugins to use, set the `--chain` option multiple times to build a chain. For each value, supply either: a) a path to a plugin file b) a path to an installed plugin package or c) the name of a built-in plugin, either `find-replace` or `index-replace`. The default plugin chain is `find-replace` then `index-replace`.',
Expand Down
2 changes: 1 addition & 1 deletion lib/rename-file.mjs → lib/rename-file.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { promises as fs } from 'fs'
import { isFileAccessible } from './util.mjs'
import { isFileAccessible } from './util.js'

const dryRunLog = {}

Expand Down
6 changes: 3 additions & 3 deletions lib/replace-chain.mjs → lib/replace-chain.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { loadPlugins } from './util.mjs'
import { loadPlugins } from './util.js'
import arrayify from 'array-back'
import path from 'path'
import FindReplace from './chain/find-replace.mjs'
import IndexReplace from './chain/index-replace.mjs'
import FindReplace from './chain/find-replace.js'
import IndexReplace from './chain/index-replace.js'

class ReplaceChain {
async loadPlugins (pluginNames) {
Expand Down
7 changes: 3 additions & 4 deletions lib/util.mjs → lib/util.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { promises as fs } from 'fs'
import { constants } from 'fs'
import { promises as fs, constants } from 'fs'
import path from 'path'
import arrayify from 'array-back'
import { isClass } from 'typical'
import { loadModuleResolvedFrom, loadModuleRelativeTo } from 'load-module'
import FindReplace from './chain/find-replace.mjs'
import IndexReplace from './chain/index-replace.mjs'
import FindReplace from './chain/find-replace.js'
import IndexReplace from './chain/index-replace.js'
import getModulePaths from 'current-module-paths'
import * as globalDirs from 'global-dirs'
const __dirname = getModulePaths(import.meta.url).__dirname
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/view/diff.mjs → lib/view/diff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import DefaultView from './default.mjs'
import DefaultView from './default.js'
import fastDiff from 'fast-diff'

class DiffView extends DefaultView {
Expand Down
2 changes: 1 addition & 1 deletion lib/view/long.mjs → lib/view/long.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import DefaultView from './default.mjs'
import DefaultView from './default.js'

class LongView extends DefaultView {
logResult (result, options = {}) {
Expand Down
2 changes: 1 addition & 1 deletion lib/view/one-line.mjs → lib/view/one-line.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import DefaultView from './default.mjs'
import DefaultView from './default.js'

class OneLineView extends DefaultView {
logComplete (stats, options) {
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
"version": "3.2.1",
"author": "Lloyd Brookes <[email protected]>",
"bin": {
"renamer": "bin/cli.mjs"
"renamer": "bin/cli.js"
},
"license": "MIT",
"exports": "./index.mjs",
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=12.17"
},
"repository": "https://github.com/75lb/renamer",
"files": [
"index.mjs",
"index.js",
"bin",
"lib"
],
Expand All @@ -27,7 +28,7 @@
"batch"
],
"scripts": {
"test": "test-runner test/*.mjs test/internals/*.mjs",
"test": "test-runner test/*.js test/internals/*.js",
"cover": "c8 npm test && c8 report --reporter=text-lcov | coveralls"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion test/api-bad-input.mjs → test/api-bad-input.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Renamer from 'renamer'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
Expand Down
2 changes: 1 addition & 1 deletion test/api-find-replace.mjs → test/api-find-replace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Renamer from 'renamer'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
Expand Down
2 changes: 1 addition & 1 deletion test/api-plugin-custom.mjs → test/api-plugin-custom.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Renamer from 'renamer'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
Expand Down
2 changes: 1 addition & 1 deletion test/api-plugin-index.mjs → test/api-plugin-index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Renamer from 'renamer'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
Expand Down
8 changes: 4 additions & 4 deletions test/cli-bad-input.mjs → test/cli-bad-input.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import CliApp from '../lib/cli-app.mjs'
import CliApp from '../lib/cli-app.js'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
import TestRunner from 'test-runner'
import DefaultView from '../lib/view/default.mjs'
import DefaultView from '../lib/view/default.js'
const a = assert.strict

const tom = new TestRunner.Tom()
Expand Down Expand Up @@ -52,7 +52,7 @@ tom.test('--view: broken plugin', async function () {
const view = new TestView()
const cliApp = new CliApp({ view })
a.deepEqual(fs.existsSync(fixturePath), true)
await cliApp.start({ argv: ['-s', '--find', 'one', '--replace', 'yeah', fixturePath, '--view', './test/lib/broken-view.mjs'] })
await cliApp.start({ argv: ['-s', '--find', 'one', '--replace', 'yeah', fixturePath, '--view', './test/lib/broken-view.js'] })
a.equal(cliApp.view.constructor.name, 'TestView')
a.ok(/View must define a `write` method/.test(view.logs[0][0]))
a.equal(process.exitCode, 1)
Expand Down
20 changes: 10 additions & 10 deletions test/cli.mjs → test/cli.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import CliApp from '../lib/cli-app.mjs'
import CliApp from '../lib/cli-app.js'
import assert from 'assert'
import { createFixture } from './lib/util.mjs'
import { createFixture } from './lib/util.js'
import rimraf from 'rimraf'
import fs from 'fs'
import path from 'path'
import TestRunner from 'test-runner'
import { spawn } from 'child_process'
import DefaultView from '../lib/view/default.mjs'
import DiffView from '../lib/view/diff.mjs'
import DefaultView from '../lib/view/default.js'
import DiffView from '../lib/view/diff.js'
const a = assert.strict
const tom = new TestRunner.Tom({ maxConcurrency: 1 })

Expand Down Expand Up @@ -50,9 +50,9 @@ tom.test('simple, dry run', async function () {
tom.test('simple, using bin', async function () {
const fixturePath = createFixture(`${testRoot}/${this.index}/one`)
const origArgv = process.argv
process.argv = ['node', 'test.mjs', '-s', '--find', 'one', '--replace', 'yeah', fixturePath]
process.argv = ['node', 'test.js', '-s', '--find', 'one', '--replace', 'yeah', fixturePath]
a.deepEqual(fs.existsSync(fixturePath), true)
const mod = await import('../bin/cli.mjs') // prints '✔︎ tmp/cli.js/3/one → tmp/cli.js/3/yeah'
const mod = await import('../bin/cli.js') // prints '✔︎ tmp/cli.js/3/one → tmp/cli.js/3/yeah'
await mod.default
process.argv = origArgv
a.deepEqual(fs.existsSync(fixturePath), false)
Expand Down Expand Up @@ -97,7 +97,7 @@ tom.test('simple regexp, insensitive', async function () {

tom.test('input file list on stdin', async function () {
const fixturePath = createFixture(`${testRoot}/${this.index}/one`)
const renamer = spawn('node', [path.join('bin', 'cli.mjs'), '-f', 'one', '-r', 'two', '-s'])
const renamer = spawn('node', [path.join('bin', 'cli.js'), '-f', 'one', '-r', 'two', '-s'])
return new Promise((resolve, reject) => {
renamer.on('close', () => {
a.deepEqual(fs.existsSync(`${testRoot}/${this.index}/one`), false)
Expand Down Expand Up @@ -211,7 +211,7 @@ tom.test('--view: load plugin', async function () {
const fixturePath = createFixture(`${testRoot}/${this.index}/one`)
const cliApp = new CliApp()
a.deepEqual(fs.existsSync(fixturePath), true)
await cliApp.start({ argv: ['-s', '--find', 'one', '--replace', 'yeah', fixturePath, '--view', './test/lib/dummy-view.mjs'] })
await cliApp.start({ argv: ['-s', '--find', 'one', '--replace', 'yeah', fixturePath, '--view', './test/lib/dummy-view.js'] })
a.equal(cliApp.view.constructor.name, 'DummyView')
a.deepEqual(fs.existsSync(fixturePath), false)
a.deepEqual(fs.existsSync(`${testRoot}/${this.index}/yeah`), true)
Expand All @@ -230,15 +230,15 @@ tom.test('--chain built-in', async function () {
const fixturePath = createFixture(`${testRoot}/${this.index}/one`)
const cliApp = new CliApp()
a.deepEqual(fs.existsSync(fixturePath), true)
await cliApp.start({ argv: ['-s', '--chain', 'find-replace.mjs', '--find', 'one', '--replace', 'yeah', fixturePath] })
await cliApp.start({ argv: ['-s', '--chain', 'find-replace.js', '--find', 'one', '--replace', 'yeah', fixturePath] })
a.deepEqual(fs.existsSync(fixturePath), false)
a.deepEqual(fs.existsSync(`${testRoot}/${this.index}/yeah`), true)
})

tom.test('--chain built-in local --help', async function () {
const cliApp = new CliApp({ view: new TestView() })
await cliApp.start({
argv: ['--chain', 'find-replace.mjs', '--chain', './test/lib/dummy-plugin.mjs', '--help']
argv: ['--chain', 'find-replace.js', '--chain', './test/lib/dummy-plugin.js', '--help']
})
a.ok(/FindReplace/.test(cliApp.view.logs[0][0]))
a.ok(/DummyPlugin/.test(cliApp.view.logs[0][0]))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import renameFile from '../../lib/rename-file.mjs'
import renameFile from '../../lib/rename-file.js'
import assert from 'assert'
import fs from 'fs'
import { createFixture } from '../lib/util.mjs'
import { createFixture } from '../lib/util.js'
import rimraf from 'rimraf'
import TestRunner from 'test-runner'
const a = assert.strict
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ReplaceChain from '../../lib/replace-chain.mjs'
import ReplaceChain from '../../lib/replace-chain.js'
import assert from 'assert'
import path from 'path'
import TestRunner from 'test-runner'
Expand Down Expand Up @@ -134,7 +134,7 @@ tom.test('custom plugins plus a built-in', async function () {
}
const file = 'a-one-two'
const chain = new ReplaceChain()
await chain.loadPlugins(['find-replace.mjs', PluginOne, PluginTwo])
await chain.loadPlugins(['find-replace.js', PluginOne, PluginTwo])
const result = chain.replace(file, { find: 'a', replace: 'b' }, 0, ['a-one-two'])
a.deepEqual(result.from, file)
a.deepEqual(result.to, 'b-{{one}}-2')
Expand All @@ -148,7 +148,7 @@ tom.test('custom plugins plus a relative local path plugin', async function () {
}
}
const chain = new ReplaceChain()
await chain.loadPlugins(['test/lib/dummy-plugin.mjs', PluginOne])
await chain.loadPlugins(['test/lib/dummy-plugin.js', PluginOne])
const result = chain.replace('start', {}, 0, [])
a.deepEqual(result.from, 'start')
a.deepEqual(result.to, 'file: start, bindex: 0, file count: 0')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { depthFirstCompare } from '../../lib/util.mjs'
import { depthFirstCompare } from '../../lib/util.js'
import assert from 'assert'
import os from 'os'
import TestRunner from 'test-runner'
Expand Down
2 changes: 1 addition & 1 deletion test/internals/util.mjs → test/internals/util.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { depthFirstCompare } from '../../lib/util.mjs'
import { depthFirstCompare } from '../../lib/util.js'
import assert from 'assert'
import rimraf from 'rimraf'
import TestRunner from 'test-runner'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 83e3385

Please sign in to comment.