1.6.6 • Published 1 year ago

build-deno v1.6.6

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Build Deno

build-deno is a Node.js package that helps you build your Deno source code from your Node source code. It can copy files, change import paths, and skip files during the build process.

Installation

Node

# npm
npm install --save-dev build-deno

# yarn
yarn add -D build-deno

# pnpm
pnpm add -D build-deno

Deno

Unlike Node, Deno doesn't use a package management like NPM and instead depends on direct URL imports. You can access build-deno on deno.land/x. This is how the most recent version may be imported:

You can also specify a particular version:

import { build } from 'npm:build-deno@^1.5';

or letest version:

import { build } from 'npm:build-deno';

NOTE: There isn't much of a change in how it's used, but the remainder of this README assumes you're using npm and importing straight from the build-deno package.

Usage

API

import type {
  Path,
  ChangePackage,
  SkipDirectory,
  SkipFile,
  CopyFiles,
  Options,
} from 'build-deno';
import { build } from 'build-deno';

const root: Path = '';

const rootDir: Path = 'src';

const outDir: Path = 'deno';

const changePackage: ChangePackage[] = [
  {
    package: `import { join as joinPath } from 'path';`,
    replace: `import { join as joinPath } from 'npm:path';`,
  },
  {
    package: `import { dirname, extname } from 'path';`,
    replace: `import { dirname, extname } from 'npm:path';`,
  },
  {
    package: `import { copyFile } from 'fs';`,
    replace: `import { copyFile } from 'npm:fs';`,
  },
  {
    byPackageName: true,
    package: `util`,
    replace: `import { promisify } from 'npm:util';`,
  },
  {
    package: `import { statSync } from 'fs';`,
    replace: `import { statSync } from 'npm:fs';`,
  },
  {
    byPackageName: true,
    package: 'fs/promises',
    replace: `import { readdir, readFile, mkdir, writeFile } from 'npm:fs/promises';`,
  },
  {
    package: `import { dirname } from 'path';`,
    replace: `import { dirname } from 'npm:path';`,
  },
  {
    package: `import { readdirSync } from 'fs';`,
    replace: `import { readdirSync } from 'npm:fs';`,
  },
];

const skipDirectory: SkipDirectory[] = [
  {
    dir: '__TEST__',
  },
];

const skipFile: SkipFile[] = [
  {
    dir: '',
    file: 'cli.ts',
  },
];

const skipExtension: SkipExtension[] = [
  {
    extension: '.mock.ts',
  },
];

const copyFiles: CopyFiles[] = [
  {
    from: 'README.md',
    to: 'README.md',
  },
];

const options: Options = {
  root,
  rootDir,
  outDir,
  changePackage,
  skipDirectory,
  skipFile,
  skipExtension,
  copyFiles,
};

build(options);

Options

  • root: The root directory of your Node project. Required.
  • rootDir: The directory of the Node source code. Required.
  • outDir: The directory where the Deno source code will be generated. Required.
  • changePackage: An array of objects that specify the package names to change the import path for. Optional.
  • skipDirectory: An array of directory names to skip during the build. Optional.
  • skipFile: An array of file paths to skip during the build. Optional.
  • skipExtension: An array of file extensions to skip during the build. Optional.
  • copyFiles: An array of file paths to copy from the Node source code to the Deno source code. Optional.

Types

build-deno exports the following types:

  • Path: A string representing a file path.
  • SkipFile: An object containing the dir and name of a file to skip.
  • ChangePackage: An object containing the packageName and path of a package to change the import path for.
  • SkipDirectory: An object containing the dir of a directory to skip.
  • CopyFiles: An object containing the from and to paths of a file to copy.
  • SkipExtension: An object containing the extension of a file to skip.
  • Options: An object containing the above properties.

Example

You can find an example of build-deno in use in the Denoify example project.

CLI Commands

To use build-deno, you can run the following commands:

build-deno

Builds your project with the configuration file. Make sure to add the configuration file in the root directory of your project. The configuration file name can be one of the following:

  • build-deno.config.js
  • build-deno.config.cjs
  • build-deno.config.mjs
  • build-deno.config.json

Example:

build-deno

NOTE: The configuration file path must be relative to the root directory of your project.

build-deno -C <config-file> or build-deno --config <config-file>

Builds your project with the specified configuration file.

Example:

build-deno -C build-deno.config.js

NOTE: The configuration file path must be relative to the root directory of your project.

build-deno -H or build-deno --help

Displays the help menu for build-deno.

Example:

build-deno -H

build-deno -V or build-deno --version

Displays the version of build-deno.

Example:

build-deno -V

Configuration

build-deno.config.js

module.exports = {
  root: '',
  rootDir: 'src',
  outDir: 'deno',
  changePackage: [
    {
      package: `import { join as joinPath } from 'path';`,
      replace: `import { join as joinPath } from 'npm:path';`,
    },
    {
      package: `import { dirname, extname } from 'path';`,
      replace: `import { dirname, extname } from 'npm:path';`,
    },
    {
      package: `import { copyFile } from 'fs';`,
      replace: `import { copyFile } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: `util`,
      replace: `import { promisify } from 'npm:util';`,
    },
    {
      package: `import { statSync } from 'fs';`,
      replace: `import { statSync } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: 'fs/promises',
      replace: `import { readdir, readFile, mkdir, writeFile } from 'npm:fs/promises';`,
    },
    {
      package: `import { dirname } from 'path';`,
      replace: `import { dirname } from 'npm:path';`,
    },
    {
      package: `import { readdirSync } from 'fs';`,
      replace: `import { readdirSync } from 'npm:fs';`,
    },
  ],
  skipDirectory: [
    {
      dir: '__TEST__',
    },
  ],
  skipFile: [
    {
      dir: '',
      name: 'cli.ts',
    },
  ],
  skipExtension: [
    {
      extension: '.mock.ts',
    },
  ],
  copyFiles: [
    {
      from: 'README.md',
      to: 'README.md',
    },
  ],
};

build-deno.config.cjs

module.exports = {
  root: '',
  rootDir: 'src',
  outDir: 'deno',
  changePackage: [
    {
      package: `import { join as joinPath } from 'path';`,
      replace: `import { join as joinPath } from 'npm:path';`,
    },
    {
      package: `import { dirname, extname } from 'path';`,
      replace: `import { dirname, extname } from 'npm:path';`,
    },
    {
      package: `import { copyFile } from 'fs';`,
      replace: `import { copyFile } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: `util`,
      replace: `import { promisify } from 'npm:util';`,
    },
    {
      package: `import { statSync } from 'fs';`,
      replace: `import { statSync } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: 'fs/promises',
      replace: `import { readdir, readFile, mkdir, writeFile } from 'npm:fs/promises';`,
    },
    {
      package: `import { dirname } from 'path';`,
      replace: `import { dirname } from 'npm:path';`,
    },
    {
      package: `import { readdirSync } from 'fs';`,
      replace: `import { readdirSync } from 'npm:fs';`,
    },
  ],
  skipDirectory: [
    {
      dir: '__TEST__',
    },
  ],
  skipFile: [
    {
      dir: '',
      name: 'cli.ts',
    },
  ],
  skipExtension: [
    {
      extension: '.mock.ts',
    },
  ],
  copyFiles: [
    {
      from: 'README.md',
      to: 'README.md',
    },
  ],
};

build-deno.config.mjs

export default {
  root: '',
  rootDir: 'src',
  outDir: 'deno',
  changePackage: [
    {
      package: `import { join as joinPath } from 'path';`,
      replace: `import { join as joinPath } from 'npm:path';`,
    },
    {
      package: `import { dirname, extname } from 'path';`,
      replace: `import { dirname, extname } from 'npm:path';`,
    },
    {
      package: `import { copyFile } from 'fs';`,
      replace: `import { copyFile } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: `util`,
      replace: `import { promisify } from 'npm:util';`,
    },
    {
      package: `import { statSync } from 'fs';`,
      replace: `import { statSync } from 'npm:fs';`,
    },
    {
      byPackageName: true,
      package: 'fs/promises',
      replace: `import { readdir, readFile, mkdir, writeFile } from 'npm:fs/promises';`,
    },
    {
      package: `import { dirname } from 'path';`,
      replace: `import { dirname } from 'npm:path';`,
    },
    {
      package: `import { readdirSync } from 'fs';`,
      replace: `import { readdirSync } from 'npm:fs';`,
    },
  ],
  skipDirectory: [
    {
      dir: '__TEST__',
    },
  ],
  skipFile: [
    {
      dir: '',
      name: 'cli.ts',
    },
  ],
  skipExtension: [
    {
      extension: '.mock.ts',
    },
  ],
  copyFiles: [
    {
      from: 'README.md',
      to: 'README.md',
    },
  ],
};

build-deno.config.json

{
  "root": "",
  "rootDir": "src",
  "outDir": "deno",
  "changePackage": [
    {
      "package": "import { join as joinPath } from 'path';",
      "replace": "import { join as joinPath } from 'npm:path';"
    },
    {
      "package": "import { dirname, extname } from 'path';",
      "replace": "import { dirname, extname } from 'npm:path';"
    },
    {
      "package": "import { copyFile } from 'fs';",
      "replace": "import { copyFile } from 'npm:fs';"
    },
    {
      "byPackageName": true,
      "package": "util",
      "replace": "import { promisify } from 'npm:util';"
    },
    {
      "package": "import { statSync } from 'fs';",
      "replace": "import { statSync } from 'npm:fs';"
    },
    {
      "byPackageName": true,
      "package": "fs/promises",
      "replace": "import { readdir, readFile, mkdir, writeFile } from 'npm:fs/promises';"
    },
    {
      "package": "import { dirname } from 'path';",
      "replace": "import { dirname } from 'npm:path';"
    },
    {
      "package": "import { readdirSync } from 'fs';",
      "replace": "import { readdirSync } from 'npm:fs';"
    }
  ],
  "skipDirectory": [
    {
      "dir": "__TEST__"
    }
  ],
  "skipFile": [
    {
      "dir": "",
      "name": "cli.ts"
    }
  ],
  "skipExtension": [
    {
      "extension": ".mock.ts"
    }
  ],
  "copyFiles": [
    {
      "from": "README.md",
      "to": "README.md"
    }
  ]
}

License

build-deno is licensed under the MIT License.

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.6.4

1 year ago

1.6.3

1 year ago

1.6.2

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.6.6

1 year ago

1.6.5

1 year ago

0.0.1

1 year ago