@canopycanopycanopy/b-ber-cli 1.2.13-react-reader.64 → 1.2.13-react-reader.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,19 @@
1
1
  "use strict";
2
2
 
3
+ var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
4
+
5
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
6
+
7
+ var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
8
+
9
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
10
+
11
+ var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
12
+
13
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
14
+
15
+ var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
16
+
3
17
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
18
 
5
19
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
@@ -14,6 +28,12 @@ var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-sta
14
28
 
15
29
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
16
30
 
31
+ var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
32
+
33
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
34
+
35
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
36
+
17
37
  var _path = _interopRequireDefault(require("path"));
18
38
 
19
39
  var _bBerTasks = require("@canopycanopycanopy/b-ber-tasks");
@@ -30,25 +50,65 @@ var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
30
50
 
31
51
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
32
52
 
33
- // note leading pipe - to ensure we can run the `all` command without arguments
53
+ var _configOptions = require("../lib/config-options");
54
+
55
+ const _excluded = ["_", "$0", "config"];
56
+
57
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
58
+
59
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
60
+
61
+ // Leading pipe ensures that the `all` command can be run without arguments
34
62
  const command = 'build [|epub|mobi|pdf|reader|sample|web]';
35
63
  const describe = 'Build a project';
36
64
 
37
- const handler = argv => {
65
+ const noop = () => {};
66
+
67
+ const handler = async argv => {
38
68
  process.env.NODE_ENV = process.env.NODE_ENV || 'development';
39
- const sequence = (0, _createBuildSequence.default)(argv);
40
- const subSequence = (0, _reduce.default)(sequence).call(sequence, (a, c) => (0, _concat.default)(a).call(a, ..._sequences.default[c]), []);
69
+ const {
70
+ _: desiredSequences,
71
+ $0,
72
+ config
73
+ } = argv,
74
+ configOptions = (0, _objectWithoutProperties2.default)(argv, _excluded);
75
+ const sequence = (0, _createBuildSequence.default)(desiredSequences);
76
+ const subSequence = (0, _reduce.default)(sequence).call(sequence, (a, c) => (0, _concat.default)(a).call(a, ..._sequences.default[c]), []); // Set up the config object that's going to be passed into the `init` function
77
+
78
+ let projectConfig = {}; // Check if a config files has been specified
79
+
80
+ if (config) projectConfig = await (0, _configOptions.parseConfigFile)(config);
81
+ projectConfig = _objectSpread(_objectSpread({}, projectConfig), configOptions);
41
82
 
42
83
  _State.default.update('sequence', subSequence);
43
84
 
44
85
  _bBerLogger.default.registerSequence(_State.default, command, subSequence);
45
86
 
46
87
  const run = buildTasks => {
47
- const build = buildTasks.shift();
88
+ const build = buildTasks.shift(); // Reset any previous changes to state and update the build type
48
89
 
49
90
  _State.default.reset();
50
91
 
51
- _State.default.update('build', build);
92
+ _State.default.update('build', build); // Apply the config options that may have been passed in via CLI flags
93
+
94
+
95
+ for (const [key, val] of (0, _entries.default)(projectConfig)) {
96
+ if (!_State.default.has(`config.${key}`)) {
97
+ _bBerLogger.default.warn('Invalid configuration option [%s]', key);
98
+
99
+ continue;
100
+ }
101
+
102
+ if (_configOptions.blacklistedConfigOptions.has(key)) {
103
+ _bBerLogger.default.warn('Disallowed configuration option [%s]', key);
104
+
105
+ continue;
106
+ }
107
+
108
+ _bBerLogger.default.notice('Applying configuration option [%s]:[%s]', key, val);
109
+
110
+ _State.default.update(`config.${key}`, val);
111
+ }
52
112
 
53
113
  return (0, _bBerTasks.serialize)(_sequences.default[build]).then(() => {
54
114
  if (buildTasks.length) run(buildTasks);
@@ -63,7 +123,7 @@ const handler = argv => {
63
123
  }).then(() => run(sequence)).catch(console.error);
64
124
  };
65
125
 
66
- const builder = yargs => yargs.command('', 'Build all formats', () => {}, handler).command('epub', 'Build an Epub', () => {}, handler).command('mobi', 'Build a Mobi', () => {}, handler).command('pdf', 'Build a PDF', () => {}, handler).command('reader', 'Build for the b-ber-reader format', () => {}, handler).command('sample', 'Build a sample Epub', () => {}, handler).command('web', 'Build for web', () => {}, handler).command('xml', 'Build for XML', () => {}, handler).help('h').alias('h', 'help');
126
+ const builder = yargs => (0, _configOptions.withConfigOptions)(yargs).command('', 'Build all formats', noop, handler).command('epub', 'Build an Epub', noop, handler).command('mobi', 'Build a Mobi', noop, handler).command('pdf', 'Build a PDF', noop, handler).command('reader', 'Build for the b-ber-reader format', noop, handler).command('sample', 'Build a sample Epub', noop, handler).command('web', 'Build for web', noop, handler).command('xml', 'Build for XML', noop, handler).help('h').alias('h', 'help');
67
127
 
68
128
  var _default = {
69
129
  command,
@@ -24,22 +24,22 @@ _Object$defineProperty(exports, "__esModule", {
24
24
 
25
25
  exports.default = void 0;
26
26
 
27
+ var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
28
+
27
29
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
28
30
 
29
31
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
30
32
 
31
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
32
-
33
- var _path = _interopRequireDefault(require("path"));
33
+ var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
34
34
 
35
35
  var _bBerTasks = require("@canopycanopycanopy/b-ber-tasks");
36
36
 
37
37
  var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
38
38
 
39
- var _YamlAdaptor = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/YamlAdaptor"));
40
-
41
39
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
42
40
 
41
+ var _configOptions = require("../lib/config-options");
42
+
43
43
  const _excluded = ["_", "$0", "name", "config"];
44
44
 
45
45
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -49,74 +49,10 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
49
49
  const command = 'new <name>';
50
50
  const describe = 'Create a new project';
51
51
 
52
- const builder = yargs => yargs.positional('name', {
52
+ const builder = yargs => (0, _configOptions.withConfigOptions)(yargs.positional('name', {
53
53
  describe: 'New project name',
54
54
  type: 'string'
55
- }).option('env', {
56
- describe: 'The default build environment',
57
- type: 'string' // default: 'development',
58
-
59
- }).option('theme', {
60
- describe: 'Default theme name',
61
- type: 'string' // default: 'b-ber-theme-serif',
62
-
63
- }).option('src', {
64
- describe: 'The name of the source directory',
65
- type: 'string' // default: 'src',
66
-
67
- }).option('dist', {
68
- describe: 'The name of the dist directory',
69
- type: 'string' // default: 'dist',
70
-
71
- }).option('cache', {
72
- describe: 'Whether to enable caching',
73
- type: 'boolean' // default: false,
74
-
75
- }).option('themes_directory', {
76
- describe: 'Relative or absolute path to the directory for third-party themes',
77
- type: 'string' // default: './themes',
78
-
79
- }).option('ignore', {
80
- describe: 'Array of files or folders to ignore during the build',
81
- type: 'array' // default: [],
82
-
83
- }).option('base_path', {
84
- describe: 'Base path appended to the URL for the reader build',
85
- type: 'string' // default: '/',
86
-
87
- }).option('remote_url', {
88
- describe: 'URL at which the reader build will be made public',
89
- type: 'string' // default: 'http://localhost:4000/',
90
-
91
- }).option('reader_url', {
92
- describe: 'URL that hosts the assets for the reader reader build',
93
- type: 'string' // default: 'http://localhost:4000/project-reader',
94
-
95
- }).option('base_url', {
96
- describe: 'URL to map assets for the web build',
97
- type: 'string' // default: '',
98
-
99
- }).option('bucket_url', {
100
- describe: 'The S3 bucket URL where the remote project will be deployed to if hosting on S3',
101
- type: 'string' // default: '',
102
-
103
- }).option('private', {
104
- describe: 'If the web and reader builds should be discoverable by search engines',
105
- type: 'boolean' // default: false,
106
-
107
- }).option('remote_javascripts', {
108
- describe: 'Remotely hosted JavaScript files for the reader',
109
- type: 'array' // default: [],
110
-
111
- }).option('remote_stylesheets', {
112
- describe: 'Remotely hosted stylesheets files for the reader',
113
- type: 'array' // default: [],
114
-
115
- }).option('config', {
116
- describe: 'Path to a JSON or YAML configuration file that will extend the base configuration',
117
- type: 'string' // default: '',
118
-
119
- }).fail((msg, err) => (0, _utils.fail)(msg, err, yargs)).help('h').alias('h', 'help').usage(`\nUsage: $0 new "My Project"\n\n${describe}`);
55
+ })).fail((msg, err) => (0, _utils.fail)(msg, err, yargs)).help('h').alias('h', 'help').usage(`\nUsage: $0 new "My Project"\n\n${describe}`);
120
56
 
121
57
  const handler = async argv => {
122
58
  // Extract CLI options and get the config file option in case there is one
@@ -126,42 +62,32 @@ const handler = async argv => {
126
62
  name,
127
63
  config
128
64
  } = argv,
129
- rest = (0, _objectWithoutProperties2.default)(argv, _excluded); // Set up the config object that's going to be passed into the `init` function
65
+ configOptions = (0, _objectWithoutProperties2.default)(argv, _excluded); // Set up the config object that's going to be passed into the `init` function
130
66
 
131
67
  let projectConfig = {}; // Check if a config files has been specified
132
68
 
133
- if (config) {
134
- const ext = _path.default.extname(config);
69
+ if (config) projectConfig = await (0, _configOptions.parseConfigFile)(config); // Override the values specified in the config file with values
70
+ // that have been explicitly provided on the CLI. Allows using the
71
+ // config file as a template that can be overridden, e.g.,
72
+ // bber new foo --config my-generic-conf.yaml --base_path /foo
135
73
 
136
- const configPath = _path.default.resolve(process.cwd(), config);
74
+ projectConfig = _objectSpread(_objectSpread({}, projectConfig), configOptions); // Remove blacklisted and unsupported config options
137
75
 
138
- if (!(await _fsExtra.default.pathExists(config))) {
139
- _bBerLogger.default.error('Could not find config at %s', configPath);
140
- }
76
+ for (const [key] of (0, _entries.default)(projectConfig)) {
77
+ if (!_State.default.has(`config.${key}`)) {
78
+ _bBerLogger.default.warn('Invalid configuration option [%s]', key);
141
79
 
142
- if (/^\.(?:ya?ml|json)/i.test(ext) === false) {
143
- _bBerLogger.default.error('Config file must have a .json or .yaml/.yml file extension');
80
+ delete projectConfig[key];
81
+ continue;
144
82
  }
145
83
 
146
- const contents = await _fsExtra.default.readFile(config);
84
+ if (_configOptions.blacklistedConfigOptions.has(key)) {
85
+ _bBerLogger.default.warn('Disallowed configuration option [%s]', key);
147
86
 
148
- if (/^\.ya?ml/i.test(ext)) {
149
- projectConfig = _YamlAdaptor.default.parse(contents);
150
- } else {
151
- projectConfig = JSON.parse(contents);
87
+ delete projectConfig[key];
88
+ continue;
152
89
  }
153
- } // Override the values specified in the config file with values
154
- // that have been explicitly provided on the CLI. Allows using the
155
- // config file as a template that can be overridden, e.g.,
156
- // bber new foo --config my-generic-conf.yaml --base_path /foo
157
-
158
-
159
- projectConfig = _objectSpread(_objectSpread({}, projectConfig), rest); // Attributes not currently configurable via the CLI:
160
- // ibooks_specified_fonts
161
- // autoprefixer_options
162
- // base_url
163
- // downloads
164
- // ui_options
90
+ }
165
91
 
166
92
  const initializer = new _bBerTasks.init({
167
93
  name,
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+
5
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
+
7
+ _Object$defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+
11
+ exports.parseConfigFile = exports.blacklistedConfigOptions = void 0;
12
+ exports.withConfigOptions = withConfigOptions;
13
+
14
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
15
+
16
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
17
+
18
+ var _path = _interopRequireDefault(require("path"));
19
+
20
+ var _YamlAdaptor = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/YamlAdaptor"));
21
+
22
+ var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
23
+
24
+ // Attributes not currently configurable via the CLI:
25
+ // ibooks_specified_fonts always set to `true`
26
+ // autoprefixer_options no JSON support
27
+ // downloads no JSON support
28
+ // ui_options no JSON support
29
+ function withConfigOptions(yargs) {
30
+ return yargs.option('env', {
31
+ describe: 'The default build environment',
32
+ type: 'string' // default: 'development',
33
+
34
+ }).option('theme', {
35
+ describe: 'Default theme name',
36
+ type: 'string' // default: 'b-ber-theme-serif',
37
+
38
+ }).option('src', {
39
+ describe: 'The name of the source directory',
40
+ type: 'string' // default: 'src',
41
+
42
+ }).option('dist', {
43
+ describe: 'The name of the dist directory',
44
+ type: 'string' // default: 'dist',
45
+
46
+ }).option('cache', {
47
+ describe: 'Whether to enable caching',
48
+ type: 'boolean' // default: false,
49
+
50
+ }).option('themes_directory', {
51
+ describe: 'Relative or absolute path to the directory for third-party themes',
52
+ type: 'string' // default: './themes',
53
+
54
+ }).option('ignore', {
55
+ describe: 'Array of files or folders to ignore during the build',
56
+ type: 'array' // default: [],
57
+
58
+ }).option('base_path', {
59
+ describe: 'Base path appended to the URL for the reader build',
60
+ type: 'string' // default: '/',
61
+
62
+ }).option('remote_url', {
63
+ describe: 'URL at which the reader build will be made public',
64
+ type: 'string' // default: 'http://localhost:4000/',
65
+
66
+ }).option('reader_url', {
67
+ describe: 'URL that hosts the assets for the reader reader build',
68
+ type: 'string' // default: 'http://localhost:4000/project-reader',
69
+
70
+ }).option('base_url', {
71
+ describe: 'URL to map assets for the web build',
72
+ type: 'string' // default: '',
73
+
74
+ }).option('bucket_url', {
75
+ describe: 'The S3 bucket URL where the remote project will be deployed to if hosting on S3',
76
+ type: 'string' // default: '',
77
+
78
+ }).option('private', {
79
+ describe: 'If the web and reader builds should be discoverable by search engines',
80
+ type: 'boolean' // default: false,
81
+
82
+ }).option('remote_javascripts', {
83
+ describe: 'Remotely hosted JavaScript files for the reader',
84
+ type: 'array' // default: [],
85
+
86
+ }).option('remote_stylesheets', {
87
+ describe: 'Remotely hosted stylesheets files for the reader',
88
+ type: 'array' // default: [],
89
+
90
+ }).option('config', {
91
+ describe: 'Path to a JSON or YAML configuration file that will extend the base configuration',
92
+ type: 'string' // default: '',
93
+
94
+ });
95
+ }
96
+
97
+ const blacklistedConfigOptions = new _set.default(['ibooks_specified_fonts', 'autoprefixer_options', 'downloads', 'ui_options']);
98
+ exports.blacklistedConfigOptions = blacklistedConfigOptions;
99
+
100
+ const parseConfigFile = async configFile => {
101
+ const ext = _path.default.extname(configFile);
102
+
103
+ const configPath = _path.default.resolve(process.cwd(), configFile);
104
+
105
+ if (!(await _fsExtra.default.pathExists(configPath))) {
106
+ _bBerLogger.default.error(`Could not find config at [${configPath}]`);
107
+ }
108
+
109
+ if (/^\.(?:ya?ml|json)/i.test(ext) === false) {
110
+ _bBerLogger.default.error('Config file must have a .json or .yaml/.yml file extension');
111
+ }
112
+
113
+ const contents = await _fsExtra.default.readFile(configPath);
114
+ if (/^\.ya?ml/i.test(ext)) return _YamlAdaptor.default.parse(contents);
115
+ return JSON.parse(contents);
116
+ };
117
+
118
+ exports.parseConfigFile = parseConfigFile;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-cli",
3
- "version": "1.2.13-react-reader.64+d46c0879",
3
+ "version": "1.2.13-react-reader.68+e7d3e3df",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -25,7 +25,7 @@
25
25
  "@canopycanopycanopy/b-ber-lib": "1.2.15",
26
26
  "@canopycanopycanopy/b-ber-logger": "1.2.12",
27
27
  "@canopycanopycanopy/b-ber-shapes-sequences": "1.2.12",
28
- "@canopycanopycanopy/b-ber-tasks": "1.2.13-react-reader.64+d46c0879",
28
+ "@canopycanopycanopy/b-ber-tasks": "1.2.15",
29
29
  "@canopycanopycanopy/b-ber-templates": "1.2.15",
30
30
  "fs-extra": "^8.1.0",
31
31
  "lodash": "^4.17.21",
@@ -59,5 +59,5 @@
59
59
  "url": "https://maxwellsimmer.com"
60
60
  }
61
61
  ],
62
- "gitHead": "d46c08797de554f0faf90c3c02300a9079fbb5e6"
62
+ "gitHead": "e7d3e3df3e8791944b2be202edd928217793c1d8"
63
63
  }