@@ -2,7 +2,7 @@ import fs from "fs";
22import path from "path" ;
33import Datastore from "nedb-promises" ;
44import chalk from "chalk" ;
5- import yaml from "js-yaml" ;
5+ import { default as YAML } from "js-yaml" ;
66import { ClassicLevel } from "classic-level" ;
77
88/* -------------------------------------------- */
@@ -214,7 +214,7 @@ async function compileNedb(pack, files, { log, transformEntry }={}) {
214214 const contents = fs . readFileSync ( file , "utf8" ) ;
215215 const ext = path . extname ( file ) ;
216216 const isYaml = ext === ".yml" || ext === ".yaml" ;
217- const doc = isYaml ? yaml . load ( contents ) : JSON . parse ( contents ) ;
217+ const doc = isYaml ? YAML . load ( contents ) : JSON . parse ( contents ) ;
218218 const key = doc . _key ;
219219 const [ , collection ] = key . split ( "!" ) ;
220220 // If the key starts with !folders, we should skip packing it as NeDB doesn't support folders.
@@ -267,7 +267,7 @@ async function compileClassicLevel(pack, files, { log, transformEntry }={}) {
267267 const contents = fs . readFileSync ( file , "utf8" ) ;
268268 const ext = path . extname ( file ) ;
269269 const isYaml = ext === ".yml" || ext === ".yaml" ;
270- const doc = isYaml ? yaml . load ( contents ) : JSON . parse ( contents ) ;
270+ const doc = isYaml ? YAML . load ( contents ) : JSON . parse ( contents ) ;
271271 const [ , collection ] = doc . _key . split ( "!" ) ;
272272 if ( await transformEntry ?. ( doc ) === false ) continue ;
273273 await packDoc ( doc , collection ) ;
@@ -351,7 +351,7 @@ export async function extractPack(src, dest, {
351351 * @returns {Promise<void> }
352352 */
353353async function extractNedb ( pack , dest , {
354- yaml : asYaml , yamlOptions, jsonOptions, log, collection, transformEntry, transformName
354+ yaml, yamlOptions, jsonOptions, log, collection, transformEntry, transformName
355355} = { } ) {
356356 // Load the NeDB file.
357357 const db = new Datastore ( { filename : pack , autoload : true } ) ;
@@ -370,10 +370,10 @@ async function extractNedb(pack, dest, {
370370 if ( await transformEntry ?. ( doc ) === false ) continue ;
371371 let name = await transformName ?. ( doc ) ;
372372 if ( ! name ) {
373- name = `${ doc . name ? `${ getSafeFilename ( doc . name ) } _${ doc . _id } ` : doc . _id } .${ asYaml ? "yml" : "json" } ` ;
373+ name = `${ doc . name ? `${ getSafeFilename ( doc . name ) } _${ doc . _id } ` : doc . _id } .${ yaml ? "yml" : "json" } ` ;
374374 }
375375 const filename = path . join ( dest , name ) ;
376- serializeDocument ( doc , filename , { yaml : asYaml , yamlOptions, jsonOptions } ) ;
376+ serializeDocument ( doc , filename , { yaml, yamlOptions, jsonOptions } ) ;
377377 if ( log ) console . log ( `Wrote ${ chalk . blue ( name ) } ` ) ;
378378 }
379379}
@@ -388,7 +388,7 @@ async function extractNedb(pack, dest, {
388388 * @returns {Promise<void> }
389389 */
390390async function extractClassicLevel ( pack , dest , {
391- yaml : asYaml , yamlOptions, jsonOptions, log, transformEntry, transformName
391+ yaml, yamlOptions, jsonOptions, log, transformEntry, transformName
392392} ) {
393393 // Load the directory as a ClassicLevel DB.
394394 const db = new ClassicLevel ( pack , { keyEncoding : "utf8" , valueEncoding : "json" } ) ;
@@ -411,10 +411,10 @@ async function extractClassicLevel(pack, dest, {
411411 if ( await transformEntry ?. ( doc ) === false ) continue ;
412412 let name = await transformName ?. ( doc ) ;
413413 if ( ! name ) {
414- name = `${ doc . name ? `${ getSafeFilename ( doc . name ) } _${ id } ` : key } .${ asYaml ? "yml" : "json" } ` ;
414+ name = `${ doc . name ? `${ getSafeFilename ( doc . name ) } _${ id } ` : key } .${ yaml ? "yml" : "json" } ` ;
415415 }
416416 const filename = path . join ( dest , name ) ;
417- serializeDocument ( doc , filename , { yaml : asYaml , yamlOptions, jsonOptions } ) ;
417+ serializeDocument ( doc , filename , { yaml, yamlOptions, jsonOptions } ) ;
418418 if ( log ) console . log ( `Wrote ${ chalk . blue ( name ) } ` ) ;
419419 }
420420
@@ -505,7 +505,7 @@ function findSourceFiles(root, { yaml=false, recursive=false }={}) {
505505function serializeDocument ( doc , filename , { yaml, yamlOptions, jsonOptions } = { } ) {
506506 fs . mkdirSync ( path . dirname ( filename ) , { recursive : true } ) ;
507507 let serialized ;
508- if ( yaml ) serialized = yaml . dump ( doc , yamlOptions ) ;
508+ if ( yaml ) serialized = YAML . dump ( doc , yamlOptions ) ;
509509 else {
510510 const { replacer= null , space= 2 } = jsonOptions ;
511511 serialized = JSON . stringify ( doc , replacer , space ) ;
0 commit comments