majo

  • Version 0.10.1
  • Published
  • 15.7 kB
  • 3 dependencies
  • MIT license

Install

npm i majo
yarn add majo
pnpm add majo

Overview

A minimal module to manipulate files.

Index

Functions

function majo

majo: () => Majo;

    function outputFile

    outputFile: (
    filepath: string,
    data: any,
    options?:
    | string
    | {
    encoding?: string | null | undefined;
    mode?: string | number | undefined;
    flag?: string | undefined;
    }
    | null
    | undefined
    ) => Promise<void>;
    • Ensure directory exists before writing file

    function remove

    remove: (arg1: string) => Promise<void>;

      Classes

      class Majo

      class Majo {}

        constructor

        constructor();

          property baseDir

          baseDir?: string;
          • Base directory You normally set this by calling .source

          property dotFiles

          dotFiles?: boolean;

            property fileList

            readonly fileList: string[];
            • Get an array of sorted file paths

            property files

            files: { [filename: string]: File };

              property meta

              meta: { [k: string]: any };
              • An object you can use across middleware to share states

              property middlewares

              middlewares: Middleware[];

                property onWrite

                onWrite?: OnWrite;

                  property sourcePatterns

                  sourcePatterns?: string[];

                    method createFile

                    createFile: (relativePath: string, file: File) => this;
                    • Create a new file

                      Parameter relativePath

                      Relative path

                      Parameter file

                    method deleteFile

                    deleteFile: (relativePath: string) => this;
                    • Delete a file

                      Parameter relativePath

                      Relative path

                    method dest

                    dest: (dest: string, options?: DestOptions) => Promise<this>;
                    • Run middlewares and write processed files to disk

                      Parameter dest

                      Target directory

                      Parameter opts

                      Parameter

                      opts.baseDir Base directory to resolve target directory

                      Parameter

                      opts.clean Clean directory before writing

                    method file

                    file: (relativePath: string) => File;
                    • Get a file by relativePath path

                      Parameter relativePath

                      Relative path

                    method fileContents

                    fileContents: (relativePath: string) => string;
                    • Get file contents as a UTF-8 string

                      Parameter relativePath

                      Relative path

                    method fileStats

                    fileStats: (relativePath: string) => fs.Stats;
                    • Get the fs.Stats object of specified file relativePath Relative path

                    method filter

                    filter: (fn: FilterHandler) => this;
                    • Filter files

                      Parameter fn

                      Filter handler

                    method process

                    process: () => Promise<this>;
                    • Process middlewares against files

                    method rename

                    rename: (fromPath: string, toPath: string) => this;

                      method source

                      source: (patterns: string | string[], options?: SourceOptions) => this;
                      • Find files from specific directory

                        Parameter source

                        Glob patterns

                        Parameter opts

                        Parameter

                        opts.baseDir The base directory to find files

                        Parameter

                        opts.dotFiles Including dot files

                      method transform

                      transform: (relativePath: string, fn: TransformHandler) => Promise<void>;
                      • Transform file at given path

                        Parameter relativePath

                        Relative path

                        Parameter fn

                        Transform handler

                      method use

                      use: (middleware: Middleware) => this;
                      • Use a middleware

                      method writeContents

                      writeContents: (relativePath: string, contents: string) => this;
                      • Write contents to specific file

                        Parameter relativePath

                        Relative path

                        Parameter string

                        File content as a UTF-8 string

                      Interfaces

                      interface DestOptions

                      interface DestOptions {}

                        property baseDir

                        baseDir?: string;
                        • The base directory to write files to process.cwd()

                        property clean

                        clean?: boolean;
                        • Whether to clean output directory before writing files false

                        interface File

                        interface File {}

                          property contents

                          contents: Buffer;

                            property path

                            path: string;
                            • The absolute path of the file

                            property stats

                            stats: fs.Stats;

                              interface SourceOptions

                              interface SourceOptions {}

                                property baseDir

                                baseDir?: string;
                                • The base directory to search files from process.cwd()

                                property dotFiles

                                dotFiles?: boolean;
                                • Whether to include dot files true

                                property onWrite

                                onWrite?: OnWrite;
                                • This function is called when a file is written

                                Type Aliases

                                type FilterHandler

                                type FilterHandler = (relativePath: string, file: File) => boolean;

                                  type Middleware

                                  type Middleware = (ctx: Majo) => Promise<void> | void;

                                    type OnWrite

                                    type OnWrite = (relativePath: string, outputPath: string) => void;

                                      type TransformHandler

                                      type TransformHandler = (contents: string) => Promise<string> | string;

                                        Package Files (1)

                                        Dependencies (3)

                                        Dev Dependencies (14)

                                        Peer Dependencies (0)

                                        No peer dependencies.

                                        Badge

                                        To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                        You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/majo.

                                        • Markdown
                                          [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/majo)
                                        • HTML
                                          <a href="https://www.jsdocs.io/package/majo"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>