Skip to content

Commit 0ab8ded

Browse files
committed
fix: Normalize line endings
1 parent 5ec6a29 commit 0ab8ded

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

packages/demo/scripts/stage.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const PATHS = {
1313
cname: BUILD_DIR + "/CNAME",
1414
};
1515

16+
function normalizeLineEndings(text: string) {
17+
return text.replace(/\r\n/g, "\n");
18+
}
19+
1620
function generateSitemapXml() {
1721
const date = new Date();
1822
const lastModified = `${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}`;
@@ -43,16 +47,16 @@ function generateSitemapXml() {
4347
${pages.join("")}
4448
</urlset>`;
4549

46-
return sitemap.trim();
50+
return normalizeLineEndings(sitemap.trim());
4751
}
4852

4953
function generateRobotsTxt() {
5054
const sitemapUrl = BASE_URL + PATHS.sitemapXml.replace(BUILD_DIR + "/", "");
5155

52-
return `# https://www.robotstxt.org/robotstxt.html
56+
return normalizeLineEndings(`# https://www.robotstxt.org/robotstxt.html
5357
User-agent: *
5458
Disallow:
55-
Sitemap: ${sitemapUrl}`;
59+
Sitemap: ${sitemapUrl}`);
5660
}
5761

5862
function generateCname() {
@@ -73,7 +77,7 @@ function generateTemplate(html: string) {
7377
fs.writeFileSync(path, html, { flag: "w+" });
7478
console.log(`- ${ANSI.fg.cyan}${path}${ANSI.reset}`);
7579

76-
return html;
80+
return normalizeLineEndings(html);
7781
}
7882

7983
/**
@@ -125,13 +129,13 @@ function stage() {
125129
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
126130
console.log(`${ANSI.fg.yellow}Staging build...${ANSI.reset}`);
127131

128-
const files: [string, () => string][] = [
132+
const metaFiles: [string, () => string][] = [
129133
[PATHS.sitemapXml, generateSitemapXml],
130134
[PATHS.robotsTxt, generateRobotsTxt],
131135
[PATHS.cname, generateCname],
132136
];
133137

134-
files.forEach(([path, generateContent]) => {
138+
metaFiles.forEach(([path, generateContent]) => {
135139
const directory = path.substring(0, path.lastIndexOf("/"));
136140
if (directory != "" && !fs.existsSync(directory))
137141
fs.mkdirSync(directory, { recursive: true });

scripts/publishSite.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function publishSite() {
1414

1515
void ghpages.publish(path.resolve(__dirname, "../", BUILD_DIR), {
1616
repo: REPO_URL,
17-
message: COMMIT_MESSAGE
17+
message: COMMIT_MESSAGE,
18+
dotfiles: true
1819
}, (error) => {
1920
if (error == null)
2021
return;

scripts/stageSite.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ function stageSite() {
1616
console.log(`Context: ${ANSI.decoration.bold}${name}${ANSI.reset}\n`);
1717
console.log(`${ANSI.fg.yellow}Staging site...${ANSI.reset}`);
1818

19+
// Copy packages to build directory
1920
PACKAGES.forEach(({ source, path }) => {
2021
const sourceDirectory = resolve(__dirname, source);
2122
const targetDirectory = resolve(__dirname, TARGET, path.replace(/^\//, ""));
@@ -26,6 +27,13 @@ function stageSite() {
2627
fs.cpSync(sourceDirectory, targetDirectory, { recursive: true });
2728
console.log(`- Copied ${ANSI.fg.cyan + source.replace(/^\.\.\//, "") + ANSI.reset} to ${ANSI.fg.cyan + path + ANSI.reset}`);
2829
});
30+
31+
// Copy git attributes to build directory
32+
const gitAttributesDirectory = resolve(__dirname, "../.gitattributes");
33+
if (fs.existsSync(gitAttributesDirectory)) {
34+
fs.copyFileSync(gitAttributesDirectory, resolve(__dirname, `../${BUILD_DIR}/.gitattributes`));
35+
console.log(`- Copied ${ANSI.fg.cyan + ".gitattributes" + ANSI.reset}`);
36+
}
2937

3038
console.log(`\n${ANSI.fg.green}✓ Site staged: ${ANSI.fg.cyan}./${BUILD_DIR + ANSI.reset}`);
3139
} catch (error) {

0 commit comments

Comments
 (0)