Spanish Total.js
English
Documentation For AI agents
Contents

Command line (total4)

Every command of the total4 command-line tool.

.md GitHub
On this page

The total4 tool is installed with npm install -g total4. The guide Command line (total4) explains the commands with examples; this page lists every command, its arguments and its output.

API

command

total4 <command> [arguments]

The command-line tool of the total4 package.

Installed with npm install -g total4 (the bin entry of the package). The first argument is the command; name, -name and --name are the same command. Each run prints a header box with the version first. Without a command it prints Use "total4 help" to list all commands., and an unknown command prints Command "..." is invalid.

Install and list the commands
npm install -g total4
total4 help
command

total4 help

Prints the list of all commands.

Aliases: h, -h, --help. Prints one line for each command with its arguments and a short description.

Show the help
total4 help
command

total4 version

Prints only the header with the version.

Aliases: -v, --version. The tool prints its header box, which contains the version of the framework, and ends.

Show the version
total4 -v
command

total4 <port>

Serves the current directory as static files on the given port.
ParameterTypeDescription
port Number The port of the HTTP server.

The number must be the first argument. The server runs in debug mode on 0.0.0.0. A directory returns its index.html, or a generated directory listing with file sizes when there is none. HTML, scripts and styles are sent without compilation; .less files are served as text/less. Temporary files go to the temporary directory of the system. Stop it with Ctrl+C.

Serve a static site
cd ~/www/landing
total4 8000
# open http://127.0.0.1:8000/
command

total4 templates

Prints the list of official project templates.

Downloads the list from GitHub and prints the name and description of each template. Without a connection it prints Total.js templates are currently unavailable.

List templates
total4 templates
command

total4 bundle [filename]

Makes a bundle of the current directory.
ParameterTypeDescription
filename? String The name of the bundle file, with the .bundle extension. Default: app.bundle

Writes all files of the current directory into one .bundle file and prints the directory, the file name, the number of files and the size. Excluded: /bundle.json, /debug.js, /release.js, /index.js with their .json and .pid files, /package.json, /readme.md, /license.txt, /bundles/, /tmp/, /.src/, /.git/ and the output file. See Application structure for how bundles are loaded.

Bundle an application
cd ~/projects/eshop
total4 --bundle eshop.bundle
# copy eshop.bundle to /bundles/ of another application
command

total4 package [filename]

Makes a .package file of the current directory.
ParameterTypeDescription
filename? String The name of the package file, with the .package extension. Default: noname.package

Works like bundle. Excluded: /bundle.json, /debug.js, /release.js, /debug.pid, /package.json, /readme.md, /license.txt, /bundles/, /tmp/, /.git/ and the output file. Copy the result to /packages/ of an application.

Make a package
cd ~/packages/reports
total4 package reports.package
command

total4 extract <filename>

since 0.0.89 Extracts a bundle or a package into the current directory.
ParameterTypeDescription
filename String The .bundle or .package file.

Writes every file of the archive into the current directory, overwriting files with the same path, and prints the number of files and the size.

Extract a bundle
mkdir restored && cd restored
total4 --extract ../eshop.bundle
command

total4 minify <filename>

Minifies a .js, .css or .html file.
ParameterTypeDescription
filename String The file to minify.

Aliases: -compress, -compile (with one or two dashes). The file name is the last argument. Writes <name>.min.<extension> next to the file and prints Minified: <path>; other extensions are not written. A missing file prints File not found.

Minify a script
total4 minify public/js/app.js
# writes public/js/app.min.js
command

total4 translate

Collects localizable texts of the application into translate.resource.

Alias: -t. Reads .html and .js files (and files with sitemap in their path) of the current directory and all its subdirectories. Collects @(text) markers (texts that start with # and a non-space character are skipped) and, in .js files, keys from $.invalid('key'), .error('key') and .err('key'). Writes translate.resource grouped by // filename comments and prints the number of texts. See Localization.

Create a resource
cd ~/projects/eshop
total4 translate
cp translate.resource resources/sk.resource
command

total4 translate "TEXT"

Prints the resource line for one text.
ParameterTypeDescription
TEXT String The text to translate.

When the argument is not an existing file, the tool prints the key (T and the base-36 hash of the text) and the text, ready to paste into a resource file.

Key of one text
total4 translate "Add to cart"
command

total4 translate <filename>

Creates translate.resource from the lines of a text file.
ParameterTypeDescription
filename String A text file with one text per line.

Each non-empty line of the file becomes one entry with a T hash key. The result is translate.resource in the current directory.

Resource from a list of texts
total4 translate texts.txt
command

total4 translatecsv

Collects localizable texts into translate.csv.

Alias: -c. Reads .html and .js files of the current directory and its subdirectories and writes each unique @(text) marker as a row of translate.csv with the columns Hash;Text;Translation.

CSV for a translator
total4 translatecsv
# send translate.csv to the translator
command

total4 translate4 <source>

Converts a resource with old numeric keys to Total.js 4 keys.
ParameterTypeDescription
source String The old resource file.

Alias: -4. Keys like T123 and T-123 become T and the base-36 form of the number; other lines stay. The output name is the argument with -new inserted before its first dot.

Convert an old resource
cd resources
total4 translate4 sk.resource
# writes sk-new.resource
command

total4 diff <source> <target>

Writes the differences between two resource files.
ParameterTypeDescription
source String The complete resource, for example from translate.
target String The resource to check.

Writes <target>-diff.txt next to the target with two sections: the keys of source that target misses ("Add to") and the keys of target that source does not have ("Remove from"), with their comments. Prints the counts and the output file.

Find new texts
total4 translate
total4 diff translate.resource resources/sk.resource
# read resources/sk-diff.txt
command

total4 merge <source> <target>

Merges the texts of one resource into another.
ParameterTypeDescription
source String The resource with new texts.
target String The resource to update.

Goes through target and replaces the text of each key that source also has. Keys missing in source keep their text; keys only in source are not added. Writes <target>-merged.txt next to the target and prints the number of merged keys.

Take translated texts
total4 merge sk-from-translator.resource resources/sk.resource
# writes resources/sk-merged.txt
command

total4 clean <source>

Aligns the keys of a resource file.
ParameterTypeDescription
source String The resource file.

Pads all keys to one column and keeps comments and empty lines. Writes <source>-cleaned.txt next to the file.

Tidy a resource
total4 clean resources/sk.resource
# writes resources/sk-cleaned.txt
command

total4 edit <url>

since 0.0.46 Connects the current directory to the Total.js Code Editor.
ParameterTypeDescription
url String The URL of the project in the Code Editor, with ?id=project.

Alias: -e. Opens a WebSocket connection to the project URL (http becomes ws) and lets the editor browse, read, create, save, rename, upload and remove files of the current directory and read its logs. Reconnects every 10 seconds. Prints 404 project not found while the project does not exist and stops with 409 project is already open.

Open a project
cd ~/projects/eshop
total4 edit "https://code.example.com/?id=eshop"
type

translate.resource

The resource file written by the translate commands.

Starts with // Total.js translation file and the creation time. Each line is key : text; total4 translate groups the lines under // filename comments that list the files using the text. Rename it to <language>.resource and put it in /resources/.

Content
// Total.js translation file
// Created: 2024-05-10 09:30

// views/index.html
T1x9c0ks     : Add to cart
T3jf0a2      : Checkout
type

translate.csv

The CSV file written by total4 translatecsv.

The first row is Hash;Text;Translation. Each next row has the key, the text in double quotes and an empty translation.

Content
Hash;Text;Translation
T1x9c0ks;"Add to cart";
T3jf0a2;"Checkout";
Made in Europe