Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configurable base path for build command for hosting as GitLab pages #41

Closed
JohannesKonings opened this issue Apr 11, 2024 · 0 comments · Fixed by #40
Closed

configurable base path for build command for hosting as GitLab pages #41

JohannesKonings opened this issue Apr 11, 2024 · 0 comments · Fixed by #40

Comments

@JohannesKonings
Copy link
Sponsor

Hi,

with #33 a configurable basePath for the static build was requested.
Unfortunately it doesn't work if the inspecor is not deployed at the root level.
With the following script it works then for a non root path (in that case eslint):

import { readFileSync, readdirSync, statSync, writeFileSync } from 'fs';
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';

// @ts-ignore
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const rootPath = __dirname.split('src')[0];

const indexHtmlPath = `${rootPath}.eslint-config-inspector/index.html`;
const indexHtmlString = readFileSync(indexHtmlPath, 'utf8');
const faviconReplaced = indexHtmlString.replace(
  /\/favicon.svg/g,
  './favicon.svg',
);
const nuxtHrefReplaced = faviconReplaced.replace(
  /href="\/_nuxt\//g,
  'href="/eslint/_nuxt/',
);
const nuxtSrcReplaced = nuxtHrefReplaced.replace(
  /src="\/_nuxt\//g,
  'src="/eslint/_nuxt/',
);

const baseReplaced = nuxtSrcReplaced.replace(
  /baseURL:"\//g,
  'baseURL:"/eslint/',
);

writeFileSync(indexHtmlPath, baseReplaced);

const getAllFiles = (dirPath: string, arrayOfFiles: string[] = []) => {
  const files = readdirSync(dirPath);

  files.forEach((file) => {
    if (statSync(join(dirPath, file)).isDirectory()) {
      arrayOfFiles = getAllFiles(join(dirPath, file), arrayOfFiles);
    } else {
      arrayOfFiles.push(join(dirPath, file));
    }
  });

  return arrayOfFiles;
};

const allFiles = getAllFiles(`${rootPath}.eslint-config-inspector`);

const searchAndReplace = (file: string) => {
  const fileString = readFileSync(file, 'utf8');
  const replaced = fileString.replace(
    /\/api\/payload.json/g,
    '/eslint/api/payload.json',
  );
  writeFileSync(file, replaced);
};
for (const file of allFiles) {
  searchAndReplace(file);
}

Is there a way to configre that via a cli parameter?

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant