async function addFile()

in scripts/stdlib/generate-redirects.js [101:145]


async function addFile(currentPath, name) {
    const oldPath = join(currentPath, name);
    const expectedPath = getTargetPath(currentPath, name);
    const expectedModulePath = expectedPath.split('/').slice(0, -1).join('/');

    if (await exists(expectedPath)) {
        redirects.add(oldPath, expectedPath);
        return;
    }

    /**
     * Init file was removed
     */
    if (name === '-init-.html') {
        const constructorName = expectedModulePath.split('/').pop();
        const constructorPage = `${expectedModulePath}/${constructorName}.html`;

        if (await exists(constructorPage)) {
            redirects.add(oldPath, `${expectedModulePath}/${constructorName}.html`);
            return;
        }

        const indexPath = `${expectedModulePath}/index.html`;

        if (await exists(indexPath)) {
            redirects.add(oldPath, `${expectedModulePath}/index.html`);
            return;
        }
    }

    const companionPath = `${expectedModulePath}/-companion/${name}`;

    if (await exists(companionPath)) {
        redirects.add(oldPath, companionPath);
        return;
    }

    const insideDefaultPath = `${expectedModulePath}/-default/${name}`;

    if (await exists(insideDefaultPath)) {
        redirects.add(oldPath, insideDefaultPath);
        return;
    }

    const directoryName = `${expectedModulePath}/${name.replace(/\.html$/, '')}`;