@adonisjs/sink

  • Version 5.4.2
  • Published
  • 122 kB
  • 10 dependencies
  • MIT license

Install

npm i @adonisjs/sink
yarn add @adonisjs/sink
pnpm add @adonisjs/sink

Overview

AdonisJS sink is a swiss knife for managing project files by applying minimal changes, inferring formatting from EditorConfig file and comes with specialized tasks for different file formats and file types.

Index

Variables

variable sinkVersion

const sinkVersion: string;
  • Sharing the sink version, since sink is mainly passed as a reference by the cli

Functions

function getPrompt

getPrompt: () => PromptContract;
  • Returns a new instance of prompt. Also we lazy load the prompts

Namespaces

namespace files

module 'src/Files/index.d.ts' {}

    class AdonisRcFile

    class AdonisRcFile extends JsonFile {}
    • Exposes API to mutate the contents of .adonisrc.json file.

    constructor

    constructor(basePath: string);

      method addAceProvider

      addAceProvider: (provider: string) => void;
      • Add new providers to the ace providers array

      method addCommand

      addCommand: (commandPath: string) => void;
      • Add new commands to the commands array

      method addMetaFile

      addMetaFile: (filePath: string, reloadServer?: boolean) => void;
      • Add custom file to metaFiles array.

      method addProvider

      addProvider: (provider: string) => void;
      • Add new providers to the providers array

      method addTestProvider

      addTestProvider: (provider: string) => void;
      • Add new providers to the test providers array

      method onset

      onset: (lifecycle: string, body: any) => true | undefined;
      • Handle preloads in a custom way on rollback, since the mrm-core uses lodash.unset which replaces the array index value with null and we instead want to remove the index value completely.

      method setAlias

      setAlias: (namespace: string, autoloadPath: string) => this;
      • Set IoC container aliases

      method setDirectory

      setDirectory: (key: string, value: string) => this;
      • Set custom directory

      method setExceptionHandler

      setExceptionHandler: (namespace: string) => this;
      • Set the exception handler namespace.

      method setPreload

      setPreload: (
      filePath: string,
      environment?: AppEnvironments[],
      optional?: boolean
      ) => this;
      • Set the preload file to the .adonisrc.json file.

      class EnvFile

      class EnvFile {}
      • Exposes the API to run mutations on .env file. The same variables will be added to .env.example with empty contents.

      constructor

      constructor(basePath: string);

        method commit

        commit: () => void;
        • Commit mutations

        method exists

        exists: () => boolean;
        • Returns a boolean telling if the file exists.

        method get

        get: () => { [key: string]: string };
        • Returns a key/value pair of the file contents.

        method rollback

        rollback: () => void;
        • Rollback mutations

        method set

        set: (key: string, value: any) => this;
        • Set key/value pair inside the .env file

        method unset

        unset: (key: string) => this;
        • Unset a key/value pair from the .env and .env.example file

        class File

        abstract class File {}
        • Base file exposes the API to add action and cd in/out from the application base directory.

        constructor

        constructor(basePath: string);

          property actions

          protected abstract actions: { action: string; body?: any }[];

            method addAction

            protected addAction: (action: string, body?: any) => void;
            • Add a new action to the actions stack. The action workings are independent on the user adding the action

            method cdIn

            protected cdIn: () => void;
            • cd to the application base path

            method cdOut

            protected cdOut: () => void;
            • cd out from the application base path

            method getCommitActions

            protected getCommitActions: () => { action: string; body?: any }[];
            • Returns an array of actions to commit

            method getRevertActions

            protected getRevertActions: () => { action: string; body?: any }[];
            • Returns an array of actions for performing revert. Since reverts are done in reverse, this method will reverse the actions array.

            class IniFile

            class IniFile extends KeyValuePair {}
            • Ini file to work with files like .editorconfig.

              const ini = new Ini(__dirname, '.editorconfig')
              ini.set('_global', { root: true })
              ini.set('**.js', { insert_final_newline: true })
              ini.commit()

            constructor

            constructor(basePath: string, filename: string);

              property filePointer

              filePointer: any;

                method merge

                merge: (section: string, values: any) => this;
                • Merge to the section values of an ini file.

                  Example 1

                  ini.merge('root', { indent_style: space })

                method onmerge

                onmerge: (lifecycle: string, body: any) => true | undefined;
                • Handling the onmerge action. This method is called by the commit method.

                class JsonFile

                class JsonFile extends KeyValuePair {}
                • Exposes the API to work with JSON files.

                  const json = new JsonFile(__dirname, 'tsconfig.json')
                  json.set('compilerOptions.lib', ['es2017'])
                  json.commit()

                constructor

                constructor(basePath: string, filename: string);

                  property filePointer

                  filePointer: any;

                    class KeyValuePair

                    abstract class KeyValuePair extends File {}
                    • Exposes the API to work with key/value pair files like ini, yaml and json.

                    constructor

                    constructor(basePath: string);

                      property actions

                      protected actions: never[];

                        property filePointer

                        abstract filePointer: any;
                        • Only these key-value pair files are supported

                        method commit

                        commit: () => void;
                        • Commit mutations

                        method delete

                        delete: () => this;
                        • Remove file

                        method exists

                        exists: () => boolean;
                        • A boolean telling if the file already exists

                        method get

                        get: { (): any; (address: string | string[], defaultValue?: any): any };
                        • Returns value for a given key from the file

                        method rollback

                        rollback: () => void;
                        • Rollback mutations

                        method set

                        set: (key: string, value: any) => this;
                        • Set key/value pair

                        method unset

                        unset: (key: string) => this;
                        • Unset key/value pair

                        class MustacheFile

                        class MustacheFile extends File {}
                        • Exposes the API to generate source files from template files.

                        constructor

                        constructor(basePath: string, filename: string, templatePath: string);

                          property actions

                          protected actions: never[];

                            property filePointer

                            filePointer: any;

                              property overwrite

                              overwrite: boolean;

                                property removeOnRollback

                                removeOnRollback: boolean;

                                  method apply

                                  apply: (contents?: any) => this;
                                  • Apply contents to the template to evaluate it's output

                                  method commit

                                  commit: () => void;
                                  • Commit changes

                                  method exists

                                  exists: () => boolean;
                                  • A boolean telling if the file already exists

                                  method get

                                  get: () => string;
                                  • Returns existing contents for a template file

                                  method partials

                                  partials: (partials: { [key: string]: string }) => this;
                                  • Define one or more partials by defining key-value pair of partial name and path to the file.

                                  method rollback

                                  rollback: () => void;
                                  • Rollback changes

                                  class NewLineFile

                                  class NewLineFile extends File {}
                                  • Base class to work with raw text new line files. For example .env file or .gitignore

                                  constructor

                                  constructor(basePath: string, filename: string);

                                    property actions

                                    protected actions: never[];

                                      property filePointer

                                      filePointer: any;

                                        method add

                                        add: (line: string | string[]) => this;
                                        • Add one or more new lines

                                        method commit

                                        commit: () => void;
                                        • Commit mutations

                                        method delete

                                        delete: () => this;
                                        • Delete file

                                        method exists

                                        exists: () => boolean;
                                        • A boolean telling if the file already exists

                                        method get

                                        get: () => string[];
                                        • Get contents for the file

                                        method remove

                                        remove: (line: string | string[]) => this;
                                        • Remove lines matching the give text

                                        method rollback

                                        rollback: () => void;
                                        • Rollback mutations

                                        method update

                                        update: (oldText: string, newText: string) => this;
                                        • Update existing text with new text

                                        class PackageJsonFile

                                        class PackageJsonFile extends File {}
                                        • Exposes the API to work with package.json file. The file is same as a standard JSON file, but with some special methods related to package file itself.

                                        constructor

                                        constructor(basePath: string, installerOutput?: StdioOptions);

                                          property actions

                                          protected actions: never[];
                                          • Collection of actions to be executed on package file

                                          property filePointer

                                          filePointer: any;

                                            property packages

                                            protected packages: {
                                            install: { dependency: string; version: string; dev: boolean }[];
                                            uninstall: { dependency: string; dev: boolean }[];
                                            };
                                            • A copy of install instructions

                                            method appendScript

                                            appendScript: (name: string, script: string) => this;
                                            • Append to existing package.json script

                                            method beforeInstall

                                            beforeInstall: (callback: InstallerNotifier) => this;
                                            • Define a function to be called before installing dependencies

                                            method beforeUninstall

                                            beforeUninstall: (callback: InstallerNotifier) => this;
                                            • Define a function to be called before uninstalling dependencies

                                            method commit

                                            commit: () => SpawnSyncReturns<Buffer> | undefined;
                                            • Commit mutations

                                            method commitAsync

                                            commitAsync: () => Promise<SpawnSyncReturns<Buffer> | undefined>;
                                            • Commits async. The files are still written using synchronous API. However, the install and uninstall becomes async.

                                            method delete

                                            delete: () => this;
                                            • Remove file

                                            method exists

                                            exists: () => boolean;
                                            • A boolean telling if the file already exists

                                            method get

                                            get: { (): any; (address: string | string[], defaultValue?: any): any };
                                            • Returns value for a given key from the file

                                            method getInstalls

                                            getInstalls: (dev?: boolean) => Dependencies;
                                            • Returns a list of dependencies along with specific versions (if any)

                                            method getUninstalls

                                            getUninstalls: (dev: boolean) => Dependencies;
                                            • Returns uninstalls list for prod or development dependencies.

                                            method install

                                            install: (dependency: string, version?: string, dev?: boolean) => this;
                                            • Install dependencies

                                            method prependScript

                                            prependScript: (name: string, script: string) => this;
                                            • Prepend to existing package.json script

                                            method removeScript

                                            removeScript: (name: string, script?: string | RegExp) => this;
                                            • Remove existing script or remove a given action from an existing script

                                            method rollback

                                            rollback: () => SpawnSyncReturns<Buffer> | undefined;
                                            • Rollback mutations

                                            method rollbackAsync

                                            rollbackAsync: () => Promise<SpawnSyncReturns<Buffer> | undefined>;
                                            • Rollsback async. The files are still written using synchronous API. However, the uninstall becomes async.

                                            method set

                                            set: (key: string, value: any) => this;
                                            • Set key/value pair in the package.json file

                                            method setScript

                                            setScript: (name: string, script: string) => this;
                                            • Set package.json script

                                            method uninstall

                                            uninstall: (dependency: string, dev?: boolean) => this;
                                            • Uninstall dependencies

                                            method unset

                                            unset: (key: string) => this;
                                            • Unset key/value pair from the package.json file

                                            method useClient

                                            useClient: (client: SupportedPackageManager) => this;
                                            • Set a specific client to be used

                                            method yarn

                                            yarn: (_useYarn: boolean) => this;
                                            • Enable/disable use of yarn

                                              Deprecated

                                              The "yarn" method is deprecated. Please use "useClient('yarn')" instead.

                                            class TemplateLiteralFile

                                            class TemplateLiteralFile extends File {}
                                            • Exposes the API to generate source files from template files.

                                            constructor

                                            constructor(basePath: string, filename: string, templatePath: string);

                                              property actions

                                              protected actions: never[];

                                                property filePointer

                                                filePointer: any;

                                                  property overwrite

                                                  overwrite: boolean;

                                                    property removeOnRollback

                                                    removeOnRollback: boolean;

                                                      method apply

                                                      apply: (contents?: any) => this;
                                                      • Apply contents to the template to evaluate it's output

                                                      method commit

                                                      commit: () => void;
                                                      • Commit changes

                                                      method exists

                                                      exists: () => boolean;
                                                      • A boolean telling if the file already exists

                                                      method get

                                                      get: () => string;
                                                      • Returns existing contents for a template file

                                                      method rollback

                                                      rollback: () => void;
                                                      • Rollback changes

                                                      class YamlFile

                                                      class YamlFile extends KeyValuePair {}
                                                      • Exposes the API to work with Yaml files.

                                                        const yaml = new YamlFile(__dirname, '.travis.yml')
                                                        yaml.set('language', 'node_js')
                                                        yaml.set('language', [4, 6])
                                                        yaml.commit()

                                                      constructor

                                                      constructor(basePath: string, filename: string);

                                                        property filePointer

                                                        filePointer: any;

                                                          namespace tasks

                                                          module 'src/Tasks/index.d.ts' {}

                                                            class Instructions

                                                            class Instructions {}
                                                            • Exposes the API to execute the instructions of a package, defined inside the package.json file.

                                                            constructor

                                                            constructor(
                                                            packageName: string,
                                                            projectRoot: string,
                                                            application: ApplicationContract,
                                                            verbose?: boolean
                                                            );

                                                              method execute

                                                              execute: () => Promise<boolean>;
                                                              • Execute the instructions file

                                                              method setDisplay

                                                              setDisplay: (display: 'browser' | 'terminal') => this;
                                                              • Preset markdown display for avoiding prompt

                                                              method useLogger

                                                              useLogger: (logger: any) => this;
                                                              • Define a custom logger to use

                                                              class MarkdownRenderer

                                                              class MarkdownRenderer {}
                                                              • Markdown renderer for opening the instructions md file inside the terminal or the browser.

                                                              constructor

                                                              constructor(mdFileAbsPath: string, packageName: string);

                                                                method renderInBrowser

                                                                renderInBrowser: () => Promise<void>;
                                                                • Converts markdown to HTML and opens it up inside the browser

                                                                method renderInTerminal

                                                                renderInTerminal: () => Promise<void>;
                                                                • Writes markdown in the terminal

                                                                class TemplatesManager

                                                                class TemplatesManager {}
                                                                • Templates manager to copy one or more templates to the user project.

                                                                constructor

                                                                constructor(
                                                                projectRoot: string,
                                                                templatesSourceDir: string,
                                                                application: ApplicationContract
                                                                );

                                                                  method copy

                                                                  copy: (templates: {
                                                                  [key: string]: TemplateNode | TemplateNode[];
                                                                  }) => Promise<void>;
                                                                  • Copy multiple templates to the destination. It takes the input of templates defined inside the package.json file.

                                                                  method useLogger

                                                                  useLogger: (logger: any) => this;
                                                                  • Define a custom logger to use

                                                                  namespace utils

                                                                  module 'src/Utils/index.d.ts' {}

                                                                    function copyFiles

                                                                    copyFiles: (
                                                                    sourceBaseDir: string,
                                                                    destinationBaseDir: string,
                                                                    files: string[],
                                                                    options?: { overwrite: boolean }
                                                                    ) => { filePath: string; state: 'skipped' | 'copied' }[];
                                                                    • Utility method to copy files

                                                                    function getPackageManager

                                                                    getPackageManager: (appRoot: string) => 'yarn' | 'pnpm' | 'npm';
                                                                    • Returns the package manager in use by checking for the lock files on the disk or by inspecting the "npm_config_user_agent".

                                                                      Defaults to npm when unable to detect the package manager.

                                                                    function isEmptyDir

                                                                    isEmptyDir: (location: string) => boolean;
                                                                    • Returns a boolean telling if a directory is empty or not.

                                                                    Package Files (21)

                                                                    Dependencies (10)

                                                                    Dev Dependencies (29)

                                                                    Peer Dependencies (1)

                                                                    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/@adonisjs/sink.

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