Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active April 10, 2018 21:35
Show Gist options
  • Save rauschma/0bdd83ed9776624f777b99d36944cb2b to your computer and use it in GitHub Desktop.
Save rauschma/0bdd83ed9776624f777b99d36944cb2b to your computer and use it in GitHub Desktop.
/*:::::::::: copySync(src, dest, [options]) ::::::::::*/
/* https://github.com/jprichardson/node-fs-extra/blob/master/docs/copy-sync.md */
let optBoolToJS = (optBool: option(bool)) =>
switch (optBool) {
| None => None
| Some(b) => Some(Js.Boolean.to_js_boolean(b));
};
type copyOpts;
[@bs.obj] external makeCopyOpts : (~overwrite: Js.boolean=?, ~errorOnExist: Js.boolean=?, ~dereference: Js.boolean=?, ~preserveTimestamps: Js.boolean=?, ~filter: (string=>Js.boolean)=?, unit) => copyOpts = "";
[@bs.module "fs-extra"] external copySyncExternal : (string, string, copyOpts) => unit = "copySync";
let copySync = (~overwrite:option(bool)=?, ~errorOnExist:option(bool)=?, ~dereference:option(bool)=?, ~preserveTimestamps:option(bool)=?, ~filter:option(string => bool)=?,
src: string, dest: string) => {
let filterJs: option(string=>Js.boolean) =
switch (filter) {
| None => None
| Some(f) =>
Some((str) => Js.Boolean.to_js_boolean(f(str)));
};
copySyncExternal(src, dest,
makeCopyOpts(
~overwrite=?optBoolToJS(overwrite),
~errorOnExist=?optBoolToJS(errorOnExist),
~dereference=?optBoolToJS(dereference),
~preserveTimestamps=?optBoolToJS(preserveTimestamps),
~filter=?filterJs, ())
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment