Skip to content

Commit 43fe390

Browse files
committed
Small fixes in tools for cwd
1 parent 5d16a10 commit 43fe390

File tree

3 files changed

+27
-23
lines changed

3 files changed

+27
-23
lines changed

tools/builder/prepare-gh-pages.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const execute = utils.promisify(exec);
77
const archiver = require("archiver");
88
const fg = require('fast-glob');
99

10+
const cwd = process.cwd();
11+
1012
function zipDirectory(sourceDir, outPath) {
1113
const archive = archiver('zip', { zlib: { level: 9 }});
1214
const stream = createWriteStream(outPath);
@@ -28,24 +30,24 @@ function zipDirectory(sourceDir, outPath) {
2830

2931
(async function() {
3032

31-
let steps = readdirSync(join(process.cwd(), "steps"));
33+
let steps = readdirSync(join(cwd, "steps"));
3234
// only consider directories
33-
steps = steps.filter((step) => statSync(join(process.cwd(), "steps", step)).isDirectory());
35+
steps = steps.filter((step) => statSync(join(cwd, "steps", step)).isDirectory());
3436

35-
if (existsSync(join(process.cwd(), "dist"))) {
36-
rmSync(join(process.cwd(), "dist"), { recursive: true });
37+
if (existsSync(join(cwd, "dist"))) {
38+
rmSync(join(cwd, "dist"), { recursive: true });
3739
}
3840

39-
mkdirSync(join(process.cwd(), "dist"), { recursive: true });
40-
mkdirSync(join(process.cwd(), "dist/build"), { recursive: true });
41+
mkdirSync(join(cwd, "dist"), { recursive: true });
42+
mkdirSync(join(cwd, "dist/build"), { recursive: true });
4143

4244
await Promise.all(steps.map((step) => {
43-
return zipDirectory(join(process.cwd(), "steps", step), join(process.cwd(), "dist", `ui5-typescript-walkthrough-step-${step}.zip`))
45+
return zipDirectory(join(cwd, "steps", step), join(cwd, "dist", `ui5-typescript-walkthrough-step-${step}.zip`))
4446
}));
4547
for (const step of steps) {
46-
console.log(`npx ui5 build --dest ${join(process.cwd(), "dist", "build", `${step}`)}`);
47-
await execute(`npx ui5 build --dest ${join(process.cwd(), "dist", "build", `${step}`)}`, {
48-
cwd: join(process.cwd(), "steps", step)
48+
console.log(`npx ui5 build --dest ${join(cwd, "dist", "build", `${step}`)}`);
49+
await execute(`npx ui5 build --dest ${join(cwd, "dist", "build", `${step}`)}`, {
50+
cwd: join(cwd, "steps", step)
4951
});
5052
}
5153

@@ -57,20 +59,20 @@ function zipDirectory(sourceDir, outPath) {
5759
writeFileSync(file, content, { encoding: "utf8" });
5860
}
5961

60-
copyFileSync(join(process.cwd(), "README.md"), join(process.cwd(), "dist/index.md"));
61-
rewriteLinks(join(process.cwd(), "dist/index.md"));
62-
const readmes = fg.globSync(["steps/**/README.md"]);
62+
copyFileSync(join(cwd, "README.md"), join(cwd, "dist/index.md"));
63+
rewriteLinks(join(cwd, "dist/index.md"));
64+
const readmes = fg.globSync(["steps/**/README.md"], { cwd });
6365
readmes.forEach((readme) => {
6466
const [, path, step] = readme.match("steps/((.*)/README.md)");
65-
mkdirSync(join(process.cwd(), `dist/build/${step}`), { recursive: true });
66-
copyFileSync(join(process.cwd(), readme), join(process.cwd(), `dist/build/${path}`));
67-
rewriteLinks(join(process.cwd(), `dist/build/${path}`), `${path}`);
67+
mkdirSync(join(cwd, `dist/build/${step}`), { recursive: true });
68+
copyFileSync(join(cwd, readme), join(cwd, `dist/build/${path}`));
69+
rewriteLinks(join(cwd, `dist/build/${path}`), `${path}`);
6870
});
6971

7072
await Promise.all(steps.map((step) => {
71-
const jsStepBaseDir = join(process.cwd(), "steps", step);
72-
const buildOutputDir = join(process.cwd(), "dist", "build", `${step}`);
73-
const targetDir = join(process.cwd(), "dist", "steps", `${step}`);
73+
const jsStepBaseDir = join(cwd, "steps", step);
74+
const buildOutputDir = join(cwd, "dist", "build", `${step}`);
75+
const targetDir = join(cwd, "dist", "steps", `${step}`);
7476

7577
// copy all files from buildOutputDir to targetDir except of TS files
7678
const files = fg.sync(["**/*"], { cwd: jsStepBaseDir, dot: true });
@@ -106,7 +108,7 @@ function zipDirectory(sourceDir, outPath) {
106108
});
107109

108110
console.log(`${jsStepBaseDir} -> ${buildOutputDir}`);
109-
return zipDirectory(join(process.cwd(), "dist", "steps", `${step}`), join(process.cwd(), "dist", `ui5-typescript-walkthrough-step-${step}-js.zip`))
111+
return zipDirectory(join(cwd, "dist", "steps", `${step}`), join(cwd, "dist", `ui5-typescript-walkthrough-step-${step}-js.zip`))
110112
}));
111113

112114
}());

tools/dev-server/server.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ async function convertMarkdown(md) {
3232
}
3333

3434
async function getTemplate() {
35-
const headContent = readFileSync(`_includes/head-custom.html`, { encoding: "utf-8" });
36-
let template = readFileSync("tools/dev-server/ghpage-template.hbs", { encoding: "utf-8" });
35+
const headContent = readFileSync(join(cwd, "_includes/head-custom.html"), { encoding: "utf-8" });
36+
let template = readFileSync(join(__dirname, "ghpage-template.hbs"), { encoding: "utf-8" });
3737
template = template.replace("%headContent%", headContent);
3838
template = template.replace(/\{\{ '([^']+)' \| relative_url \}\}/g, "/$1");
3939
const templateFn = handlebars.compile(template);

tools/utils/download-assets.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ const fs = require('fs');
22
const path = require('path');
33
const axios = require('axios');
44

5+
const cwd = process.cwd();
6+
57
const findMarkdownFiles = (dir) => {
68
let results = [];
79
const files = fs.readdirSync(dir, { withFileTypes: true });
@@ -17,7 +19,7 @@ const findMarkdownFiles = (dir) => {
1719
return results;
1820
};
1921

20-
const markdownFiles = [path.join(process.cwd(), "README.md"), findMarkdownFiles(path.join(process.cwd(), 'steps'))].flat();
22+
const markdownFiles = [path.join(cwd, "README.md"), findMarkdownFiles(path.join(cwd, 'steps'))].flat();
2123

2224
const downloadImage = async (url, outputPath) => {
2325
const response = await axios({

0 commit comments

Comments
 (0)