@platform/react.ssr
Version:
A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.
19 lines (18 loc) • 732 B
JavaScript
import { fs, semver } from '../common';
export function dir(parentDir) {
const api = {
async latest() {
const dirs = await api.semver();
return dirs[dirs.length - 1];
},
async semver(options = {}) {
const { sort = 'ASC' } = options;
parentDir = fs.resolve(parentDir);
const paths = await fs.glob.find(fs.join(parentDir, '*/'), { includeDirs: true });
const names = paths.map(path => fs.basename(path)).filter(name => semver.valid(name));
const ascending = semver.sort(names).map(name => fs.join(parentDir, name));
return sort === 'DESC' ? ascending.reverse() : ascending;
},
};
return api;
}