@acoustic-content-sdk/cli
Version:
Command line utility for the Acoustic Content SDK.
627 lines (610 loc) • 22.3 kB
JavaScript
import { createChalkLoggerService, canonicalizeAssets, createReadDirectory, writeFiles, logFileDescriptor, generateDataOverlay, createReadTextFile, generateKeys, generateLayout, generateLayouts } from '@acoustic-content-sdk/tooling';
import { isString, isStringArray, NOOP_LOGGER_SERVICE, rxPipe } from '@acoustic-content-sdk/utils';
import { normalize, isAbsolute, join, parse, relative } from 'path';
import { cwd, argv } from 'process';
import { ignoreElements } from 'rxjs/operators';
import { createVersionString } from '@acoustic-content-sdk/api';
import { Command } from 'commander';
import { generateFeatureModule } from '@acoustic-content-sdk/tooling-feature-module';
import { generateMessages } from '@acoustic-content-sdk/tooling-messages';
import { generateTypes } from '@acoustic-content-sdk/tooling-types';
/**
* @fileoverview added by tsickle
* Generated from: commands/utils.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} aValue
* @return {?}
*/
function splitParams(aValue) {
return isString(aValue)
? aValue.split(',')
: isStringArray(aValue)
? aValue
: undefined;
}
/**
* @param {?} aRoot
* @param {?} aDir
* @return {?}
*/
function getFullPath(aRoot, aDir) {
return normalize(isAbsolute(aDir) ? aDir : join(aRoot, aDir));
}
/**
* @fileoverview added by tsickle
* Generated from: commands/canonicalize.assets.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const CANONICALIZE_ASSETS = 'canonicalize-assets';
/**
* @param {?} program
* @return {?}
*/
function canonicalizeAssetsCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command(CANONICALIZE_ASSETS)
.description('Rewrites the wchtools data folder in a canonical format.')
.option('--data <data>', 'Location of the data directory.')
.option('--dir <dir>', 'Location of the target directory. Defaults to the data directory.')
.option('--include <include>', 'Regular expression of the types to include.')
.option('--exclude <exclude>', 'Regular expression of the types to exclude.')
.action((/**
* @param {?} aLayoutName
* @return {?}
*/
(aLayoutName) => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
/** @type {?} */
const dataDir = normalize(cmd.data || join(currentDir, 'data'));
// target dire
/** @type {?} */
const dstDir = normalize(cmd.dir || dataDir);
// log this
logger.info('dataDir', dataDir, 'dstDir', dstDir);
// execute the command
/** @type {?} */
const command = canonicalizeAssets({
data: '/',
include: splitParams(cmd.include),
exclude: splitParams(cmd.exclude)
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadDirectory(dataDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.data.overlay.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const GENERATE_DATA_OVERLAY_COMMAND = 'generate-data-overlay';
/**
* Generates a data overlay of the wchtools folders referenced by a node module and all
* of its dependencies. The resulting folder can then be used with {\@link https://www.npmjs.com/package/wchtools-cli|wchtools}.
*
* @param {?} program - the commander instance to attach the command to
* @return {?} the commander instance
*/
function generateDataOverlayCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command(`${GENERATE_DATA_OVERLAY_COMMAND}`)
.description('Generates an overlay of wchtools data folders for referenced modules.')
.option('--dir <dir>', 'Location of the target directory. Defaults to "temp".')
.option('--src <dir>', 'Location of the directory that contains the package.json to analyze. Defaults to the current working directory.')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
// target dir
/** @type {?} */
const fullDstDir = getFullPath(currentDir, cmd.dir || 'temp');
// source dir
/** @type {?} */
const fullSrcDir = getFullPath(currentDir, cmd.src || '');
// root
const { root: srcRoot } = parse(fullSrcDir);
const { root: dstRoot } = parse(fullDstDir);
// decode relative paths
/** @type {?} */
const dstDir = relative(dstRoot, fullDstDir);
/** @type {?} */
const srcDir = relative(srcRoot, fullSrcDir);
// log this
logger.info('srcDir', srcDir);
logger.info('dstDir', dstDir);
// execute the command
/** @type {?} */
const command = generateDataOverlay({
src: srcDir
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadTextFile(srcRoot), createReadDirectory(dstRoot), logSvc), writeFiles(fullDstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.keys.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} program
* @return {?}
*/
function generateKeysCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command('generate-keys')
.description('Generates keys into the content.')
.option('--data <data>', 'Location of the data directory.')
.option('--dir <dir>', 'Location of the target directory. Defaults to the data directory.')
.option('--include <include>', 'Regular expression of the content items to include.')
.option('--exclude <exclude>', 'Regular expression of the content items to exclude.')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
/** @type {?} */
const dataDir = normalize(cmd.data || join(currentDir, 'data'));
// target dire
/** @type {?} */
const dstDir = normalize(cmd.dir || dataDir);
// log this
logger.info('dataDir', dataDir, 'dstDir', dstDir);
// execute the command
/** @type {?} */
const command = generateKeys({
data: '/',
include: splitParams(cmd.include),
exclude: splitParams(cmd.exclude)
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadDirectory(dataDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.layout.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const GENERATE_LAYOUT_COMMAND = 'generate-layout';
/**
* @param {?} program
* @return {?}
*/
function generateLayoutCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command(`${GENERATE_LAYOUT_COMMAND} [name]`)
.description('Generates a layout for a particular content type.')
.option('--data <data>', 'Location of the data directory.')
.requiredOption('--type <type>', 'Name or ID of the type.')
.option('--dir <dir>', 'Location of the target directory. Defaults to the data directory.')
.option('--templateType <templateType>', 'Type of the rendering template to use, can be "angular" or "handlebars".')
.option('--tags <tags>', 'Tags to add to the new layouts.')
.action((/**
* @param {?} aLayoutName
* @return {?}
*/
(aLayoutName) => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
/** @type {?} */
const dataDir = normalize(cmd.data || join(currentDir, 'data'));
// target dire
/** @type {?} */
const dstDir = normalize(cmd.dir || dataDir);
// log this
logger.info('dataDir', dataDir, 'dstDir', dstDir);
// execute the command
/** @type {?} */
const command = generateLayout({
data: '/',
type: cmd.type,
name: aLayoutName,
tags: splitParams(cmd.tags),
templateType: cmd.templateType
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadDirectory(dataDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.layouts.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} program
* @return {?}
*/
function generateLayoutsCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command('generate-layouts')
.description('Generates layouts and layout mappings based on type information in a batch in the wchtools folder. The names of the artifacts are derived from the type names.')
.option('--data <data>', 'Location of the data directory.')
.option('--dir <dir>', 'Location of the target directory. Defaults to the data directory.')
.option('--include <include>', 'Regular expression of the types to include.')
.option('--exclude <exclude>', 'Regular expression of the types to exclude.')
.option('--templateType <templateType>', 'Type of the rendering template to use, can be "angular" or "handlebars".')
.option('--tags <tags>', 'Tags to add to the new layouts.')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
/** @type {?} */
const dataDir = normalize(cmd.data || join(currentDir, 'data'));
// target dire
/** @type {?} */
const dstDir = normalize(cmd.dir || dataDir);
// log this
logger.info('dataDir', dataDir, 'dstDir', dstDir);
// execute the command
/** @type {?} */
const command = generateLayouts({
data: '/',
tags: splitParams(cmd.tags),
include: splitParams(cmd.include),
exclude: splitParams(cmd.exclude),
templateType: cmd.templateType
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadDirectory(dataDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: version.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* Version and build number of the package
* @type {?}
*/
const VERSION = { version: { major: '9', minor: '0', patch: '10076', branch: 'master' }, build: new Date(1585229427693) };
/**
* Module name
* @type {?}
*/
const MODULE = '@acoustic-content-sdk/cli';
/**
* @fileoverview added by tsickle
* Generated from: commands/version.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @param {?} program
* @return {?}
*/
function versionCommand(program) {
// default
/** @type {?} */
const cmd = program
.command('version', { isDefault: true })
.description('Show version info.')
.action((/**
* @return {?}
*/
() => {
// logger
/** @type {?} */
const logSvc = createChalkLoggerService();
/** @type {?} */
const logger = logSvc.get(cmd.name());
// version
logger.info(MODULE, createVersionString(VERSION));
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.feature.module.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const GENERATE_FEATURE_MODULE_COMMAND = 'generate-feature-module';
/**
*
*
* @param {?} program - the commander instance to attach the command to
* @return {?} the commander instance
*/
function generateFeatureModuleCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command(`${GENERATE_FEATURE_MODULE_COMMAND}`)
.description('Adds support for the ng-add schematic to feature modules.')
.option('--src <dir>', 'Location of the directory that contains the package.json to analyze. Defaults to the current working directory.')
.requiredOption('--module <modules>', 'NgModule to export from the feature module. May be a comma separated list.')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
// module
/** @type {?} */
const module = cmd.module;
// source dir
/** @type {?} */
const srcDir = getFullPath(currentDir, cmd.src || '');
// log this
logger.info('module', module);
logger.info('srcDir', srcDir);
// execute the command
/** @type {?} */
const command = generateFeatureModule({
module
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadTextFile(srcDir), logSvc), writeFiles(srcDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.messages.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const GENERATE_MESSAGES_COMMAND = 'generate-messages';
/**
* Returns a command that generates a typescript message file from NLS JSON input sources.
*
* @param {?} program - the driver
* @return {?} the command
*/
function generateMessagesCommand(program) {
// register our commands
/** @type {?} */
const messageCommand = program
.command(GENERATE_MESSAGES_COMMAND)
.description('Generate translated messages.')
.option('--src <directory>', 'Source directory')
.option('--dir <directory>', 'Target directory')
.option('--default <default>', 'Default locale')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(messageCommand.name());
// write callback
/** @type {?} */
const srcDir = messageCommand.src || cwd();
/** @type {?} */
const dstDir = messageCommand.dir || cwd();
/** @type {?} */
const defaultLocale = messageCommand.default;
// log this
logger.info('srcDir', srcDir);
logger.info('dstDir', dstDir);
logger.info('defaultLocale', defaultLocale);
// read callback
/** @type {?} */
const command = generateMessages({ dir: '/', default: defaultLocale });
// execute the command
/** @type {?} */
const cmp$ = rxPipe(command(createReadDirectory(srcDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return cmp$.toPromise();
}));
return messageCommand;
}
/**
* @fileoverview added by tsickle
* Generated from: commands/generate.types.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const GENERATE_TYPES_COMMAND = 'generate-types';
/**
* Generates typings and helper methods based on a set of content type definitions.
*
* @param {?} program
* @return {?}
*/
function generateTypesCommand(program) {
// register our commands
/** @type {?} */
const cmd = program
.command(GENERATE_TYPES_COMMAND)
.description('Generates typings and helper methods based on a set of content type definitions.')
.option('--data <data>', 'Location of the data directory.')
.option('--dir <dir>', 'Location of the target directory. Defaults to the "src" directory.')
.option('--include <include>', 'Regular expression of the types to include.')
.option('--exclude <exclude>', 'Regular expression of the types to exclude.')
.action((/**
* @return {?}
*/
() => {
// service
/** @type {?} */
const logSvc = program.verbose
? createChalkLoggerService()
: NOOP_LOGGER_SERVICE;
// logger
/** @type {?} */
const logger = logSvc.get(cmd.name());
// write callback
/** @type {?} */
const currentDir = cwd();
/** @type {?} */
const dataDir = normalize(cmd.data || join(currentDir, 'data'));
// target dire
/** @type {?} */
const dstDir = normalize(cmd.dir || currentDir);
// log this
logger.info('dataDir', dataDir);
logger.info('dstDir', dstDir);
// execute the command
/** @type {?} */
const command = generateTypes({
data: '/',
include: splitParams(cmd.include),
exclude: splitParams(cmd.exclude)
});
// execute the command
/** @type {?} */
const files$ = rxPipe(command(createReadDirectory(dataDir), createReadTextFile(dataDir), logSvc), writeFiles(dstDir), logFileDescriptor(), ignoreElements());
// subscribe
return files$.toPromise();
}));
// ok
return cmd;
}
/**
* @fileoverview added by tsickle
* Generated from: driver/index.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/** @type {?} */
const NAME = 'acoustic-content-sdk-cli';
/**
* @param {?=} aArgs
* @return {?}
*/
function runProgram(aArgs = argv) {
// construct the wrapper
/** @type {?} */
const program = new Command(NAME)
.version(createVersionString(VERSION))
.option('-v, --verbose', 'print additional logs');
versionCommand(program);
generateLayoutsCommand(program);
generateLayoutCommand(program);
generateKeysCommand(program);
generateDataOverlayCommand(program);
generateMessagesCommand(program);
generateTypesCommand(program);
generateFeatureModuleCommand(program);
canonicalizeAssetsCommand(program);
return program.parse(aArgs);
}
/**
* @fileoverview added by tsickle
* Generated from: public_api.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
/**
* @fileoverview added by tsickle
* Generated from: acoustic-content-sdk-cli.ts
* @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc
*/
export { VERSION, canonicalizeAssetsCommand, generateDataOverlayCommand, generateKeysCommand, generateLayoutCommand, generateLayoutsCommand, runProgram, versionCommand };
//# sourceMappingURL=acoustic-content-sdk-cli.js.map