xpm
Version:
The xPack project manager command line tool
126 lines (99 loc) • 3.99 kB
JavaScript
/*
* This file is part of the xPack project (http://xpack.github.io).
* Copyright (c) 2017-2026 Liviu Ionescu. All rights reserved.
*
* Permission to use, copy, modify, and/or distribute this software
* for any purpose is hereby granted, under the terms of the MIT license.
*
* If a copy of the license was not distributed with this file, it can
* be obtained from https://opensource.org/license/mit.
*/
// ----------------------------------------------------------------------------
/**
* The Xpm main module.
*
* It is re-exported publicly by `index.js`.
*
* To import classes from this module into Node.js applications, use:
*
* ```javascript
* const Xpm = require('xpm').Xpm
* ```
*/
// ----------------------------------------------------------------------------
import fs from 'fs'
// https://nodejs.org/docs/latest/api/
import path from 'path'
import { fileURLToPath } from 'url'
// ----------------------------------------------------------------------------
// ES6: `import { CliApplication, CliOptions } from 'cli-start-options'
import cliStartOptionsCsj from '@ilg/cli-start-options'
// ----------------------------------------------------------------------------
const { CliApplication, CliOptions } = cliStartOptionsCsj
const __dirname = path.dirname(fileURLToPath(import.meta.url))
// ============================================================================
// export
export class Xpm extends CliApplication {
// --------------------------------------------------------------------------
/**
* @summary Initialise the application class object.
*
* @returns {undefined} Nothing.
*
* @description
* Initialise the options manager with application
* specific commands and common options.
*
* @override
*/
static doInitialise() {
const Self = this
// ------------------------------------------------------------------------
// Mandatory, must be set here, not in the library, since it takes
// the shortcut of using `__dirname` of the main file.
Self.rootPath = path.dirname(__dirname)
// Enable -i|--interactive
Self.hasInteractiveMode = true
// ------------------------------------------------------------------------
// Initialise the tree of known commands.
// Paths should be relative to the package root.
CliOptions.addCommand(['install', 'i', 'intsall'], 'src/xpm/install.js')
CliOptions.addCommand(
['run', 'rum', 'ru', 'run-action', 'run-script'],
'src/xpm/run-action.js'
)
CliOptions.addCommand(['init', 'ini'], 'src/xpm/init.js')
CliOptions.addCommand(['link', 'lnk'], 'src/xpm/link.js')
CliOptions.addCommand(['list', 'ls', 'll'], 'src/xpm/list.js')
CliOptions.addCommand(
['uninstall', 'un', 'uni', 'unin', 'unintsall', 'unlink', 'rm', 'r'],
'src/xpm/uninstall.js'
)
// 24 hours in seconds.
Self.checkUpdatesIntervalSeconds = 60 * 60 * 24
// The common options were already initialised by the caller,
// and are ok, no need to redefine them.
// ------------------------------------------------------------------------
// Hack!
// For unknown reasons, on Windows these definitions are not available.
if (process.platform === 'win32') {
if (fs.constants.S_IWUSR === undefined) {
fs.constants.S_IWUSR = 128 // 0200
}
if (fs.constants.S_IWGRP === undefined) {
fs.constants.S_IWGRP = 16 // 0020
}
if (fs.constants.S_IWOTH === undefined) {
fs.constants.S_IWOTH = 2 // 0002
}
}
// ------------------------------------------------------------------------
}
// --------------------------------------------------------------------------
// Constructor: use parent definition.
// main(): use parent definition
// help(): use parent definition.
// (isn't object oriented code reuse great?)
}
// ----------------------------------------------------------------------------