update for updated packages
temporary remove of uci-logging
This commit is contained in:
parent
05b85065d8
commit
ce3a562785
3 changed files with 18 additions and 18 deletions
13
package.json
Normal file → Executable file
13
package.json
Normal file → Executable file
|
@ -5,7 +5,7 @@
|
||||||
"main": "src/read-lines.js",
|
"main": "src/read-lines.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "./node_modules/.bin/mocha --timeout 30000",
|
"test": "mocha --timeout 30000",
|
||||||
"testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha --timeout 30000' || exit 0",
|
"testd": "UCI_ENV=dev ./node_modules/.bin/nodemon --exec './node_modules/.bin/mocha --timeout 30000' || exit 0",
|
||||||
"testdd": "UCI_LOG_LEVEL='trace' npm run testd",
|
"testdd": "UCI_LOG_LEVEL='trace' npm run testd",
|
||||||
"testde": "UCI_LOG_LEVEL='warn' npm run testd",
|
"testde": "UCI_LOG_LEVEL='warn' npm run testd",
|
||||||
|
@ -29,14 +29,13 @@
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/uCOMmandIt/uci-utils#readme",
|
"homepage": "https://github.com/uCOMmandIt/uci-utils#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@uci-utils/logger": "^0.1.0",
|
"p-settle": "^5.1.1"
|
||||||
"p-settle": "^4.1.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"chai": "^4.3.4",
|
"chai": "^5.1.2",
|
||||||
"chai-arrays": "^2.2.0",
|
"chai-arrays": "^2.2.0",
|
||||||
"dirname-filename-esm": "^1.0.2",
|
"dirname-filename-esm": "^1.1.2",
|
||||||
"mocha": "^8.3.2",
|
"mocha": "^11.0.1",
|
||||||
"nodemon": "^2.0.7"
|
"nodemon": "^3.1.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,12 @@ import { readFile, writeFile } from 'fs'
|
||||||
const read = promisify(readFile)
|
const read = promisify(readFile)
|
||||||
const write = promisify(writeFile)
|
const write = promisify(writeFile)
|
||||||
import settle from 'p-settle'
|
import settle from 'p-settle'
|
||||||
import logger from '@uci-utils/logger'
|
// import logger from '@uci-utils/logger'
|
||||||
let log = logger({ package:'@uci-utils/read-lines', file:'src/read-lines.js'})
|
// let log = logger({ package:'@uci-utils/read-lines', file:'src/read-lines.js'})
|
||||||
|
|
||||||
// read lines from one or more files
|
// read lines from one or more files
|
||||||
function readLines (files=[],dir) {
|
function readLines (files=[],dir) {
|
||||||
log.debug({files:files,dir:dir,msg:'additional files'})
|
// log.debug({files:files,dir:dir,msg:'additional files'})
|
||||||
let list = []
|
let list = []
|
||||||
if (!Array.isArray(files)) files=[files]
|
if (!Array.isArray(files)) files=[files]
|
||||||
// each set in an the array is new line delimited set of ignore patterns
|
// each set in an the array is new line delimited set of ignore patterns
|
||||||
|
@ -17,13 +17,15 @@ function readLines (files=[],dir) {
|
||||||
return settle(files.map(file => {
|
return settle(files.map(file => {
|
||||||
// console.log('directory',path.dirname(file))
|
// console.log('directory',path.dirname(file))
|
||||||
if (path.dirname(file)==='.') file = dir+'/'+file
|
if (path.dirname(file)==='.') file = dir+'/'+file
|
||||||
log.debug({function:'readLines',file:file,msg:'reading a file of lines into array'})
|
// log.debug({function:'readLines',file:file,msg:'reading a file of lines into array'})
|
||||||
return read(file)
|
return read(file)
|
||||||
}))
|
}))
|
||||||
.then((sets) => {
|
.then((sets) => {
|
||||||
sets.forEach( set => {
|
sets.forEach( set => {
|
||||||
if (set.isFulfilled) list.push(...set.value.toString().match(/.+/g))
|
if (set.isFulfilled) list.push(...set.value.toString().match(/.+/g))
|
||||||
else log.warn({function:'readLines', error:set.reason, msg:' was unable to read file'})
|
else
|
||||||
|
console.log("unable to read file")
|
||||||
|
// log.warn({function:'readLines', error:set.reason, msg:' was unable to read file'})
|
||||||
})
|
})
|
||||||
return Promise.resolve(list)
|
return Promise.resolve(list)
|
||||||
})
|
})
|
||||||
|
@ -38,10 +40,10 @@ function writeLines (filePath,list) {
|
||||||
|
|
||||||
return write(filePath,list.join('\n'))
|
return write(filePath,list.join('\n'))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
log.info({function:'writeLines', file:filePath, msg:'wrote array to file of lines'})
|
// log.info({function:'writeLines', file:filePath, msg:'wrote array to file of lines'})
|
||||||
})
|
})
|
||||||
.catch( err => {
|
.catch( err => {
|
||||||
log.fatal({function:'writeLines', error:err, msg:'unable to write array to file of lines'})
|
// log.fatal({function:'writeLines', error:err, msg:'unable to write array to file of lines'})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,13 @@
|
||||||
// let ignoreFiles = ['.npmignore','.gitignore']
|
// let ignoreFiles = ['.npmignore','.gitignore']
|
||||||
|
|
||||||
import { readLines, writeLines } from '../src/read-lines.js'
|
import { readLines, writeLines } from '../src/read-lines.js'
|
||||||
import chai from 'chai'
|
|
||||||
import assertArrays from 'chai-arrays'
|
|
||||||
import { it } from 'mocha'
|
import { it } from 'mocha'
|
||||||
import { dirname } from 'dirname-filename-esm';
|
import { dirname } from 'dirname-filename-esm';
|
||||||
const __dirname = dirname(import.meta);
|
const __dirname = dirname(import.meta);
|
||||||
|
|
||||||
chai.use(assertArrays)
|
import { expect, use as chaiuse } from 'chai';
|
||||||
const expect = chai.expect
|
import assertArrays from 'chai-arrays'
|
||||||
|
chaiuse(assertArrays)
|
||||||
|
|
||||||
describe (
|
describe (
|
||||||
'Read a File of Lines to Array and vice versa',
|
'Read a File of Lines to Array and vice versa',
|
||||||
|
|
Loading…
Reference in a new issue