Skip to content

Commit

Permalink
yup
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotberry committed Oct 22, 2023
1 parent ce572de commit 87bbc63
Show file tree
Hide file tree
Showing 7 changed files with 865 additions and 806 deletions.
26 changes: 26 additions & 0 deletions default.detawksrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dryrun": false,
"directories": false,
"silent": true,
"rename": true,
"ignores": [
"node_modules",
".git",
".DS_Store"
],
"sequence": [
"toString",
"trim",
"doSwaps",
"toParamCase",
"lowerCase",
{
"name": "maxChars",
"args": {
"max": 10
}
},
"minChars",
"fallbackToRandom"
]
}
16 changes: 7 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ import useFdir from './lib/useFdir.js'
import { validateAndFormatInput } from './lib/path-validation.js'
import logChanges from './lib/log-changes.js'
import chalk from 'chalk'

let defaultOpts = {
dryrun: false,
directories: false,
silent: true,
rename: true,
}
import config from './lib/rc.js'

const run = async (globPattern, userOpts) => {
var opts = Object.assign({}, defaultOpts, userOpts)

var opts
if (userOpts) {
opts = Object.assign({}, config, userOpts)
} else {
opts = config
}
global.silent = opts.silent

let inputStr = await validateAndFormatInput(globPattern)
Expand Down
38 changes: 34 additions & 4 deletions lib/ignore.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import path from 'path'
import config from './rc.js'
var silent = process.env.SILENT
import fg from 'fast-glob'

var ignoreFn
var silent = process.env.SILENT

const filterFn = (f) => {
return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -32,7 +34,7 @@ async function filterArrayAsync(arrayOfFilePaths) {
if (isEvenNumber === true) {
return e
} else {
!global.silent && console.log(`ignoring ${e.old}`)
!global.silent && console.log(`ignoring ${e.old}`)
return null
}
})
Expand All @@ -41,9 +43,37 @@ async function filterArrayAsync(arrayOfFilePaths) {

return ret
}
const getIgnores = () => {
let ret = null
let ignores = config.ignores
if (Array.isArray(ignores)) {
if (ignores.length > 0) {
ret = ignores
}
}
if (ret === null) {
throw new Error(`ignore config in the config file is not valid`)
}
return ret
}
const init = () => {
let conf = getIgnores()
if (conf !== null) {
let shouldFilter = async (filePath) => {
const entries = await fg(conf, { dot: true })
return entries.includes(filePath)
}
return shouldFilter
} else {
return () => false
}
}
ignoreFn = init()

const ignore = async (arrayOfFilePaths) => {
let newArrayOfFilePaths = await filterArrayAsync(arrayOfFilePaths)
return newArrayOfFilePaths
let newArrayOfFilePathsFiltered = arrayOfFilePaths.filter((e) => {
return ignoreFn(e)
})
return newArrayOfFilePathsFiltered
}
export default ignore
59 changes: 32 additions & 27 deletions lib/rc.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,40 @@
import rc from 'rc'


let conf = rc('detawks', {})
import fs from 'fs'
let conf = rc('detawks', JSON.parse(fs.readFileSync('./default.detawksrc')))

const parseConf = () => {
const formatItem = (x) => {
if (typeof x === "string") {
console.log("jgfjf")
return {
name: x,
args: {},
}
} else if (typeof x === 'object') {
if (x.name) {
if (!x.args) {
x.args = {}
}
return x
} else {
throw new Error(
`sequence object must have a name property`
)
}
} else {
throw new Error(
`sequence array item must be a string or an object`
)
}
}
try {
let seq = conf.sequence.map(formatItem)
let ignores = conf.ignores
delete conf.sequence
delete conf.ignores
let parsedConf = {
ignores: conf.ignores,
sequence: conf.sequence.map((x) => {
if (typeof x === 'string') {
return {
name: x,
args: {},
}
} else if (typeof x === 'object') {
if (x.name) {
if (!x.args) {
x.args = {}
}
return x
} else {
throw new Error(
`sequence object must have a name property`
)
}
} else {
throw new Error(
`sequence array item must be a string or an object`
)
}
}),
ignores:ignores,
sequence: seq,
...conf,
}
return parsedConf
Expand Down
Loading

0 comments on commit 87bbc63

Please sign in to comment.