@platform/react.ssr
Version:
A lightweight SSR (server-side-rendering) system for react apps bundled with ParcelJS and hosted on S3.
31 lines (27 loc) • 904 B
text/typescript
import { fs, semver } from '../common';
/**
* Retrieves the last directory from within the given path.
*/
export function dir(parentDir: string) {
const api = {
/**
* Retrieves the latest semver directory.
*/
async latest() {
const dirs = await api.semver();
return dirs[dirs.length - 1];
},
/**
* Retrievs child directories that are semvers.
*/
async semver(options: { sort?: 'ASC' | 'DESC' } = {}) {
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;
}