boilersuit
Advanced tools
Comparing version 0.3.5 to 0.3.6
const fs = require('fs'); | ||
const path = require('path'); | ||
const { concat, parseCamelCaseToArray } = require('../../tools/utils'); | ||
@@ -15,3 +16,3 @@ const Cases = require('../../tools/cases'); | ||
} | ||
fileToChange = `${fixedFolder}suit.json`; | ||
fileToChange = path.resolve(`${fixedFolder}suit.json`); | ||
} | ||
@@ -18,0 +19,0 @@ |
const colors = require('colors'); // eslint-disable-line | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { cleanFile } = require('../../tools/utils'); | ||
const removeSuitFromFile = filename => { | ||
fs.writeFileSync(filename, cleanFile(fs.readFileSync(filename).toString())); | ||
fs.writeFileSync( | ||
filename, | ||
cleanFile(fs.readFileSync(path.resolve(filename)).toString()), | ||
); | ||
}; | ||
@@ -8,0 +12,0 @@ |
const fs = require('fs'); | ||
const path = require('path'); | ||
@@ -11,6 +12,10 @@ /** | ||
const messages = []; | ||
if (fs.existsSync(`./.suit/${dotSuitFolder}/suit.old.json`) && !force) { | ||
if ( | ||
fs.existsSync(path.resolve(`./.suit/${dotSuitFolder}/suit.old.json`)) && | ||
!force | ||
) { | ||
if ( | ||
fs.readFileSync(`./.suit/${dotSuitFolder}/suit.old.json`).toString() === | ||
schemaBuf | ||
fs | ||
.readFileSync(path.resolve(`./.suit/${dotSuitFolder}/suit.old.json`)) | ||
.toString() === schemaBuf | ||
) { | ||
@@ -17,0 +22,0 @@ if (!quiet) { |
const fs = require('fs'); | ||
const path = require('path'); | ||
const { transforms } = require('../../tools/utils'); | ||
@@ -6,6 +7,8 @@ | ||
const { found, file } = transforms({ found: false, file: null }, [ | ||
...['./.suitrc.json', './.suitrc'].map(fileName => () => { | ||
const wasFound = fs.existsSync(fileName); | ||
return { found: wasFound, file: wasFound ? fileName : null }; | ||
}), | ||
...[path.resolve('./.suitrc.json'), path.resolve('./.suitrc')].map( | ||
fileName => () => { | ||
const wasFound = fs.existsSync(fileName); | ||
return { found: wasFound, file: wasFound ? fileName : null }; | ||
}, | ||
), | ||
]); | ||
@@ -12,0 +15,0 @@ if (!found) { |
const diff = require('deep-diff'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const Cases = require('../../tools/cases'); | ||
@@ -11,5 +12,5 @@ const { parseCamelCaseToArray } = require('../../tools/utils'); | ||
module.exports = ({ dotSuitFolder, schemaBuf }) => { | ||
if (fs.existsSync(`./.suit/${dotSuitFolder}/suit.old.json`)) { | ||
if (fs.existsSync(path.resolve(`./.suit/${dotSuitFolder}/suit.old.json`))) { | ||
const oldSchemaBuf = fs | ||
.readFileSync(`./.suit/${dotSuitFolder}/suit.old.json`) | ||
.readFileSync(path.resolve(`./.suit/${dotSuitFolder}/suit.old.json`)) | ||
.toString(); | ||
@@ -22,12 +23,12 @@ | ||
.filter(({ kind }) => kind === 'D' || kind === 'N') | ||
.map(({ path }, index) => { | ||
.map(({ path: oldPath }, index) => { | ||
if (!differences[index + 1]) return null; | ||
const newPath = differences[index + 1].path; | ||
return JSON.stringify(path.slice(0, path.length - 1)) === | ||
return JSON.stringify(oldPath.slice(0, oldPath.length - 1)) === | ||
JSON.stringify(newPath.slice(0, newPath.length - 1)) | ||
? { | ||
removed: path, | ||
removed: oldPath, | ||
added: newPath, | ||
removedCases: new Cases( | ||
parseCamelCaseToArray(path[path.length - 1]), | ||
parseCamelCaseToArray(oldPath[oldPath.length - 1]), | ||
).all(), | ||
@@ -43,5 +44,8 @@ addedCases: new Cases( | ||
...differences | ||
.filter(({ path, lhs, rhs }) => path.includes('saga') && lhs && rhs) | ||
.map(({ lhs, rhs, path }) => ({ | ||
removed: path, | ||
.filter( | ||
({ path: diffPath, lhs, rhs }) => | ||
diffPath.includes('saga') && lhs && rhs, | ||
) | ||
.map(({ lhs, rhs, path: diffPath }) => ({ | ||
removed: diffPath, | ||
removedCases: new Cases(parseCamelCaseToArray(`${lhs}`)).all(), | ||
@@ -48,0 +52,0 @@ addedCases: new Cases(parseCamelCaseToArray(`${rhs}`)).all(), |
const colors = require('colors'); // eslint-disable-line | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const checkExtends = require('./checkExtends'); | ||
@@ -15,4 +16,4 @@ const printError = require('../../tools/printError'); | ||
// If no .suit folder exists at the root, create one | ||
if (!fs.existsSync('./.suit')) { | ||
fs.mkdirSync('./.suit'); | ||
if (!fs.existsSync(path.resolve('./.suit'))) { | ||
fs.mkdirSync(path.resolve('./.suit')); | ||
} | ||
@@ -57,4 +58,6 @@ | ||
const file = `${c}`.includes('.json') ? c : `${c}.json`; | ||
if (fs.existsSync(`${folder}/${file}`)) { | ||
const buf = fs.readFileSync(`${folder}/${file}`).toString(); | ||
if (fs.existsSync(path.resolve(`${folder}/${file}`))) { | ||
const buf = fs | ||
.readFileSync(path.resolve(`${folder}/${file}`)) | ||
.toString(); | ||
const otherSchema = JSON.parse(buf); | ||
@@ -74,3 +77,3 @@ schema = { | ||
folder, | ||
schemaFile: `${folder}/${file}`, | ||
schemaFile: path.resolve(`${folder}/${file}`), | ||
schemaBuf: buf, | ||
@@ -83,4 +86,4 @@ }); | ||
); | ||
if (!allWatchedPaths.includes(`${folder}${file}`)) { | ||
watcher.add(`${folder}${file}`); | ||
if (!allWatchedPaths.includes(path.resolve(`${folder}${file}`))) { | ||
watcher.add(path.resolve(`${folder}${file}`)); | ||
} | ||
@@ -139,16 +142,36 @@ } else { | ||
buffers: { | ||
reducer: fs.readFileSync(`${folder}/reducer.js`).toString(), | ||
actions: fs.readFileSync(`${folder}/actions.js`).toString(), | ||
constants: fs.readFileSync(`${folder}/constants.js`).toString(), | ||
selectors: fs.readFileSync(`${folder}/selectors.js`).toString(), | ||
index: fs.readFileSync(`${folder}/index.js`).toString(), | ||
saga: fs.readFileSync(`${folder}/saga.js`).toString(), | ||
reducerTests: fs.existsSync(`${folder}/tests/reducer.test.js`) | ||
? fs.readFileSync(`${folder}/tests/reducer.test.js`).toString() | ||
reducer: fs | ||
.readFileSync(path.resolve(`${folder}/reducer.js`)) | ||
.toString(), | ||
actions: fs | ||
.readFileSync(path.resolve(`${folder}/actions.js`)) | ||
.toString(), | ||
constants: fs | ||
.readFileSync(path.resolve(`${folder}/constants.js`)) | ||
.toString(), | ||
selectors: fs | ||
.readFileSync(path.resolve(`${folder}/selectors.js`)) | ||
.toString(), | ||
index: fs.readFileSync(path.resolve(`${folder}/index.js`)).toString(), | ||
saga: fs.readFileSync(path.resolve(`${folder}/saga.js`)).toString(), | ||
reducerTests: fs.existsSync( | ||
path.resolve(`${folder}/tests/reducer.test.js`), | ||
) | ||
? fs | ||
.readFileSync(path.resolve(`${folder}/tests/reducer.test.js`)) | ||
.toString() | ||
: '', | ||
actionTests: fs.existsSync(`${folder}/tests/actions.test.js`) | ||
? fs.readFileSync(`${folder}/tests/actions.test.js`).toString() | ||
actionTests: fs.existsSync( | ||
path.resolve(`${folder}/tests/actions.test.js`), | ||
) | ||
? fs | ||
.readFileSync(path.resolve(`${folder}/tests/actions.test.js`)) | ||
.toString() | ||
: '', | ||
selectorsTests: fs.existsSync(`${folder}/tests/selectors.test.js`) | ||
? fs.readFileSync(`${folder}/tests/selectors.test.js`).toString() | ||
selectorsTests: fs.existsSync( | ||
path.resolve(`${folder}/tests/selectors.test.js`), | ||
) | ||
? fs | ||
.readFileSync(path.resolve(`${folder}/tests/selectors.test.js`)) | ||
.toString() | ||
: '', | ||
@@ -185,18 +208,33 @@ }, | ||
]); | ||
fs.writeFileSync(`${folder}/reducer.js`, newReducerBuffer); | ||
fs.writeFileSync(`${folder}/tests/reducer.test.js`, newReducerTestBuffer); | ||
fs.writeFileSync(`${folder}/actions.js`, newActionsBuffer); | ||
fs.writeFileSync(`${folder}/tests/actions.test.js`, newActionTestsBuffer); | ||
fs.writeFileSync(`${folder}/constants.js`, newConstantsBuffer); | ||
fs.writeFileSync(`${folder}/selectors.js`, newSelectorsBuffer); | ||
fs.writeFileSync(path.resolve(`${folder}/reducer.js`), newReducerBuffer); | ||
fs.writeFileSync( | ||
`${folder}/tests/selectors.test.js`, | ||
path.resolve(`${folder}/tests/reducer.test.js`), | ||
newReducerTestBuffer, | ||
); | ||
fs.writeFileSync(path.resolve(`${folder}/actions.js`), newActionsBuffer); | ||
fs.writeFileSync( | ||
path.resolve(`${folder}/tests/actions.test.js`), | ||
newActionTestsBuffer, | ||
); | ||
fs.writeFileSync( | ||
path.resolve(`${folder}/constants.js`), | ||
newConstantsBuffer, | ||
); | ||
fs.writeFileSync( | ||
path.resolve(`${folder}/selectors.js`), | ||
newSelectorsBuffer, | ||
); | ||
fs.writeFileSync( | ||
path.resolve(`${folder}/tests/selectors.test.js`), | ||
newSelectorsTestsBuffer, | ||
); | ||
fs.writeFileSync(`${folder}/index.js`, newIndexBuffer); | ||
fs.writeFileSync(`${folder}/saga.js`, saga.buffer); | ||
if (!fs.existsSync(`./.suit/${dotSuitFolder}`)) { | ||
fs.mkdirSync(`./.suit/${dotSuitFolder}`); | ||
fs.writeFileSync(path.resolve(`${folder}/index.js`), newIndexBuffer); | ||
fs.writeFileSync(path.resolve(`${folder}/saga.js`), saga.buffer); | ||
if (!fs.existsSync(path.resolve(`./.suit/${dotSuitFolder}`))) { | ||
fs.mkdirSync(path.resolve(`./.suit/${dotSuitFolder}`)); | ||
} | ||
fs.writeFileSync(`./.suit/${dotSuitFolder}/suit.old.json`, newSchemaBuf); | ||
fs.writeFileSync( | ||
path.resolve(`./.suit/${dotSuitFolder}/suit.old.json`), | ||
newSchemaBuf, | ||
); | ||
@@ -203,0 +241,0 @@ /** Runs prettier and checks for prettier warnings */ |
const fs = require('fs'); | ||
const path = require('path'); | ||
const { exec } = require('child_process'); | ||
@@ -7,3 +8,3 @@ const { concat } = require('../../tools/utils'); | ||
const prettierErrors = []; | ||
if (fs.existsSync('./.prettierrc')) { | ||
if (fs.existsSync(path.resolve('./.prettierrc'))) { | ||
try { | ||
@@ -10,0 +11,0 @@ exec(`prettier --config ./.prettierrc --write "${folder}/**/*.js"`); |
13
index.js
@@ -6,2 +6,3 @@ #!/usr/bin/env node | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const up = require('./commands/up'); | ||
@@ -11,3 +12,3 @@ const ajax = require('./commands/ajax'); | ||
program.version('0.3.5'); | ||
program.version('0.3.6'); | ||
@@ -19,8 +20,12 @@ program | ||
let watchedDirectories = ['!node_modules/**/*']; | ||
if (fs.existsSync('./.suitrc')) { | ||
const config = JSON.parse(fs.readFileSync('./.suitrc').toString()); | ||
if (fs.existsSync(path.resolve('./.suitrc'))) { | ||
const config = JSON.parse( | ||
fs.readFileSync(path.resolve('./.suitrc')).toString(), | ||
); | ||
if (config.include && config.include.length) { | ||
watchedDirectories = [ | ||
...watchedDirectories, | ||
config.include.map(path => `${path}/**/suit.json`), | ||
config.include.map(suitPath => | ||
path.resolve(`${suitPath}/**/suit.json`), | ||
), | ||
]; | ||
@@ -27,0 +32,0 @@ } else { |
{ | ||
"name": "boilersuit", | ||
"description": "A CLI tool for generating selectors, reducers, actions, constants and sagas in react-boilerplate", | ||
"version": "0.3.5", | ||
"version": "0.3.6", | ||
"main": "index.js", | ||
"author": "matt <matt.pocock@thevirtualforge.com>", | ||
"author": "Matt Pocock <matt.pocock@thevirtualforge.com>", | ||
"repository": { | ||
@@ -22,3 +22,3 @@ "type": "git", | ||
"bin": { | ||
"suit": "./index.js" | ||
"suit": "node index.js" | ||
}, | ||
@@ -25,0 +25,0 @@ "scripts": { |
@@ -425,2 +425,4 @@ <div style="text-align: center"><img src="https://raw.githubusercontent.com/mattpocock/boilersuit/master/logo.png" max-height="240px" alt="boilerplate logo"/></div> | ||
You'll need to add `"payload": true` if you want the action to carry a payload, and the `customFunction` to receive that payload. | ||
One final note: `"customFunction"` cannot be combined with `"set"` - though this may change in the future if it seems useful. | ||
@@ -427,0 +429,0 @@ |
const fs = require('fs'); | ||
const path = require('path'); | ||
const Cases = require('./cases'); | ||
@@ -11,8 +12,8 @@ const { cleanFile, parseCamelCaseToArray } = require('./utils'); | ||
const hasDuplicateReducer = | ||
cleanFile(fs.readFileSync(`${folder}/reducer.js`).toString()).indexOf( | ||
`${cases.camel}Reducer = `, | ||
) !== -1; | ||
cleanFile( | ||
fs.readFileSync(path.resolve(`${folder}/reducer.js`)).toString(), | ||
).indexOf(`${cases.camel}Reducer = `) !== -1; | ||
const constantFile = cleanFile( | ||
fs.readFileSync(`${folder}/constants.js`).toString(), | ||
fs.readFileSync(path.resolve(`${folder}/constants.js`)).toString(), | ||
); | ||
@@ -25,3 +26,3 @@ | ||
const actionsFile = cleanFile( | ||
fs.readFileSync(`${folder}/actions.js`).toString(), | ||
fs.readFileSync(path.resolve(`${folder}/actions.js`)).toString(), | ||
); | ||
@@ -28,0 +29,0 @@ |
const { expect } = require('chai'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const replaceInNameOnly = require('../replaceInNameOnly'); | ||
const file = fs.readFileSync('./tools/tests/mocks/nameOnly.js').toString(); | ||
const file = fs | ||
.readFileSync(path.resolve('./tools/tests/mocks/nameOnly.js')) | ||
.toString(); | ||
const correctFile = fs | ||
.readFileSync('./tools/tests/mocks/nameOnlyCorrect.js') | ||
.readFileSync(path.resolve('./tools/tests/mocks/nameOnlyCorrect.js')) | ||
.toString(); | ||
const file2 = fs.readFileSync('./tools/tests/mocks/nameOnly.2.js').toString(); | ||
const file2 = fs | ||
.readFileSync(path.resolve('./tools/tests/mocks/nameOnly.2.js')) | ||
.toString(); | ||
const correctFile2 = fs | ||
.readFileSync('./tools/tests/mocks/nameOnly.2.correct.js') | ||
.readFileSync(path.resolve('./tools/tests/mocks/nameOnly.2.correct.js')) | ||
.toString(); | ||
@@ -14,0 +19,0 @@ |
const { expect } = require('chai'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const { indexesOf } = require('../utils'); | ||
const file = fs.readFileSync('./tools/tests/mocks/nameOnly.2.js').toString(); | ||
const file = fs | ||
.readFileSync(path.resolve('./tools/tests/mocks/nameOnly.2.js')) | ||
.toString(); | ||
@@ -7,0 +10,0 @@ describe('indexesOf', () => { |
@@ -75,4 +75,5 @@ const concat = array => array.filter(line => line !== null).join(`\n`); | ||
const isImported = | ||
buffer.slice(0, buffer.lastIndexOf(' from ')).indexOf(`${property}`) !== | ||
-1; | ||
buffer | ||
.slice(0, buffer.lastIndexOf(` from '`)) | ||
.indexOf(`${property}`) !== -1; | ||
if (isImported) { | ||
@@ -79,0 +80,0 @@ return buffer; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
451544
3169
495