Skip to content

Commit ea66fdd

Browse files
committed
Refactor askQuestion function to set default project name and improve prompt message
1 parent 17a1b3b commit ea66fdd

File tree

3 files changed

+90
-123
lines changed

3 files changed

+90
-123
lines changed

.tkb

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,6 @@
11
{
22
"scope": "Workspace",
33
"tasks": {
4-
"G-1H47JpSI69kav1qZ-kp": {
5-
"id": "G-1H47JpSI69kav1qZ-kp",
6-
"description": "Star [this repository](https://github.com/react18-tools/turborepo-template/) for easy access and to show your support",
7-
"columnId": "column-todo"
8-
},
9-
"gbzyhx0FwFfzRoE-iqVeu": {
10-
"id": "gbzyhx0FwFfzRoE-iqVeu",
11-
"description": "run `yarn rebrand` to rebrand and clean up the repo; the `rebrand` script will automatically rebrand the repo, adjust workflows, and create a commit",
12-
"columnId": "column-todo"
13-
},
14-
"Y5__aEZl3Pbxp7r90HKpV": {
15-
"id": "Y5__aEZl3Pbxp7r90HKpV",
16-
"description": "Install `pnpm` using `npm i -g pnpm`",
17-
"columnId": "column-todo"
18-
},
19-
"jcpymbi71e702p7n6fwvZ": {
20-
"id": "jcpymbi71e702p7n6fwvZ",
21-
"description": "Install dependencies using `pnpm`: run `pnpm i`.",
22-
"columnId": "column-todo"
23-
},
24-
"jdZxwLymOo7w2eZeNpvsN": {
25-
"id": "jdZxwLymOo7w2eZeNpvsN",
26-
"description": "Run `yarn plop`, and follow prompts to generate server or client components for your library",
27-
"columnId": "column-todo"
28-
},
29-
"RX4J5v4y5IOe_ucf8pMRT": {
30-
"id": "RX4J5v4y5IOe_ucf8pMRT",
31-
"description": "🌟 Enable [private vulnerability reporting](https://github.com/react18-tools/create-r18-turborepo/security) (For public repo - do this after updating visibility to public)",
32-
"columnId": "column-todo"
33-
},
34-
"EdPbrbJLllUHfZmCS80f7": {
35-
"id": "EdPbrbJLllUHfZmCS80f7",
36-
"description": "Set up `CodeCov`\n - Visit Codecov and set up your repo\n - Create [repository secret]((https://github.com/react18-tools/create-r18-turborepo/settings/secrets/actions)) for `CODECOV_TOKEN`",
37-
"columnId": "column-todo"
38-
},
394
"MLLUsAhCKaKxvEXFY0HSq": {
405
"id": "MLLUsAhCKaKxvEXFY0HSq",
416
"description": "Set up `CodeClimate`\n - Visit CodeClimate and set up your repo\n - Create [repository secret] for `CC_TEST_REPORTER_ID`\n - Add `*.test.*` to ignore patterns on the website\n - Update Code Climate badge",
@@ -117,13 +82,6 @@
11782
"id": "column-todo",
11883
"title": "To do",
11984
"tasksIds": [
120-
"G-1H47JpSI69kav1qZ-kp",
121-
"Y5__aEZl3Pbxp7r90HKpV",
122-
"jcpymbi71e702p7n6fwvZ",
123-
"gbzyhx0FwFfzRoE-iqVeu",
124-
"jdZxwLymOo7w2eZeNpvsN",
125-
"RX4J5v4y5IOe_ucf8pMRT",
126-
"EdPbrbJLllUHfZmCS80f7",
12785
"MLLUsAhCKaKxvEXFY0HSq",
12886
"gMYfaAh2RABMP8uZRQgNx",
12987
"_BfuX7quWBANpDK1bI7YM",
@@ -153,4 +111,4 @@
153111
]
154112
}
155113
]
156-
}
114+
}

lib/src/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,20 @@ export const askQuestion = (query: string): Promise<string> => {
2525
input: process.stdin,
2626
output: process.stdout,
2727
});
28-
return new Promise(resolve =>
28+
return new Promise(resolve => {
2929
rl.question(query, ans => {
3030
rl.close();
3131
resolve(ans);
32-
}),
33-
);
32+
});
33+
rl.write(DEFAULT_NAME);
34+
});
3435
};
3536

3637
const main = async (): Promise<void> => {
3738
let projectName = process.argv[2];
3839

3940
if (!projectName) {
40-
const input = await askQuestion(`Project name (default: ${DEFAULT_NAME}): `);
41+
const input = await askQuestion(`Project name: `);
4142
projectName = input.trim() || DEFAULT_NAME;
4243
}
4344

scripts/publish.js

Lines changed: 84 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,84 @@
1-
/** It is assumed that this is called only from the default branch. */
2-
const { execSync } = require("child_process");
3-
4-
const BRANCH = process.env.BRANCH;
5-
6-
// Apply changesets if any -- e.g., coming from pre-release branches
7-
try {
8-
execSync("pnpm changeset pre exit");
9-
} catch {
10-
// empty
11-
}
12-
try {
13-
execSync("pnpm changeset version");
14-
execSync(
15-
`git add . && git commit -m "Apply changesets and update CHANGELOG [skip ci]" && git push origin ${BRANCH}`,
16-
);
17-
} catch {
18-
// no changesets to be applied
19-
}
20-
21-
const { version: VERSION, name } = require("../lib/package.json");
22-
let LATEST_VERSION = "0.0.-1";
23-
24-
try {
25-
LATEST_VERSION = execSync(`npm view ${name} version`).toString().trim() ?? "0.0.-1";
26-
} catch {
27-
// empty
28-
}
29-
30-
console.log({ VERSION, LATEST_VERSION });
31-
32-
const [newMajor, newMinor] = VERSION.split(".");
33-
const [oldMajor, oldMinor] = LATEST_VERSION.split(".");
34-
35-
const isPatch = newMajor === oldMajor && newMinor === oldMinor;
36-
const releaseBranch = `release-${newMajor}.${newMinor}`;
37-
38-
if (isPatch) {
39-
// update release branch
40-
try {
41-
execSync(
42-
`git checkout ${releaseBranch} && git merge ${BRANCH} && git push origin ${releaseBranch}`,
43-
);
44-
} catch {}
45-
} else {
46-
try {
47-
require("./update-security-md")(`${newMajor}.${newMinor}`, `${oldMajor}.${oldMinor}`);
48-
/** Create new release branch for every Major or Minor release */
49-
execSync(`git checkout -b ${releaseBranch} && git push origin ${releaseBranch}`);
50-
} catch (err) {
51-
console.error("Error pushing to release branch: ", err);
52-
}
53-
}
54-
55-
const { visibility } = JSON.parse(execSync("gh repo view --json visibility").toString());
56-
const provenance = visibility.toLowerCase() === "public" ? "--provenance" : "";
57-
58-
/** Create release */
59-
execSync(`cd lib && pnpm build && npm publish ${provenance} --access public`);
60-
61-
/** Create GitHub release */
62-
try {
63-
execSync(
64-
`gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' lib/CHANGELOG.md)" --title "Release v${VERSION}"`,
65-
);
66-
} catch {
67-
execSync(`gh release create ${VERSION} --generate-notes --latest --title "Release v${VERSION}"`);
68-
}
69-
70-
try {
71-
// Publish canonical packages
72-
execSync("node scripts/publish-canonical.js");
73-
} catch {
74-
console.error("Failed to publish canonical packages");
75-
}
76-
1+
/** It is assumed that this is called only from the default branch. */
2+
const { execSync } = require("child_process");
3+
4+
const BRANCH = process.env.BRANCH;
5+
6+
// Apply changesets if any -- e.g., coming from pre-release branches
7+
try {
8+
execSync("pnpm changeset pre exit");
9+
} catch {
10+
// empty
11+
}
12+
try {
13+
execSync("pnpm changeset version");
14+
execSync(
15+
`git add . && git commit -m "Apply changesets and update CHANGELOG [skip ci]" && git push origin ${BRANCH}`,
16+
);
17+
} catch {
18+
// no changesets to be applied
19+
}
20+
21+
const { version: VERSION, name } = require("../lib/package.json");
22+
let LATEST_VERSION = "0.0.-1";
23+
24+
try {
25+
LATEST_VERSION = execSync(`npm view ${name} version`).toString().trim() ?? "0.0.-1";
26+
} catch {
27+
// empty
28+
}
29+
30+
console.log({ VERSION, LATEST_VERSION });
31+
32+
const [newMajor, newMinor] = VERSION.split(".");
33+
const [oldMajor, oldMinor] = LATEST_VERSION.split(".");
34+
35+
const isPatch = newMajor === oldMajor && newMinor === oldMinor;
36+
const releaseBranch = `release-${newMajor}.${newMinor}`;
37+
38+
if (isPatch) {
39+
// update release branch
40+
try {
41+
execSync(
42+
`git checkout ${releaseBranch} && git merge ${BRANCH} && git push origin ${releaseBranch}`,
43+
);
44+
} catch {}
45+
} else {
46+
try {
47+
require("./update-security-md")(`${newMajor}.${newMinor}`, `${oldMajor}.${oldMinor}`);
48+
/** Create new release branch for every Major or Minor release */
49+
execSync(`git checkout -b ${releaseBranch} && git push origin ${releaseBranch}`);
50+
} catch (err) {
51+
console.error("Error pushing to release branch: ", err);
52+
}
53+
}
54+
55+
const { visibility } = JSON.parse(execSync("gh repo view --json visibility").toString());
56+
const provenance = visibility.toLowerCase() === "public" ? "--provenance" : "";
57+
58+
/** Create release */
59+
execSync(`cd lib && pnpm build && npm publish ${provenance} --access public`);
60+
61+
/** Create GitHub release */
62+
try {
63+
execSync(
64+
`gh release create ${VERSION} --generate-notes --latest -n "$(sed '1,/^## /d;/^## /,$d' lib/CHANGELOG.md)" --title "Release v${VERSION}"`,
65+
);
66+
} catch {
67+
try {
68+
execSync(
69+
`gh release create ${VERSION} --generate-notes --latest --title "Release v${VERSION}"`,
70+
);
71+
} catch {
72+
// ignore
73+
}
74+
}
75+
76+
try {
77+
// Publish canonical packages
78+
execSync("node scripts/publish-canonical.js");
79+
} catch {
80+
console.error("Failed to publish canonical packages");
81+
}
82+
83+
execSync("node ./scripts/lite.js");
84+
execSync(`cd lib && pnpm build && npm publish ${provenance} --access public`);

0 commit comments

Comments
 (0)