Skip to content

Commit 9d4476d

Browse files
committed
refactored the repo to make 'npm create harmonia' possible
1 parent f35767b commit 9d4476d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+31322
-187
lines changed

.husky/pre-commit

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,4 @@
11
#!/bin/sh
22
. "$(dirname "$0")/_/husky.sh"
33

4-
fileList=$(git diff --staged --name-only :^package-lock.json :^README.md :^client :^server)
5-
6-
echo '----- Checking Root...'
7-
8-
if [ ! -z "$fileList" ]
9-
then
10-
echo "error: Unauthorized modifications\n"
11-
12-
echo "$fileList\n"
13-
14-
echo "use 'git restore --staged ...' to fix the problem"
15-
echo "(and ask your instructor why you should not change these files)\n"
16-
17-
exit 1
18-
fi
19-
20-
echo '----- Done!'
21-
22-
npx validate-branch-name
234
npm run lint

.tours/01-get-started.tour

Lines changed: 0 additions & 32 deletions
This file was deleted.

.tours/02-frontend.tour

Lines changed: 0 additions & 42 deletions
This file was deleted.

.tours/03-backend.tour

Lines changed: 0 additions & 62 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ tables.foo.callSomeCrudMethod();
190190

191191
### Added
192192

193-
- Git commands for Windows users, to fix issues with different newline formats (see [README.md](README.md#windows-users)).
193+
- Git commands for Windows users, to fix issues with different newline formats (see [README.md](template/README.md#windows-users)).
194194

195195
### Changed
196196

CONTRIBUTING.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
- **Do not open up a GitHub issue if the bug is a security vulnerability**, and instead send an email to [email protected].
66

7-
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/wildcodeschool/our-resql/issues).
7+
- **Ensure the bug was not already reported** by searching on GitHub under [Issues](https://github.com/wildcodeschool/create-harmonia/issues).
88

9-
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/wildcodeschool/our-resql/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
9+
- If you're unable to find an open issue addressing the problem, [open a new one](https://github.com/wildcodeschool/create-harmonia/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
1010

1111
#### **Did you write a patch that fixes a bug?**
1212

@@ -20,9 +20,9 @@ Changes that are cosmetic in nature and do not add anything substantial to the s
2020

2121
#### **Do you intend to add a new feature or change an existing one?**
2222

23-
- **Ensure the change was not already proposed** by searching on GitHub under [Issues](https://github.com/wildcodeschool/our-resql/issues).
23+
- **Ensure the change was not already proposed** by searching on GitHub under [Issues](https://github.com/wildcodeschool/create-harmonia/issues).
2424

25-
- If you're unable to find an appropriate open issue, [open a new one](https://github.com/wildcodeschool/our-resql/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
25+
- If you're unable to find an appropriate open issue, [open a new one](https://github.com/wildcodeschool/create-harmonia/issues/new). Be sure to include a **title and clear description**, as much relevant information as possible, and a **code sample** or an **executable test case** demonstrating the expected behavior that is not occurring.
2626

2727
- Do not start writing code until you have collected positive feedback on the issue 🙂
2828

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## Concept
1+
# Harmonia
22

3-
This framework is meant to serve as a foundation for every project following the React-Express-MySQL stack, as learned in Wild Code School.
3+
Harmonia is a framework meant to serve as a foundation for every project following the React-Express-MySQL stack, as learned in Wild Code School.
44
It's pre-configured with a set of tools which'll help students produce industry-quality and easier-to-maintain code, while staying a pedagogical tool.
55

66
## Setup & Use

bin/create-harmonia.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#!/usr/bin/env node
2+
import fs from "node:fs";
3+
import path from "node:path";
4+
5+
import * as p from "@clack/prompts";
6+
import { bold, cyan, grey } from "kleur/colors";
7+
import Mustache from "mustache";
8+
import { execSync } from "node:child_process";
9+
10+
const { version } = JSON.parse(
11+
fs.readFileSync(new URL("../package.json", import.meta.url), "utf-8")
12+
);
13+
14+
console.log(`
15+
${grey(`create-harmonia version ${version}`)}
16+
`);
17+
18+
let [org, name] = process.argv[2].split("/") ?? [];
19+
20+
if (name == null) {
21+
name = org;
22+
org = null;
23+
}
24+
25+
if (org == null) {
26+
org = await p.text({
27+
message: "What is your organization name?",
28+
placeholder: " (hit Enter to use empty string)",
29+
});
30+
31+
if (p.isCancel(org)) process.exit(1);
32+
33+
if (org == null) {
34+
org = /** @type {string} */ ("");
35+
}
36+
}
37+
38+
p.intro("Welcome to Harmonia!");
39+
40+
if (name === ".") {
41+
const dir = await p.text({
42+
message: "Where should we create your project?",
43+
placeholder: " (hit Enter to use current directory)",
44+
});
45+
46+
if (p.isCancel(dir)) process.exit(1);
47+
48+
if (dir) {
49+
name = /** @type {string} */ (dir);
50+
}
51+
}
52+
53+
if (fs.existsSync(name)) {
54+
if (fs.readdirSync(name).length > 0) {
55+
const force = await p.confirm({
56+
message: "Directory not empty. Continue?",
57+
initialValue: false,
58+
});
59+
60+
// bail if `force` is `false` or the user cancelled with Ctrl-C
61+
if (force !== true) {
62+
process.exit(1);
63+
}
64+
}
65+
}
66+
67+
const destDir = path.resolve(process.cwd(), name);
68+
69+
const sCp = p.spinner();
70+
71+
sCp.start("Copying files");
72+
73+
fs.cpSync(new URL("../template", import.meta.url), destDir, {
74+
recursive: true,
75+
});
76+
77+
sCp.stop("Copied files");
78+
79+
const sMustache = p.spinner();
80+
81+
sMustache.start("Filling templates");
82+
83+
const data = { name, org, year: new Date().getFullYear() };
84+
85+
fs.writeFileSync(
86+
`${destDir}/package.json`,
87+
Mustache.render(
88+
fs.readFileSync(`${destDir}/package.template.json`, "utf8"),
89+
data
90+
)
91+
);
92+
fs.rmSync(`${destDir}/package.template.json`);
93+
94+
fs.writeFileSync(
95+
`${destDir}/package-lock.json`,
96+
Mustache.render(
97+
fs.readFileSync(`${destDir}/package-lock.template.json`, "utf8"),
98+
data
99+
)
100+
);
101+
fs.rmSync(`${destDir}/package-lock.template.json`);
102+
103+
fs.writeFileSync(
104+
`${destDir}/LICENSE.md`,
105+
Mustache.render(
106+
fs.readFileSync(`${destDir}/LICENSE.template.md`, "utf8"),
107+
data
108+
)
109+
);
110+
fs.rmSync(`${destDir}/LICENSE.template.md`);
111+
112+
sMustache.stop("Filled templates");
113+
114+
const sGit = p.spinner();
115+
116+
sGit.start("Starting git");
117+
118+
execSync(
119+
`cd ${destDir} && git init && git add -A && git commit -m "Initial commit" -n`
120+
);
121+
122+
sGit.stop("Started git");
123+
124+
p.outro("Your project is ready!");
125+
126+
console.log("\nNext steps:");
127+
let i = 1;
128+
129+
const relative = path.relative(process.cwd(), name);
130+
131+
if (relative !== "") {
132+
console.log(` ${i++}: ${bold(cyan(`cd ${relative}`))}`);
133+
}
134+
135+
console.log(` ${i++}: ${bold(cyan(`npm install`))}`);
136+
console.log(
137+
` ${i++}: ${bold(cyan(`cp client/.env.sample client/.env && nano client/.env`))}`
138+
);
139+
console.log(
140+
` ${i++}: ${bold(cyan(`cp server/.env.sample server/.env && nano server/.env`))}`
141+
);
142+
console.log(` ${i++}: ${bold(cyan(`npm run dev`))}`);
143+
144+
console.log(`\nTo stop the run, hit ${bold(cyan("Ctrl-C"))}`);
145+
console.log(
146+
`\nStuck? Visit us at ${cyan("https://documentation-harmonia.vercel.app/")}`
147+
);

0 commit comments

Comments
 (0)