Skip to content

Commit

Permalink
refactor: further updates
Browse files Browse the repository at this point in the history
  • Loading branch information
damienbutt committed Feb 12, 2024
1 parent 69544b5 commit 7ce9b96
Show file tree
Hide file tree
Showing 8 changed files with 2,189 additions and 494 deletions.
103 changes: 42 additions & 61 deletions tests/c.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { NodeEnvironment } from "../src/environments/index.js";
import { ConfigHelper } from "../src/helpers/index.js";
import config from "../config/default.json";
import { UnresolvedConfig, NodePackageManager } from "../src/@types/index.js";
import { getNodeDependencyObject } from "./helpers.js";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const generator = path.resolve(__dirname, "../dist/generators/app");
Expand All @@ -17,9 +18,23 @@ await ConfigHelper.initialize(config as UnresolvedConfig);
const node = new NodeEnvironment();
await node.initialize();

const { devDependencies } = node.packageJson;
const engine = node.getNodeEngine().split(".")[0];

const devDependencies = [
"@commitlint/cli",
"@commitlint/config-conventional",
"@semantic-release/changelog",
"@semantic-release/git",
"all-contributors-cli",
"commitizen",
"cz-conventional-changelog",
"doctoc",
"husky",
"lint-staged",
"prettier",
"semantic-release",
];

const files = [
".github/workflows/main.yml",
".github/dependabot.yml",
Expand Down Expand Up @@ -140,26 +155,13 @@ describe("generator-norgate-av:c", () => {
engines: {
node: `>=${engine}`,
},
devDependencies: {
"@commitlint/cli": devDependencies!["@commitlint/cli"],
"@commitlint/config-conventional":
devDependencies!["@commitlint/config-conventional"],
"@semantic-release/changelog":
devDependencies!["@semantic-release/changelog"],
"@semantic-release/git":
devDependencies!["@semantic-release/git"],
"all-contributors-cli":
devDependencies!["all-contributors-cli"],
commitizen: devDependencies!.commitizen,
"cz-conventional-changelog":
devDependencies!["cz-conventional-changelog"],
doctoc: devDependencies!.doctoc,
husky: devDependencies!.husky,
"lint-staged": devDependencies!["lint-staged"],
prettier: devDependencies!.prettier,
"semantic-release":
devDependencies!["semantic-release"],
},
devDependencies: getNodeDependencyObject(
devDependencies,
node.packageJson.devDependencies as Record<
string,
string
>,
),
});
});

Expand Down Expand Up @@ -334,26 +336,13 @@ describe("generator-norgate-av:c", () => {
engines: {
node: `>=${engine}`,
},
devDependencies: {
"@commitlint/cli": devDependencies!["@commitlint/cli"],
"@commitlint/config-conventional":
devDependencies!["@commitlint/config-conventional"],
"@semantic-release/changelog":
devDependencies!["@semantic-release/changelog"],
"@semantic-release/git":
devDependencies!["@semantic-release/git"],
"all-contributors-cli":
devDependencies!["all-contributors-cli"],
commitizen: devDependencies!.commitizen,
"cz-conventional-changelog":
devDependencies!["cz-conventional-changelog"],
doctoc: devDependencies!.doctoc,
husky: devDependencies!.husky,
"lint-staged": devDependencies!["lint-staged"],
prettier: devDependencies!.prettier,
"semantic-release":
devDependencies!["semantic-release"],
},
devDependencies: getNodeDependencyObject(
devDependencies,
node.packageJson.devDependencies as Record<
string,
string
>,
),
});
});

Expand Down Expand Up @@ -444,6 +433,11 @@ describe("generator-norgate-av:c", () => {
type: "c",
yes: true,
},
{
destination: "Test Project",
type: "clang",
yes: true,
},
])(
"cli: using all defaults, skipping prompts",
({ destination, type, yes }) => {
Expand Down Expand Up @@ -495,26 +489,13 @@ describe("generator-norgate-av:c", () => {
engines: {
node: `>=${engine}`,
},
devDependencies: {
"@commitlint/cli": devDependencies!["@commitlint/cli"],
"@commitlint/config-conventional":
devDependencies!["@commitlint/config-conventional"],
"@semantic-release/changelog":
devDependencies!["@semantic-release/changelog"],
"@semantic-release/git":
devDependencies!["@semantic-release/git"],
"all-contributors-cli":
devDependencies!["all-contributors-cli"],
commitizen: devDependencies!.commitizen,
"cz-conventional-changelog":
devDependencies!["cz-conventional-changelog"],
doctoc: devDependencies!.doctoc,
husky: devDependencies!.husky,
"lint-staged": devDependencies!["lint-staged"],
prettier: devDependencies!.prettier,
"semantic-release":
devDependencies!["semantic-release"],
},
devDependencies: getNodeDependencyObject(
devDependencies,
node.packageJson.devDependencies as Record<
string,
string
>,
),
});
});

Expand Down
17 changes: 17 additions & 0 deletions tests/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export function getNodeDependencyObject(
dependencies: Array<string>,
store: Record<string, string>,
): Record<string, string> {
return dependencies.reduce<Record<string, string>>((dependencies, key) => {
const value = store[key];

if (value === undefined) {
return dependencies;
}

return {
...dependencies,
[key]: value,
};
}, {});
}
Loading

0 comments on commit 7ce9b96

Please sign in to comment.