@zimbra/zimlet-cli 12.13.0 → 14.2.0
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.
- package/.browserslistrc +1 -0
- package/dist/cli.js +11 -17
- package/dist/commands/create.js +206 -324
- package/dist/commands/package.js +144 -93
- package/dist/entry.js +14 -12
- package/dist/index.js +89 -114
- package/dist/lib/async-command.js +8 -14
- package/dist/lib/setup.js +55 -133
- package/dist/lib/webpack/transform-config.js +8 -8
- package/dist/shims/@apollo/client/index.js +92 -82
- package/dist/shims/@apollo/client/react/components/index.js +6 -6
- package/dist/shims/@apollo/client/react/hoc/index.js +8 -8
- package/dist/shims/@apollo/client/react/index.js +16 -16
- package/dist/shims/@zimbra-client/blocks/index.js +28 -28
- package/dist/shims/@zimbra-client/browser/index.js +4 -4
- package/dist/shims/@zimbra-client/components/index.js +53 -51
- package/dist/shims/@zimbra-client/constants/index.js +7 -7
- package/dist/shims/@zimbra-client/enhancers/index.js +10 -10
- package/dist/shims/@zimbra-client/errors/index.js +5 -5
- package/dist/shims/@zimbra-client/graphql/index.js +29 -29
- package/dist/shims/@zimbra-client/hooks/graphql/index.js +8 -8
- package/dist/shims/@zimbra-client/hooks/index.js +8 -8
- package/dist/shims/@zimbra-client/platform/index.js +5 -5
- package/dist/shims/@zimbra-client/util/contacts/index.js +4 -4
- package/dist/shims/@zimbra-client/util/index.js +15 -13
- package/dist/shims/@zimbra-client/util/redux/index.js +8 -8
- package/dist/shims/clipboard-polyfill/index.js +4 -4
- package/dist/shims/index.js +2 -2
- package/dist/shims/moment/index.js +43 -43
- package/dist/shims/preact/compat/index.js +40 -52
- package/dist/shims/preact/hooks/index.js +14 -14
- package/dist/shims/preact/index.js +15 -15
- package/dist/shims/preact-context-provider/index.js +6 -6
- package/dist/shims/preact-i18n/index.js +12 -12
- package/dist/shims/preact-pwa-install/index.js +3 -3
- package/dist/shims/preact-render-to-string/index.js +5 -5
- package/dist/shims/preact-router/index.js +9 -9
- package/dist/shims/preact-router/match/index.js +4 -4
- package/dist/shims/react-redux/index.js +16 -16
- package/dist/shims/recompose/index.js +46 -46
- package/dist/shims/redux-actions/index.js +9 -9
- package/dist/util.js +11 -11
- package/dist/zimlet-style-loader.js +8 -4
- package/package-lock.json +6400 -6926
- package/package.json +41 -44
package/.browserslistrc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
last 2 Chrome versions, last 2 Firefox versions, last 2 Safari versions, last 2 ChromeAndroid versions, last 2 iOS versions, last 2 Edge versions
|
package/dist/cli.js
CHANGED
|
@@ -11,22 +11,16 @@ var _package = _interopRequireDefault(require("./commands/package"));
|
|
|
11
11
|
|
|
12
12
|
var _index = _interopRequireDefault(require("./index"));
|
|
13
13
|
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
19
|
-
|
|
20
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
21
|
-
|
|
22
|
-
var optionsForAllCommands = {
|
|
16
|
+
const optionsForAllCommands = {
|
|
23
17
|
config: {
|
|
24
18
|
type: 'string',
|
|
25
19
|
description: 'Path to a custom config file',
|
|
26
|
-
|
|
20
|
+
default: './zimlet.config.js'
|
|
27
21
|
}
|
|
28
22
|
};
|
|
29
|
-
_yargs
|
|
23
|
+
_yargs.default.command(_create.default).command('watch', 'Start a development server', { ...optionsForAllCommands,
|
|
30
24
|
port: {
|
|
31
25
|
type: 'number',
|
|
32
26
|
description: 'Port of dev server',
|
|
@@ -34,13 +28,13 @@ _yargs["default"].command(_create["default"]).command('watch', 'Start a developm
|
|
|
34
28
|
},
|
|
35
29
|
https: {
|
|
36
30
|
type: 'boolean',
|
|
37
|
-
|
|
31
|
+
default: true,
|
|
38
32
|
description: 'Protocol of dev server. https if true, http if false'
|
|
39
33
|
}
|
|
40
|
-
}
|
|
34
|
+
}, argv => {
|
|
41
35
|
argv.watch = true;
|
|
42
36
|
runCli(argv);
|
|
43
|
-
}).command(['build'], 'Compile a zimlet',
|
|
37
|
+
}).command(['build'], 'Compile a zimlet', { ...optionsForAllCommands,
|
|
44
38
|
dest: {
|
|
45
39
|
type: 'string',
|
|
46
40
|
defaultDescription: './build',
|
|
@@ -51,15 +45,15 @@ _yargs["default"].command(_create["default"]).command('watch', 'Start a developm
|
|
|
51
45
|
defaultDescription: '/',
|
|
52
46
|
description: 'Public path you would like to download resources from, e.g. "/service/zimlet/com_example_zimlet/"'
|
|
53
47
|
}
|
|
54
|
-
}
|
|
48
|
+
}, argv => {
|
|
55
49
|
argv.production = true;
|
|
56
50
|
runCli(argv);
|
|
57
|
-
}).command(_package
|
|
51
|
+
}).command(_package.default).demandCommand(1, 'A command must be specified').usage('Zimlet client tool for developing and building Zimlets.\n\nType "zimlet [commmand] --help" for command specific usage information').help().argv;
|
|
58
52
|
|
|
59
53
|
function runCli(argv) {
|
|
60
|
-
(0, _index
|
|
54
|
+
(0, _index.default)(argv, (err, result) => {
|
|
61
55
|
if (err) process.stderr.write(err);else if (result) process.stdout.write(result);
|
|
62
|
-
setTimeout(
|
|
56
|
+
setTimeout(() => {
|
|
63
57
|
process.exit(err ? 1 : 0);
|
|
64
58
|
}, 10);
|
|
65
59
|
});
|
package/dist/commands/create.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports
|
|
6
|
+
exports.default = void 0;
|
|
7
7
|
|
|
8
8
|
var _ora = _interopRequireDefault(require("ora"));
|
|
9
9
|
|
|
@@ -25,50 +25,34 @@ var _setup = require("./../lib/setup");
|
|
|
25
25
|
|
|
26
26
|
var _asyncCommand = _interopRequireDefault(require("../lib/async-command"));
|
|
27
27
|
|
|
28
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : {
|
|
29
|
-
|
|
30
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
31
|
-
|
|
32
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
33
|
-
|
|
34
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
35
|
-
|
|
36
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
37
|
-
|
|
38
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
39
|
-
|
|
40
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
28
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
41
29
|
|
|
42
30
|
// This command borrows heavily from preact-cli's create command
|
|
43
31
|
// https://github.com/developit/preact-cli
|
|
44
|
-
|
|
32
|
+
const ORG = 'zimbra'; //repo we want as an alias for 'default'?
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
34
|
+
const DEFAULT_REPO = 'zimbra/zm-x-zimlet-template-default';
|
|
35
|
+
const RGX = /\.(woff2?|ttf|eot|jpe?g|ico|png|gif|mp4|mov|ogg|webm)(\?.*)?$/i;
|
|
48
36
|
|
|
49
|
-
|
|
50
|
-
return RGX.test(str);
|
|
51
|
-
};
|
|
37
|
+
const isMedia = str => RGX.test(str);
|
|
52
38
|
|
|
53
|
-
|
|
54
|
-
return str.charAt(0).toUpperCase() + str.substring(1);
|
|
55
|
-
};
|
|
39
|
+
const capitalize = str => str.charAt(0).toUpperCase() + str.substring(1);
|
|
56
40
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
41
|
+
const templateDesc = 'Remote template to clone (user/repo#tag)',
|
|
42
|
+
destDesc = 'Directory to create the zimlet',
|
|
43
|
+
nameDesc = 'The zimlet\'s name',
|
|
44
|
+
forceDesc = 'Force `dest` directory to created if it already exists; will overwrite!',
|
|
45
|
+
installDesc = 'Install dependencies',
|
|
46
|
+
yarnDesc = 'Install with `yarn` instead of `npm`',
|
|
47
|
+
gitDesc = 'Initialize a `git` repository';
|
|
64
48
|
|
|
65
|
-
var _default = (0, _asyncCommand
|
|
49
|
+
var _default = (0, _asyncCommand.default)({
|
|
66
50
|
command: 'create [template] [dest]',
|
|
67
51
|
desc: 'Create a new zimlet.',
|
|
68
52
|
builder: {
|
|
69
53
|
cwd: {
|
|
70
54
|
description: 'A directory to use instead of $PWD.',
|
|
71
|
-
|
|
55
|
+
default: '.',
|
|
72
56
|
requiresArg: true
|
|
73
57
|
},
|
|
74
58
|
name: {
|
|
@@ -78,23 +62,23 @@ var _default = (0, _asyncCommand["default"])({
|
|
|
78
62
|
alias: 'f',
|
|
79
63
|
description: forceDesc,
|
|
80
64
|
type: 'boolean',
|
|
81
|
-
|
|
65
|
+
default: false
|
|
82
66
|
},
|
|
83
67
|
yarn: {
|
|
84
68
|
description: yarnDesc,
|
|
85
69
|
type: 'boolean',
|
|
86
|
-
|
|
70
|
+
default: false
|
|
87
71
|
},
|
|
88
72
|
git: {
|
|
89
73
|
description: gitDesc,
|
|
90
74
|
type: 'boolean',
|
|
91
|
-
|
|
75
|
+
default: false
|
|
92
76
|
},
|
|
93
77
|
install: {
|
|
94
78
|
alias: 'i',
|
|
95
79
|
description: installDesc,
|
|
96
80
|
type: 'boolean',
|
|
97
|
-
|
|
81
|
+
default: true
|
|
98
82
|
},
|
|
99
83
|
template: {
|
|
100
84
|
description: templateDesc
|
|
@@ -103,303 +87,199 @@ var _default = (0, _asyncCommand["default"])({
|
|
|
103
87
|
description: destDesc
|
|
104
88
|
}
|
|
105
89
|
},
|
|
106
|
-
handler: function handler(argv) {
|
|
107
|
-
return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
108
|
-
var destArg, templateArg, nameArg, questions, response, cwd, isYarn, target, exists, repo, _isValidName, errors, archive, spinner, keeps, _ret, pkgData, pkgFile, pfx;
|
|
109
|
-
|
|
110
|
-
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
111
|
-
while (1) {
|
|
112
|
-
switch (_context.prev = _context.next) {
|
|
113
|
-
case 0:
|
|
114
|
-
destArg = argv.dest;
|
|
115
|
-
templateArg = argv.template;
|
|
116
|
-
nameArg = argv.name; // Prompt if incomplete data
|
|
117
|
-
|
|
118
|
-
if (!(!destArg || !templateArg)) {
|
|
119
|
-
_context.next = 12;
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
(0, _util.warn)('Insufficient command arguments! Prompting...');
|
|
124
|
-
(0, _util.info)('Alternatively, run `zimlet create --help` for usage info.');
|
|
125
|
-
questions = isMissing(argv);
|
|
126
|
-
_context.next = 9;
|
|
127
|
-
return (0, _inquirer.prompt)(questions);
|
|
128
|
-
|
|
129
|
-
case 9:
|
|
130
|
-
response = _context.sent;
|
|
131
|
-
//trim all args to prevent accidental extra whitespace in user prompted values from messing things up
|
|
132
|
-
Object.keys(response).forEach(function (k) {
|
|
133
|
-
return response[k] && response[k].trim && (response[k] = response[k].trim());
|
|
134
|
-
});
|
|
135
|
-
Object.assign(argv, response);
|
|
136
|
-
|
|
137
|
-
case 12:
|
|
138
|
-
//default is a special keyword that will use the predefiend default repo
|
|
139
|
-
if (templateArg === 'default') templateArg = DEFAULT_REPO;
|
|
140
|
-
cwd = (0, _path.resolve)(argv.cwd);
|
|
141
|
-
destArg = destArg || (0, _path.dirname)(cwd);
|
|
142
|
-
isYarn = argv.yarn && (0, _util.hasCommand)('yarn');
|
|
143
|
-
target = (0, _path.resolve)(cwd, destArg);
|
|
144
|
-
exists = (0, _util.isDir)(target);
|
|
145
|
-
|
|
146
|
-
if (!(exists && !argv.force)) {
|
|
147
|
-
_context.next = 20;
|
|
148
|
-
break;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return _context.abrupt("return", (0, _util.error)('Refusing to overwrite current directory! Please specify a different destination or use the `--force` flag', 1));
|
|
152
|
-
|
|
153
|
-
case 20:
|
|
154
|
-
if (!(exists && argv.force)) {
|
|
155
|
-
_context.next = 25;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
_context.next = 23;
|
|
160
|
-
return (0, _inquirer.prompt)({
|
|
161
|
-
type: 'confirm',
|
|
162
|
-
name: 'enableForce',
|
|
163
|
-
message: "You are using '--force'. Do you wish to continue and overwrite ".concat(target, "?"),
|
|
164
|
-
"default": false
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
case 23:
|
|
168
|
-
if (_context.sent) {
|
|
169
|
-
_context.next = 25;
|
|
170
|
-
break;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return _context.abrupt("return", (0, _util.error)('Refusing to overwrite current directory!', 1));
|
|
174
|
-
|
|
175
|
-
case 25:
|
|
176
|
-
repo = templateArg;
|
|
177
|
-
|
|
178
|
-
if (!repo.includes('/')) {
|
|
179
|
-
repo = "".concat(ORG, "/").concat(repo);
|
|
180
|
-
(0, _util.info)("Fetching ".concat(templateArg, " template from ").concat(repo, "..."));
|
|
181
|
-
} // Use `--name` value or `dest` dir's name
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
nameArg = nameArg || destArg;
|
|
185
|
-
_isValidName = (0, _validateNpmPackageName["default"])(nameArg), errors = _isValidName.errors;
|
|
186
|
-
|
|
187
|
-
if (!errors) {
|
|
188
|
-
_context.next = 32;
|
|
189
|
-
break;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
errors.unshift("Invalid package name: ".concat(nameArg));
|
|
193
|
-
return _context.abrupt("return", (0, _util.error)(errors.map(capitalize).join('\n ~ '), 1));
|
|
194
|
-
|
|
195
|
-
case 32:
|
|
196
|
-
_context.next = 34;
|
|
197
|
-
return _gittar["default"].fetch(repo)["catch"](function (err) {
|
|
198
|
-
err = err || {
|
|
199
|
-
message: 'An error occured while fetching template.'
|
|
200
|
-
};
|
|
201
|
-
return (0, _util.error)(err.code === 404 ? "Could not find repository: ".concat(repo) : err.message, 1);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
case 34:
|
|
205
|
-
archive = _context.sent;
|
|
206
|
-
spinner = (0, _ora["default"])({
|
|
207
|
-
text: 'Creating project',
|
|
208
|
-
color: 'magenta'
|
|
209
|
-
}).start(); // Extract files from `archive` to `target`
|
|
210
|
-
// TODO: read & respond to meta/hooks
|
|
211
|
-
|
|
212
|
-
keeps = [];
|
|
213
|
-
_context.next = 39;
|
|
214
|
-
return _gittar["default"].extract(archive, target, {
|
|
215
|
-
strip: 2,
|
|
216
|
-
filter: function filter(path, obj) {
|
|
217
|
-
if (path.includes('/template/')) {
|
|
218
|
-
obj.on('end', function () {
|
|
219
|
-
if (obj.type === 'File' && !isMedia(obj.path)) {
|
|
220
|
-
keeps.push(obj.absolute);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
return true;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
case 39:
|
|
229
|
-
if (!keeps.length) {
|
|
230
|
-
_context.next = 45;
|
|
231
|
-
break;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
_ret = function () {
|
|
235
|
-
var dict = new Map(); // TODO: concat author-driven patterns
|
|
236
|
-
//globally replace instances of {{name}} with value of name arg
|
|
237
|
-
|
|
238
|
-
['name'].forEach(function (str) {
|
|
239
|
-
// if value is defined
|
|
240
|
-
if (nameArg !== void 0) {
|
|
241
|
-
dict.set(new RegExp("{{\\s*".concat(str, "\\s*}}"), 'g'), nameArg);
|
|
242
|
-
}
|
|
243
|
-
}); // Update each file's contents
|
|
244
|
-
|
|
245
|
-
var buf,
|
|
246
|
-
entry,
|
|
247
|
-
enc = 'utf8';
|
|
248
|
-
|
|
249
|
-
var _iterator = _createForOfIteratorHelper(keeps),
|
|
250
|
-
_step;
|
|
251
|
-
|
|
252
|
-
try {
|
|
253
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
254
|
-
entry = _step.value;
|
|
255
|
-
buf = _fs["default"].readFileSync(entry, enc);
|
|
256
|
-
dict.forEach(function (v, k) {
|
|
257
|
-
buf = buf.replace(k, v);
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
_fs["default"].writeFileSync(entry, buf, enc);
|
|
262
|
-
} catch (err) {
|
|
263
|
-
return {
|
|
264
|
-
v: (0, _util.error)("Couldn't write ".concat(entry, ": ").concat(err))
|
|
265
|
-
};
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
} catch (err) {
|
|
269
|
-
_iterator.e(err);
|
|
270
|
-
} finally {
|
|
271
|
-
_iterator.f();
|
|
272
|
-
}
|
|
273
|
-
}();
|
|
274
|
-
|
|
275
|
-
if (!(_typeof(_ret) === "object")) {
|
|
276
|
-
_context.next = 43;
|
|
277
|
-
break;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
return _context.abrupt("return", _ret.v);
|
|
281
|
-
|
|
282
|
-
case 43:
|
|
283
|
-
_context.next = 46;
|
|
284
|
-
break;
|
|
285
|
-
|
|
286
|
-
case 45:
|
|
287
|
-
return _context.abrupt("return", (0, _util.error)("No `template` directory found within ".concat(repo, "!"), 1));
|
|
288
|
-
|
|
289
|
-
case 46:
|
|
290
|
-
spinner.succeed().start('Parsing `package.json` file'); // Validate user's `package.json` file
|
|
291
|
-
|
|
292
|
-
pkgFile = (0, _path.resolve)(target, 'package.json');
|
|
293
|
-
|
|
294
|
-
if (!pkgFile) {
|
|
295
|
-
_context.next = 64;
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
_context.prev = 49;
|
|
300
|
-
pkgData = JSON.parse(_fs["default"].readFileSync(pkgFile));
|
|
301
|
-
_context.next = 56;
|
|
302
|
-
break;
|
|
303
|
-
|
|
304
|
-
case 53:
|
|
305
|
-
_context.prev = 53;
|
|
306
|
-
_context.t0 = _context["catch"](49);
|
|
307
|
-
return _context.abrupt("return", (0, _util.error)("Could not reach package.json file: ".concat(_context.t0)));
|
|
308
|
-
|
|
309
|
-
case 56:
|
|
310
|
-
_context.t1 = pkgData.scripts;
|
|
311
|
-
|
|
312
|
-
if (_context.t1) {
|
|
313
|
-
_context.next = 61;
|
|
314
|
-
break;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
_context.next = 60;
|
|
318
|
-
return (0, _setup.addScripts)(pkgData, target, isYarn);
|
|
319
|
-
|
|
320
|
-
case 60:
|
|
321
|
-
_context.t1 = _context.sent;
|
|
322
|
-
|
|
323
|
-
case 61:
|
|
324
|
-
pkgData.scripts = _context.t1;
|
|
325
|
-
_context.next = 65;
|
|
326
|
-
break;
|
|
327
|
-
|
|
328
|
-
case 64:
|
|
329
|
-
(0, _util.warn)('Could not locate `package.json` file!');
|
|
330
|
-
|
|
331
|
-
case 65:
|
|
332
|
-
// Update `package.json` key
|
|
333
|
-
if (pkgData) {
|
|
334
|
-
spinner.succeed().start('Updating `name` to `' + nameArg + '` within `package.json` file');
|
|
335
|
-
pkgData.name = nameArg.toLowerCase().replace(/\s+/g, '_');
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
if (!pkgData) {
|
|
339
|
-
_context.next = 74;
|
|
340
|
-
break;
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
_context.prev = 67;
|
|
344
|
-
|
|
345
|
-
_fs["default"].writeFileSync(pkgFile, JSON.stringify(pkgData, null, 2));
|
|
346
|
-
|
|
347
|
-
_context.next = 74;
|
|
348
|
-
break;
|
|
349
|
-
|
|
350
|
-
case 71:
|
|
351
|
-
_context.prev = 71;
|
|
352
|
-
_context.t2 = _context["catch"](67);
|
|
353
|
-
return _context.abrupt("return", (0, _util.error)("Unable to write back package.json file: ".concat(_context.t2)));
|
|
354
|
-
|
|
355
|
-
case 74:
|
|
356
|
-
if (!argv.install) {
|
|
357
|
-
_context.next = 78;
|
|
358
|
-
break;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
spinner.succeed().start('Installing dependencies');
|
|
362
|
-
_context.next = 78;
|
|
363
|
-
return (0, _setup.install)(target, isYarn);
|
|
364
|
-
|
|
365
|
-
case 78:
|
|
366
|
-
if (!argv.git) {
|
|
367
|
-
_context.next = 82;
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
spinner.succeed().start('Initializing git repo');
|
|
372
|
-
_context.next = 82;
|
|
373
|
-
return (0, _setup.initGit)(target);
|
|
374
90
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
91
|
+
async handler(argv) {
|
|
92
|
+
let destArg = argv.dest;
|
|
93
|
+
let templateArg = argv.template;
|
|
94
|
+
let nameArg = argv.name; // Prompt if incomplete data
|
|
95
|
+
|
|
96
|
+
if (!destArg || !templateArg) {
|
|
97
|
+
(0, _util.warn)('Insufficient command arguments! Prompting...');
|
|
98
|
+
(0, _util.info)('Alternatively, run `zimlet create --help` for usage info.');
|
|
99
|
+
let questions = isMissing(argv);
|
|
100
|
+
let response = await (0, _inquirer.prompt)(questions); //trim all args to prevent accidental extra whitespace in user prompted values from messing things up
|
|
101
|
+
|
|
102
|
+
Object.keys(response).forEach(k => response[k] && response[k].trim && (response[k] = response[k].trim()));
|
|
103
|
+
Object.assign(argv, response);
|
|
104
|
+
} //default is a special keyword that will use the predefiend default repo
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
if (templateArg === 'default') templateArg = DEFAULT_REPO;
|
|
108
|
+
let cwd = (0, _path.resolve)(argv.cwd);
|
|
109
|
+
destArg = destArg || (0, _path.dirname)(cwd);
|
|
110
|
+
let isYarn = argv.yarn && (0, _util.hasCommand)('yarn');
|
|
111
|
+
let target = (0, _path.resolve)(cwd, destArg);
|
|
112
|
+
let exists = (0, _util.isDir)(target);
|
|
113
|
+
|
|
114
|
+
if (exists && !argv.force) {
|
|
115
|
+
return (0, _util.error)('Refusing to overwrite current directory! Please specify a different destination or use the `--force` flag', 1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (exists && argv.force) {
|
|
119
|
+
if (!(await (0, _inquirer.prompt)({
|
|
120
|
+
type: 'confirm',
|
|
121
|
+
name: 'enableForce',
|
|
122
|
+
message: `You are using '--force'. Do you wish to continue and overwrite ${target}?`,
|
|
123
|
+
default: false
|
|
124
|
+
}))) {
|
|
125
|
+
return (0, _util.error)('Refusing to overwrite current directory!', 1);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
let repo = templateArg;
|
|
130
|
+
|
|
131
|
+
if (!repo.includes('/')) {
|
|
132
|
+
repo = `${ORG}/${repo}`;
|
|
133
|
+
(0, _util.info)(`Fetching ${templateArg} template from ${repo}...`);
|
|
134
|
+
} // Use `--name` value or `dest` dir's name
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
nameArg = nameArg || destArg;
|
|
138
|
+
let {
|
|
139
|
+
errors
|
|
140
|
+
} = (0, _validateNpmPackageName.default)(nameArg);
|
|
379
141
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
142
|
+
if (errors) {
|
|
143
|
+
errors.unshift(`Invalid package name: ${nameArg}`);
|
|
144
|
+
return (0, _util.error)(errors.map(capitalize).join('\n ~ '), 1);
|
|
145
|
+
} // Attempt to fetch the `template`
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
let archive = await _gittar.default.fetch(repo).catch(err => {
|
|
149
|
+
err = err || {
|
|
150
|
+
message: 'An error occured while fetching template.'
|
|
151
|
+
};
|
|
152
|
+
return (0, _util.error)(err.code === 404 ? `Could not find repository: ${repo}` : err.message, 1);
|
|
153
|
+
});
|
|
154
|
+
let spinner = (0, _ora.default)({
|
|
155
|
+
text: 'Creating project',
|
|
156
|
+
color: 'magenta'
|
|
157
|
+
}).start(); // Extract files from `archive` to `target`
|
|
158
|
+
// TODO: read & respond to meta/hooks
|
|
159
|
+
|
|
160
|
+
let keeps = [];
|
|
161
|
+
await _gittar.default.extract(archive, target, {
|
|
162
|
+
strip: 2,
|
|
163
|
+
|
|
164
|
+
filter(path, obj) {
|
|
165
|
+
if (path.includes('/template/')) {
|
|
166
|
+
obj.on('end', () => {
|
|
167
|
+
if (obj.type === 'File' && !isMedia(obj.path)) {
|
|
168
|
+
keeps.push(obj.absolute);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
return true;
|
|
384
172
|
}
|
|
385
|
-
}
|
|
386
|
-
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
if (keeps.length) {
|
|
178
|
+
let dict = new Map(); // TODO: concat author-driven patterns
|
|
179
|
+
//globally replace instances of {{name}} with value of name arg
|
|
180
|
+
|
|
181
|
+
['name'].forEach(str => {
|
|
182
|
+
// if value is defined
|
|
183
|
+
if (nameArg !== void 0) {
|
|
184
|
+
dict.set(new RegExp(`{{\\s*${str}\\s*}}`, 'g'), nameArg);
|
|
185
|
+
}
|
|
186
|
+
}); // Update each file's contents
|
|
187
|
+
|
|
188
|
+
let buf,
|
|
189
|
+
entry,
|
|
190
|
+
enc = 'utf8';
|
|
191
|
+
|
|
192
|
+
for (entry of keeps) {
|
|
193
|
+
buf = _fs.default.readFileSync(entry, enc);
|
|
194
|
+
dict.forEach((v, k) => {
|
|
195
|
+
buf = buf.replace(k, v);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
try {
|
|
199
|
+
_fs.default.writeFileSync(entry, buf, enc);
|
|
200
|
+
} catch (err) {
|
|
201
|
+
return (0, _util.error)(`Couldn't write ${entry}: ${err}`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
} else {
|
|
205
|
+
return (0, _util.error)(`No \`template\` directory found within ${repo}!`, 1);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
spinner.succeed().start('Parsing `package.json` file'); // Validate user's `package.json` file
|
|
209
|
+
|
|
210
|
+
let pkgData,
|
|
211
|
+
pkgFile = (0, _path.resolve)(target, 'package.json');
|
|
212
|
+
|
|
213
|
+
if (pkgFile) {
|
|
214
|
+
try {
|
|
215
|
+
pkgData = JSON.parse(_fs.default.readFileSync(pkgFile));
|
|
216
|
+
} catch (err) {
|
|
217
|
+
return (0, _util.error)(`Could not reach package.json file: ${err}`);
|
|
218
|
+
} // Write default "scripts" if none found
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
pkgData.scripts = pkgData.scripts || (await (0, _setup.addScripts)(pkgData, target, isYarn));
|
|
222
|
+
} else {
|
|
223
|
+
(0, _util.warn)('Could not locate `package.json` file!');
|
|
224
|
+
} // Update `package.json` key
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
if (pkgData) {
|
|
228
|
+
spinner.succeed().start('Updating `name` to `' + nameArg + '` within `package.json` file');
|
|
229
|
+
pkgData.name = nameArg.toLowerCase().replace(/\s+/g, '_');
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (pkgData) {
|
|
233
|
+
// Assume changes were made
|
|
234
|
+
try {
|
|
235
|
+
_fs.default.writeFileSync(pkgFile, JSON.stringify(pkgData, null, 2));
|
|
236
|
+
} catch (err) {
|
|
237
|
+
return (0, _util.error)(`Unable to write back package.json file: ${err}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (argv.install) {
|
|
242
|
+
spinner.succeed().start('Installing dependencies');
|
|
243
|
+
await (0, _setup.install)(target, isYarn);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
if (argv.git) {
|
|
247
|
+
spinner.succeed().start('Initializing git repo');
|
|
248
|
+
await (0, _setup.initGit)(target);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
spinner.succeed().succeed('Done!\n');
|
|
252
|
+
let pfx = isYarn ? 'yarn' : 'npm run';
|
|
253
|
+
return (0, _util.trim)(`
|
|
254
|
+
To get started, cd into the new directory:
|
|
255
|
+
${(0, _chalk.green)('cd ' + destArg)}
|
|
256
|
+
|
|
257
|
+
To start a development live-reload server:
|
|
258
|
+
${(0, _chalk.green)(pfx + ' watch')}
|
|
259
|
+
|
|
260
|
+
To create a production build (in ./build):
|
|
261
|
+
${(0, _chalk.green)(pfx + ' build')}
|
|
262
|
+
|
|
263
|
+
To create the official zimlet package (in ./pkg)
|
|
264
|
+
${(0, _chalk.green)(pfx + ' package')}
|
|
265
|
+
`) + '\n';
|
|
387
266
|
}
|
|
267
|
+
|
|
388
268
|
}); // Formulate Questions if `create` args are missing
|
|
389
269
|
|
|
390
270
|
|
|
391
|
-
exports
|
|
271
|
+
exports.default = _default;
|
|
392
272
|
|
|
393
273
|
function isMissing(argv) {
|
|
394
|
-
|
|
274
|
+
let out = [];
|
|
395
275
|
|
|
396
|
-
|
|
397
|
-
|
|
276
|
+
const ask = (name, message, val) => {
|
|
277
|
+
let type = typeof val === 'boolean' ? 'confirm' : 'input';
|
|
398
278
|
out.push({
|
|
399
|
-
name
|
|
400
|
-
message
|
|
401
|
-
type
|
|
402
|
-
|
|
279
|
+
name,
|
|
280
|
+
message,
|
|
281
|
+
type,
|
|
282
|
+
default: val
|
|
403
283
|
});
|
|
404
284
|
}; // Required data
|
|
405
285
|
|
|
@@ -407,8 +287,10 @@ function isMissing(argv) {
|
|
|
407
287
|
!argv.template && ask('template', templateDesc, 'default');
|
|
408
288
|
!argv.dest && ask('dest', destDesc); // Extra data / flags
|
|
409
289
|
|
|
410
|
-
!argv.name && ask('name', nameDesc,
|
|
411
|
-
|
|
290
|
+
!argv.name && ask('name', nameDesc, _ref => {
|
|
291
|
+
let {
|
|
292
|
+
dest
|
|
293
|
+
} = _ref;
|
|
412
294
|
return dest;
|
|
413
295
|
}); //use the current answer for 'dest' as the default
|
|
414
296
|
|