This repository was archived by the owner on Feb 26, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathadd.js
More file actions
49 lines (42 loc) · 1.85 KB
/
Copy pathadd.js
File metadata and controls
49 lines (42 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require('shelljs/global');
// Utilities from shelljs
// /* globals mkdir */
// const fs = require('fs');
// const path = require('path');
const util = require('../util');
const { stripIndent } = require('common-tags');
module.exports = function (program, version) {
program
.command('add <module-type> <module-name>')
.description(stripIndent`
Add an Apostrophe module with boilerplate configuration to get you started.
- Add "module" for <module type> to add a generic module.
- Add "piece" for <module type> to add a piece-type module.
- Add "widget" for <module type> to add a widget-type module.
Example: \`apos add piece article\`
`)
.option('--page', 'Used with the "piece" module type. Also add a corresponding piece page module.')
.option('--widget', 'Used with the "piece" module type. Also add a corresponding piece widget module (A2 only).')
.option('--player', 'Used with the "widget" module type. Also add a Javascript player file for browser-side code.')
.action(async function(type, moduleName, options) {
const allowedTypes = [ 'module', 'piece', 'widget' ];
if (!allowedTypes.includes(type)) {
await util.error('add module', `Module type ${type} was not recognized. Options include "module", "piece", and "widget".`);
return false;
}
const appPath = await util.getAppPath(`add ${type}`);
if (!appPath) {
return false;
}
const majorVersion = await util.getMajorVersion('add', version);
if (!majorVersion) {
await util.error('add module', 'Error finding the version of Apostrophe installed in this project');
return false;
}
const success = require(`./add-types/${type}`)(moduleName, majorVersion, options);
if (success) {
await util.success(`add ${type}`);
}
return true;
});
};