Skip to content

Commit

Permalink
chore: apply autoformatting from new Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
crutchcorn committed Sep 5, 2023
1 parent 1a52401 commit 3026d78
Show file tree
Hide file tree
Showing 48 changed files with 155 additions and 157 deletions.
2 changes: 1 addition & 1 deletion packages/node-plop/src/actions/_common-action-add-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function addFile(data, cfg, plop) {
const transformedTemplate = await getTransformedTemplate(
renderedTemplate,
data,
cfg
cfg,
);

await fspp.writeFile(fileDestPath, transformedTemplate);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function (
action,
{ checkPath = true, checkAbortOnFail = true } = {}
{ checkPath = true, checkAbortOnFail = true } = {},
) {
// it's not even an object, you fail!
if (typeof action !== "object") {
Expand Down
10 changes: 5 additions & 5 deletions packages/node-plop/src/actions/_common-action-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ export const normalizePath = (path) => {
export const makeDestPath = (data, cfg, plop) => {
return path.resolve(
plop.getDestBasePath(),
plop.renderString(normalizePath(cfg.path) || "", getFullData(data, cfg))
plop.renderString(normalizePath(cfg.path) || "", getFullData(data, cfg)),
);
};

export function getRenderedTemplatePath(data, cfg, plop) {
if (cfg.templateFile) {
const absTemplatePath = path.resolve(
plop.getPlopfilePath(),
cfg.templateFile
cfg.templateFile,
);
return plop.renderString(
normalizePath(absTemplatePath),
getFullData(data, cfg)
getFullData(data, cfg),
);
}
return null;
Expand Down Expand Up @@ -68,8 +68,8 @@ export async function getTransformedTemplate(template, data, cfg) {
if (typeof result !== "string")
throw new TypeError(
`Invalid return value for transform (${JSON.stringify(
result
)} is not a string)`
result,
)} is not a string)`,
);

return result;
Expand Down
8 changes: 4 additions & 4 deletions packages/node-plop/src/actions/addMany.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default async function (data, userConfig, plop) {
cfg.templateFiles,
cfg.base,
cfg.globOptions,
plop
plop,
);

const filesAdded = [];
Expand All @@ -49,7 +49,7 @@ export default async function (data, userConfig, plop) {
const fileCfg = Object.assign({}, cfg, {
path: stripExtensions(
cfg.stripExtensions,
resolvePath(cfg.destination, templateFile, cfg.base)
resolvePath(cfg.destination, templateFile, cfg.base),
),
templateFile: absTemplatePath,
});
Expand All @@ -66,7 +66,7 @@ function resolveTemplateFiles(templateFilesGlob, basePath, globOptions, plop) {
globOptions = Object.assign({ cwd: plop.getPlopfilePath() }, globOptions);
return globbySync(
templateFilesGlob,
Object.assign({ braceExpansion: false }, globOptions)
Object.assign({ braceExpansion: false }, globOptions),
)
.filter(isUnder(basePath))
.filter(isAbsoluteOrRelativeFileTo(plop.getPlopfilePath()));
Expand All @@ -82,7 +82,7 @@ function isUnder(basePath = "") {

function resolvePath(destination, file, rootPath) {
return normalizePath(
path.join(destination, dropFileRootPath(file, rootPath))
path.join(destination, dropFileRootPath(file, rootPath)),
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/node-plop/src/actions/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const doAppend = async function (data, cfg, plop, fileData) {
const lastPart = parts[parts.length - 1];
const lastPartWithoutDuplicates = lastPart.replace(
new RegExp(separator + stringToAppend, "g"),
""
"",
);
fileData = fileData.replace(lastPart, lastPartWithoutDuplicates);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/node-plop/src/fs-promise-proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const writeFileRaw = (path, data) =>
export const fileExists = (path) =>
fs.promises.access(path).then(
() => true,
() => false
() => false,
);

export const constants = fs.constants;
12 changes: 6 additions & 6 deletions packages/node-plop/src/generator-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function (plopfileApi, flags) {
const [promptsAfterBypass, bypassAnswers] = await promptBypass(
prompts,
bypassArr,
plopfileApi
plopfileApi,
);

return await plopfileApi.inquirer
Expand All @@ -35,7 +35,7 @@ export default function (plopfileApi, flags) {
const runGeneratorActions = async function (
genObject,
data = {},
hooks = {}
hooks = {},
) {
const noop = () => {};
const {
Expand Down Expand Up @@ -114,7 +114,7 @@ export default function (plopfileApi, flags) {
const actionResult = await executeActionLogic(
actionLogic,
actionCfg,
data
data,
);
onSuccess(actionResult);
changes.push(actionResult);
Expand Down Expand Up @@ -156,7 +156,7 @@ export default function (plopfileApi, flags) {

// track keys that can be applied to the main data scope
const cfgDataKeys = Object.keys(cfgData).filter(
(k) => typeof data[k] === "undefined"
(k) => typeof data[k] === "undefined",
);
// copy config data into main data scope so it's available for templates
cfgDataKeys.forEach((k) => {
Expand All @@ -174,13 +174,13 @@ export default function (plopfileApi, flags) {
// a rejected promise is treated as a failure
(err) => {
throw { type, path: "", error: err.message || err.toString() };
}
},
)
// cleanup main data scope so config data doesn't leak
.finally(() =>
cfgDataKeys.forEach((k) => {
delete data[k];
})
}),
);
};

Expand Down
20 changes: 10 additions & 10 deletions packages/node-plop/src/node-plop.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {
{
pkg: (propertyPath) => _get(pkgJson, propertyPath, ""),
},
bakedInHelpers
bakedInHelpers,
);
const baseHelpers = Object.keys(helpers);

Expand All @@ -45,10 +45,10 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {

function renderString(template, data) {
Object.keys(helpers).forEach((h) =>
handlebars.registerHelper(h, helpers[h])
handlebars.registerHelper(h, helpers[h]),
);
Object.keys(partials).forEach((p) =>
handlebars.registerPartial(p, partials[p])
handlebars.registerPartial(p, partials[p]),
);
return handlebars.compile(template)(data);
}
Expand Down Expand Up @@ -103,7 +103,7 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {
{
destBasePath: getDestBasePath(),
},
loadCfg
loadCfg,
);

await Promise.all(
Expand All @@ -119,35 +119,35 @@ async function nodePlop(plopfilePath = "", plopCfg = {}) {
partials: false,
actionTypes: false,
},
includeCfg
includeCfg,
);

const genNameList = proxy.getGeneratorList().map((g) => g.name);
loadAsset(
genNameList,
includeCfg === true || include.generators,
setGenerator,
(proxyName) => ({ proxyName, proxy })
(proxyName) => ({ proxyName, proxy }),
);
loadAsset(
proxy.getPartialList(),
includeCfg === true || include.partials,
setPartial,
proxy.getPartial
proxy.getPartial,
);
loadAsset(
proxy.getHelperList(),
includeCfg === true || include.helpers,
setHelper,
proxy.getHelper
proxy.getHelper,
);
loadAsset(
proxy.getActionTypeList(),
includeCfg === true || include.actionTypes,
setActionType,
proxy.getActionType
proxy.getActionType,
);
})
}),
);
}

Expand Down
9 changes: 5 additions & 4 deletions packages/node-plop/src/prompt-bypass.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ const typeBypass = {

const valList = v.split(",");
const valuesNoMatch = valList.filter(
(val) => !prompt.choices.some((c, idx) => choiceMatchesValue(c, idx, val))
(val) =>
!prompt.choices.some((c, idx) => choiceMatchesValue(c, idx, val)),
);
if (valuesNoMatch.length) {
throw Error(`no match for "${valuesNoMatch.join('", "')}"`);
}

return valList.map((val) =>
getChoiceValue(
prompt.choices.find((c, idx) => choiceMatchesValue(c, idx, val))
)
prompt.choices.find((c, idx) => choiceMatchesValue(c, idx, val)),
),
);
},
list: listTypeBypass,
Expand Down Expand Up @@ -186,7 +187,7 @@ export default async function (prompts, bypassArr, plop) {
} catch (err) {
// if we encounter an error above... assume the bypass value was invalid
bypassFailures.push(
`The "${p.name}" prompt did not recognize "${val}" as a valid ${p.type} value (ERROR: ${err.message})`
`The "${p.name}" prompt did not recognize "${val}" as a valid ${p.type} value (ERROR: ${err.message})`,
);
bypassedPromptValues.push(false);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("abort-on-fail", () => {
expect(changes.length).toBe(0);
expect(failures.length).toBe(2);
expect(failures[1].error).not.toBe(
"Aborted due to previous action failure"
"Aborted due to previous action failure",
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe("action-data-cleanup", () => {
.map((c) => normalizePath(c.path).split("/").slice(-1))
.join("|");
expect(addedFiles).toBe(
"one-unchanged.txt|two-unchanged.txt|three-unchanged.txt"
"one-unchanged.txt|two-unchanged.txt|three-unchanged.txt",
);
expect(changes.length).toBe(3);
expect(failures.length).toBe(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ describe("addMany-dynamic-template-file", function () {

expect(
multipleAddsResult.changes[0].path.includes(
`${expectedFiles.length} files added`
)
`${expectedFiles.length} files added`,
),
).toBe(true);
});

test("Test the content of the rendered file", () => {
const filePath = path.resolve(
testSrcPath,
"john-doe-bar-chart/john-doe-bar-tmpl.html"
"john-doe-bar-chart/john-doe-bar-tmpl.html",
);
const content = fs.readFileSync(filePath).toString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe("addMany-multiple-files", function () {

expect(
multipleAddsResult.changes[0].path.includes(
`${expectedFiles.length} files added`
)
`${expectedFiles.length} files added`,
),
).toBe(true);
});

Expand All @@ -52,8 +52,8 @@ describe("addMany-multiple-files", function () {

expect(
multipleAddsResult.changes[0].path.includes(
`${expectedFiles.length} files added`
)
`${expectedFiles.length} files added`,
),
).toBe(true);
});

Expand Down Expand Up @@ -90,7 +90,7 @@ describe("addMany-multiple-files", function () {
test("Test the content of the rendered file in nested folder", () => {
const filePath = path.resolve(
testSrcPath,
"john-doe/nested-folder/a-nested-add.txt"
"john-doe/nested-folder/a-nested-add.txt",
);
const content = fs.readFileSync(filePath).toString();

Expand Down Expand Up @@ -132,8 +132,8 @@ describe("addMany-multiple-files", function () {
});
expect(
multipleAddsResult.changes[4].path.includes(
`${expectedFiles.length} files added`
)
`${expectedFiles.length} files added`,
),
).toBe(true);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe("addMany-non-verbose", function () {

// has the summary line
expect(multipleAddsResult.changes[0].path.includes("5 files added")).toBe(
true
true,
);
// does not have additional lines
expect(multipleAddsResult.changes[0].path.includes("\n")).toBe(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ describe("addMany-strip-extensions", function () {
test("Check that all files generated without hbs extension", () => {
const nonSpecPath = path.resolve(
testSrcPath,
"remove-hbs/john-doe-my-view.js"
"remove-hbs/john-doe-my-view.js",
);
const specPath = path.resolve(
testSrcPath,
"remove-hbs/john-doe-my-view._test.js"
"remove-hbs/john-doe-my-view._test.js",
);

expect(fs.existsSync(nonSpecPath)).toBe(true);
Expand All @@ -38,13 +38,10 @@ describe("addMany-strip-extensions", function () {
});

test("Check that dot files generated without hbs extension", () => {
const dotPath = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.gitignore"
);
const dotPath = path.resolve(testSrcPath, "remove-dotfile-hbs/.gitignore");
const dotPathWithExtension = path.resolve(
testSrcPath,
"remove-dotfile-hbs/.eslintrc.cjs"
"remove-dotfile-hbs/.eslintrc.cjs",
);

expect(fs.existsSync(dotPath)).toBe(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ describe("basic-plopfile", function () {
expect(content.includes("test: basic-plopfile-test")).toBe(true);
expect(
content.includes(
"propertyPathTest: basic-plopfile-test-propertyPath-value-index-1"
)
"propertyPathTest: basic-plopfile-test-propertyPath-value-index-1",
),
).toBe(true);
});

Expand All @@ -54,7 +54,7 @@ describe("basic-plopfile", function () {

expect(content.includes("this is a test: 21")).toBe(true);
expect(
content.includes("this is prepended! replaced => this-is-a-test: 21")
content.includes("this is prepended! replaced => this-is-a-test: 21"),
).toBe(true);
});
});
Loading

0 comments on commit 3026d78

Please sign in to comment.