Skip to content
Snippets Groups Projects
Select Git revision
  • 5f09f0bb14908df4bdb0d800f86dffba89aa890e
  • main default protected
  • renovate/lock-file-maintenance
  • demo protected
  • person-select-custom
  • dbp-translation-component
  • icon-set-mapping
  • port-i18next-parser
  • remove-sentry
  • favorites-and-recent-files
  • revert-6c632dc6
  • lit2
  • advertisement
  • wc-part
  • automagic
  • publish
  • wip-cleanup
  • demo-file-handling
18 results

rollup.utils.js

  • Christoph Reiter's avatar
    Reiter, Christoph authored
    Takes a package name and a dest path. This way we can more eassily change the
    layout and it will error out on package name typos or missing packages.
    f2dd39fe
    History
    rollup.utils.js 1.47 KiB
    import path from 'path';
    import url from 'url';
    import child_process from 'child_process';
    import resolve from '@rollup/plugin-node-resolve';
    
    export function getBuildInfo(build) {
        let remote = child_process.execSync('git config --get remote.origin.url').toString().trim();
        let commit = child_process.execSync('git rev-parse --short HEAD').toString().trim();
    
        let parsed = url.parse(remote);
        let newPath = parsed.path.slice(0, parsed.path.lastIndexOf('.'));
        let newUrl = parsed.protocol + '//' + parsed.host + newPath + '/commit/' + commit;
    
        return {
            info: commit,
            url: newUrl,
            time: new Date().toISOString(),
            env: build
        }
    }
    
    export async function getDistPath(packageName, assetPath) {
        if (assetPath === undefined)
            assetPath = '';
        // make sure the package exists to avoid typos
        await getPackagePath(packageName, '');
        return path.join('local', packageName, assetPath);
    }
    
    export async function getPackagePath(packageName, assetPath) {
        const r = resolve();
        const resolved = await r.resolveId(packageName);
        let packageRoot;
        if (resolved !== null) {
            const id = (await r.resolveId(packageName)).id;
            const packageInfo = r.getPackageInfoForId(id);
            packageRoot = packageInfo.root;
        } else {
            // Non JS packages
            packageRoot = path.dirname(require.resolve(packageName + '/package.json'));
        }
        return path.relative(process.cwd(), path.join(packageRoot, assetPath));
    }