@tezka/makedist
v0.2.3
Published
A tool for creating distributable packages
Downloads
2
Maintainers
Readme
Makedist
Makedist helps developers and administrators prepare a package containing their source code or distributable binary.
It's written in JavaScript but is intended for (eventually) helping to package anything.
Currently only JavaScript projects with package.json are supported.
Installation
To install Makedist:
npm install -g @tezka/makedistUsage
To package a NodeJS project with only sources:
cd project_dir
makedistTo package a NodeJS project with only production dependencies:
cd project_dir
makedist --dependenciesWhen successful, the output is a single line with the path to the output file. For example:
makedist/package.tgzMore options are available:
- Change source directory with
--src <dir> - Change output directory with
--out <dir> - Change package name with
--name <name> - Use preset options with
--preset <preset>where<preset>is one of 'script', 'library', or 'website' - Show verbose messages with
-vor--verbose
See the Options section for all options.
Options
dependencies
Includes runtime dependencies in the package.
This automatically adds dependencies to the packageInfo option, so the
dependencies section of package.json will be included in the output package.json
file.
files
Includes additional files in the package.
The default setting for this option is the files section from package.json.
You can override it by setting the files property in the makedist section
of package.json. This will completely replace the original files section,
not add to it, so you may need to repeat entries.
Currently, this option can only be set from the makedist section
of package.json or from the makedist.config.js (or .mjs or .cjs) file.
name
Change output package name.
Instead of creating an output file package.tgz in the output directory,
you can name it whatever you like:
makedist --name example.tgzout
Change output directory.
Instead of creating an output directory ./makedist, you can
choose any other location instead:
makedist --out /tmp/makedistpackageInfo
Include additional properties from package.json in the output
package.json file.
This is an array of property names.
The default setting for this option is ['name', 'version', 'license', 'author', 'contributors'].
When you specify the packageInfo option, it adds to the default setting.
Currently, this option can only be set from the makedist section
of package.json or from the makedist.config.js (or .mjs or .cjs) file.
preset
Select a preset.
The files and packageInfo options aren't available directly via the command
line, but there are a few presets you can select for these.
For example:
makedist --preset script
makedist --preset library
makedist --preset websiteAvailable presets:
- library
- script
- website
library
Sets the dependencies option to true (unless you override it with --no-dependencies).
Includes dependencies, type, main, and engines top-level properties from package.json.
script
Sets the dependencies option to true (unless you override it with --no-dependencies).
Includes dependencies, type, bin, and engines top-level properties from package.json.
website
Sets the dependencies option to false (unless you override it with --dependencies).
Does not include additional top-level properties from package.json.
src
Change source directory.
Instead of looking for package.json in the current directory, you
can look in another directory:
makedist --src /path/to/project_dirverbose
Shows verbose messages.
If you need to see more details about what is happening, use the verbose flag:
makedist --verbose
makedist -vConfiguration
When an option can be defined in multiple places, the following priority order is used:
- Command line arguments (override configuration)
- Export from
makedist.config.mjsormakedist.config.cjs(can actually readmakedistfrom package.json and then override it) - Content of
package.jsonin the 'makedist' section - Built-in defaults (package name is 'package', output directory is 'makedist')
However, not all settings can be defined in all these places.
The following options can ONLY be set via the command line:
--src--verboseor-v
The following options can ONLY be set via the configuration file:
files(which files to copy into the package; overrides the top-levelfilessection frompackage.json)packageInfo(which top-level attributes ofpackage.jsonto copy into the package)
The preferred way to configure makedist is using the configuration file
makedist.config.mjs or makedist.config.cjs. This enables you to create a
package by simply executing makedist on the command line without any arguments,
and makes it easier to integrate with other software. For example, if you use
both an IDE and a build server, using the configuration file means you don't
need to maintain two separate configurations.
makedist.config.js
Makedist looks for a file named makedist.config.mjs or makedist.config.cjs
or makedist.config.js in the source directory, in that order.
Only the first one found is imported.
If you use makedist.config.js, the content can be ESM or CommonJS, and MUST
match your project settings in package.json (default is CommonJS if not specified).
The file should export the configuration settings that should be set.
You can export static values, or you can run some JavaScript code before exporting.
Here is an example makedist.config.mjs that sets a static package name:
const name = 'makedist';
export { name };Here is the same functionality but in 'makedist.config.cjs`:
const name = 'makedist';
module.exports = { name };Here is an example makedist.config.mjs that sets a dynamic package name based on
the name and version fields in package.json:
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const thisFilePath = fileURLToPath(import.meta.url);
const packageJsonFile = path.resolve(path.dirname(thisFilePath), 'package.json');
const packageJsonFileContent = fs.readFileSync(packageJsonFile, 'utf-8');
const pkg = JSON.parse(packageJsonFileContent);
let packageName = pkg.name ?? 'unknown';
if (pkg.name.indexOf('/') > -1) {
[, packageName] = pkg.name.split('/');
}
let packageVersion = pkg.version ?? '0.0.0';
const name = `${packageName}-${packageVersion}`;
export { name };Here is the same functionality but in makedist.config.cjs:
const fs = require('fs');
const path = require('path');
const packageJsonFile = path.resolve(path.dirname(__filename), 'package.json');
const packageJsonFileContent = fs.readFileSync(packageJsonFile, 'utf-8');
const pkg = JSON.parse(packageJsonFileContent);
let packageName = pkg.name ?? 'unknown';
if (pkg.name.indexOf('/') > -1) {
[, packageName] = pkg.name.split('/');
}
let packageVersion = pkg.version ?? '0.0.0';
const name = `${packageName}-${packageVersion}`;
module.exports = { name };package.json
Here is an example package.json that sets a static package name:
{
"name": "@getpkg/makedist",
"version": "0.1.2",
"makedist": {
"name": "makedist-0.1.2"
}
}Project types
NodeJS
By default, makedist will create a makedist/package directory containing a
copy of each file and directory mentioned in the files section of
package.json, and also a makedist/package/node_modules directory containing
only the packages mentioned in the dependencies section of
package.json (and not in the devDependencies), then it will
create an output file makedist/package.tgz with the content of the makedist/package directory.
