@cocojs/cli 0.0.1-alpha.5 → 0.0.1-alpha.7

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/dist/index.js CHANGED
@@ -8,6 +8,7 @@ var rollup = require('rollup');
8
8
  var typescript = require('@rollup/plugin-typescript');
9
9
  var babel = require('@rollup/plugin-babel');
10
10
  var cocojs = require('@cocojs/rollup-plugin-mvc');
11
+ var fs = require('node:fs');
11
12
 
12
13
  function _arrayLikeToArray(r, a) {
13
14
  (null == a || a > r.length) && (a = r.length);
@@ -216,6 +217,15 @@ function _toPropertyKey(t) {
216
217
  var i = _toPrimitive(t, "string");
217
218
  return "symbol" == typeof i ? i : i + "";
218
219
  }
220
+ function _typeof(o) {
221
+ "@babel/helpers - typeof";
222
+
223
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
224
+ return typeof o;
225
+ } : function (o) {
226
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
227
+ }, _typeof(o);
228
+ }
219
229
  function _unsupportedIterableToArray(r, a) {
220
230
  if (r) {
221
231
  if ("string" == typeof r) return _arrayLikeToArray(r, a);
@@ -409,13 +419,112 @@ function _buildApp() {
409
419
  return _buildApp.apply(this, arguments);
410
420
  }
411
421
 
422
+ var cmdDefaultEnvMap = {
423
+ dev: 'dev',
424
+ build: 'prod'
425
+ };
426
+ var defaultConfigName = 'config.js';
427
+ /**
428
+ * 得到构建配置的名称
429
+ */
430
+ var configFileName = function configFileName(cmd) {
431
+ var env = process$1.env.NODE_ENV || cmdDefaultEnvMap[cmd] || '';
432
+ return env ? "config.".concat(env, ".js") : defaultConfigName;
433
+ };
434
+
435
+ function readRollup(_x) {
436
+ return _readRollup.apply(this, arguments);
437
+ } // 目前 rollup 的配置仅支持简单的自定义,后续有需求再增强
438
+ function _readRollup() {
439
+ _readRollup = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(cmd) {
440
+ var _yield$import, _content$rollup;
441
+ var filename, filepath, content, _t, _t2, _t3;
442
+ return _regenerator().w(function (_context2) {
443
+ while (1) switch (_context2.n) {
444
+ case 0:
445
+ filename = cmd ? configFileName(cmd) : defaultConfigName;
446
+ filepath = path$1.resolve(process$1.cwd(), "config/".concat(filename));
447
+ if (fs.existsSync(filepath)) {
448
+ _context2.n = 1;
449
+ break;
450
+ }
451
+ console.warn("\u914D\u7F6E\u6587\u4EF6\u4E0D\u5B58\u5728\uFF1A".concat(filepath));
452
+ return _context2.a(2, {});
453
+ case 1:
454
+ _context2.n = 2;
455
+ return import(filepath);
456
+ case 2:
457
+ _t2 = _yield$import = _context2.v;
458
+ _t = _t2 === null;
459
+ if (_t) {
460
+ _context2.n = 3;
461
+ break;
462
+ }
463
+ _t = _yield$import === void 0;
464
+ case 3:
465
+ if (!_t) {
466
+ _context2.n = 4;
467
+ break;
468
+ }
469
+ _t3 = void 0;
470
+ _context2.n = 5;
471
+ break;
472
+ case 4:
473
+ _t3 = _yield$import["default"];
474
+ case 5:
475
+ content = _t3;
476
+ return _context2.a(2, (_content$rollup = content === null || content === void 0 ? void 0 : content.rollup) !== null && _content$rollup !== void 0 ? _content$rollup : {});
477
+ }
478
+ }, _callee2);
479
+ }));
480
+ return _readRollup.apply(this, arguments);
481
+ }
482
+ function mergeRollupConfig(config1, config2) {
483
+ var validKeys = ['cocoId'];
484
+ var _config1 = {};
485
+ var _config2 = {};
486
+ for (var _i = 0, _validKeys = validKeys; _i < _validKeys.length; _i++) {
487
+ var key = _validKeys[_i];
488
+ _config1[key] = _typeof(config1) !== 'object' || config1 === null ? config1[key] : undefined;
489
+ _config2[key] = _typeof(config2) !== 'object' || config2 === null ? config2[key] : undefined;
490
+ }
491
+ return Object.assign({}, _config1, _config2);
492
+ }
493
+ function getRollupConfig() {
494
+ return _getRollupConfig.apply(this, arguments);
495
+ }
496
+ function _getRollupConfig() {
497
+ _getRollupConfig = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
498
+ var baseConfig, envConfig;
499
+ return _regenerator().w(function (_context3) {
500
+ while (1) switch (_context3.n) {
501
+ case 0:
502
+ _context3.n = 1;
503
+ return readRollup();
504
+ case 1:
505
+ baseConfig = _context3.v;
506
+ _context3.n = 2;
507
+ return readRollup('build');
508
+ case 2:
509
+ envConfig = _context3.v;
510
+ return _context3.a(2, mergeRollupConfig(baseConfig, envConfig));
511
+ }
512
+ }, _callee3);
513
+ }));
514
+ return _getRollupConfig.apply(this, arguments);
515
+ }
412
516
  var build = /*#__PURE__*/function () {
413
517
  var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
414
- var result;
518
+ var config, result;
415
519
  return _regenerator().w(function (_context) {
416
520
  while (1) switch (_context.n) {
417
521
  case 0:
418
522
  _context.n = 1;
523
+ return getRollupConfig();
524
+ case 1:
525
+ config = _context.v;
526
+ console.info('rollup config', config);
527
+ _context.n = 2;
419
528
  return rollup.rollup({
420
529
  input: path$1.join(process$1.cwd(), './src/index.ts'),
421
530
  plugins: [cocojs(), typescript({
@@ -443,14 +552,14 @@ var build = /*#__PURE__*/function () {
443
552
  }]]
444
553
  })]
445
554
  });
446
- case 1:
555
+ case 2:
447
556
  result = _context.v;
448
- _context.n = 2;
557
+ _context.n = 3;
449
558
  return result.write({
450
559
  file: path$1.join(process$1.cwd(), './dist/index.esm.js'),
451
560
  format: 'es'
452
561
  });
453
- case 2:
562
+ case 3:
454
563
  return _context.a(2);
455
564
  }
456
565
  }, _callee);
@@ -295,11 +295,6 @@ var buildInConfig = {
295
295
  importSource: '@cocojs/mvc'
296
296
  }]]
297
297
  }
298
- }, function debugAfterTsLoader(source) {
299
- console.log('-------- SOURCE START --------');
300
- console.log(source);
301
- console.log('-------- SOURCE END ----------');
302
- return source;
303
298
  }, {
304
299
  loader: require.resolve('ts-loader'),
305
300
  options: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cocojs/cli",
3
3
  "description": "命令行工具,支持开发和构建功能",
4
- "version": "0.0.1-alpha.5",
4
+ "version": "0.0.1-alpha.7",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "bin": {
@@ -44,8 +44,8 @@
44
44
  "webpack-dev-server": "^5.2.0",
45
45
  "webpack-merge": "^6.0.1",
46
46
  "@cocojs/webpack-loader-mvc": "0.0.1-alpha.1",
47
- "@cocojs/rollup-plugin-mvc": "0.0.1-alpha.3",
48
- "@cocojs/type-extractor": "0.0.16"
47
+ "@cocojs/type-extractor": "0.0.16",
48
+ "@cocojs/rollup-plugin-mvc": "0.0.1-alpha.4"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@types/node": "^22.15.18"