@zohodesk/react-cli 0.0.1-beta.98 → 0.0.1-betaa.138.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (139) hide show
  1. package/CHANGELOG.md +5 -0
  2. package/README.md +149 -0
  3. package/bin/cli.js +34 -29
  4. package/files/eslintrc.js +57 -0
  5. package/files/prettierrc.js +3 -0
  6. package/lib/babel/cmjs-plugins-presets.js +16 -9
  7. package/lib/babel/es-plugins-presets.js +26 -14
  8. package/lib/common/getEntries.js +31 -22
  9. package/lib/common/getPublicPathConfig.js +27 -13
  10. package/lib/common/index.js +21 -25
  11. package/lib/common/splitChunks.js +62 -53
  12. package/lib/common/templateParameters.js +10 -8
  13. package/lib/configs/jest.config.js +15 -25
  14. package/lib/configs/webpack.component.umd.config.js +31 -37
  15. package/lib/configs/webpack.css.umd.config.js +44 -47
  16. package/lib/configs/webpack.dev.config.js +70 -52
  17. package/lib/configs/webpack.docs.config.js +106 -106
  18. package/lib/configs/webpack.prod.config.js +95 -75
  19. package/lib/hooks/docsProptypeHook.js +32 -38
  20. package/lib/jest/commitedFilesResult.js +103 -74
  21. package/lib/jest/coverageCollector.js +41 -21
  22. package/lib/jest/jsonMaker.js +15 -16
  23. package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
  24. package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
  25. package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
  26. package/lib/jest/result.js +90 -45
  27. package/lib/jest/run.js +43 -43
  28. package/lib/jest/setup.js +102 -95
  29. package/lib/loaderUtils/getCSSLoaders.js +21 -22
  30. package/lib/loaderUtils/getDevJsLoaders.js +25 -23
  31. package/lib/loaderUtils/index.js +11 -13
  32. package/lib/loaders/docsLoader.js +15 -15
  33. package/lib/loaders/docsPropsLoader.js +14 -17
  34. package/lib/loaders/fileLoader.js +33 -35
  35. package/lib/loaders/scriptInstrumentLoader.js +21 -20
  36. package/lib/loaders/workerLoader.js +136 -0
  37. package/lib/middlewares/HMRMiddleware.js +54 -45
  38. package/lib/middlewares/SSTMiddleware.js +8 -5
  39. package/lib/pluginUtils/getDevPlugins.js +114 -52
  40. package/lib/pluginUtils/getDocsPlugins.js +25 -29
  41. package/lib/pluginUtils/getLibraryPlugins.js +8 -10
  42. package/lib/pluginUtils/getProdPlugins.js +163 -74
  43. package/lib/pluginUtils/getServerPlugins.js +8 -11
  44. package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
  45. package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
  46. package/lib/pluginUtils/index.js +36 -43
  47. package/lib/plugins/CdnChangePlugin.js +63 -0
  48. package/lib/plugins/CleanupStatsPlugin.js +18 -32
  49. package/lib/plugins/CustomAttributePlugin.js +79 -0
  50. package/lib/plugins/CustomAttributePlugin.md +35 -0
  51. package/lib/plugins/EFCPlugin.js +185 -0
  52. package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
  53. package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
  54. package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
  55. package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
  56. package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
  57. package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
  58. package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
  59. package/lib/plugins/I18nSplitPlugin/README.md +25 -0
  60. package/lib/plugins/I18nSplitPlugin/index.js +185 -0
  61. package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
  62. package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
  63. package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
  64. package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
  65. package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
  66. package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
  67. package/lib/plugins/ManifestPlugin.js +52 -63
  68. package/lib/plugins/ModuleStatsPlugin.js +83 -173
  69. package/lib/plugins/OptimizeJSPlugin.js +24 -41
  70. package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
  71. package/lib/plugins/PublicPathChangePlugin.js +175 -284
  72. package/lib/plugins/ReportGeneratePlugin.js +150 -151
  73. package/lib/plugins/ResourceHintsPlugin.js +53 -35
  74. package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
  75. package/lib/plugins/ServiceWorkerPlugin.js +81 -57
  76. package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
  77. package/lib/plugins/SourceMapHookPlugin.js +21 -33
  78. package/lib/plugins/TPHashMappingPlugin.js +67 -0
  79. package/lib/plugins/UglifyCSSPlugin.js +23 -30
  80. package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
  81. package/lib/plugins/index.js +100 -91
  82. package/lib/plugins/webpackwatchrunplugin.js +18 -30
  83. package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
  84. package/lib/schemas/index.js +336 -81
  85. package/lib/servers/clusterHubServer.js +22 -26
  86. package/lib/servers/docsServer.js +3 -5
  87. package/lib/servers/docsServerCore.js +84 -91
  88. package/lib/servers/helpServer.js +19 -21
  89. package/lib/servers/impactServer.js +99 -92
  90. package/lib/servers/mockserver.js +24 -24
  91. package/lib/servers/scrServer.js +78 -98
  92. package/lib/servers/server.js +101 -122
  93. package/lib/servers/ssServer.js +63 -61
  94. package/lib/sh/reportPublish.sh +1 -2
  95. package/lib/templates/CoverageScriptTemplate.js +45 -18
  96. package/lib/templates/WMSTemplate.js +17 -18
  97. package/lib/templates/linterConstant.js +6 -4
  98. package/lib/utils/babelPresets.js +12 -5
  99. package/lib/utils/clean.js +12 -11
  100. package/lib/utils/copy.js +12 -34
  101. package/lib/utils/copyTimezones.js +9 -16
  102. package/lib/utils/createEventStream.js +24 -19
  103. package/lib/utils/cssClassNameGenerate.js +44 -73
  104. package/lib/utils/cssURLReplacer.js +62 -56
  105. package/lib/utils/dependencyPostPublish.js +20 -19
  106. package/lib/utils/fileUtils.js +66 -54
  107. package/lib/utils/folderIterator.js +20 -21
  108. package/lib/utils/getComponents.js +70 -27
  109. package/lib/utils/getCurrentBranch.js +11 -17
  110. package/lib/utils/getDependenciesImpactList.js +114 -187
  111. package/lib/utils/getHash.js +9 -13
  112. package/lib/utils/getIp.js +9 -9
  113. package/lib/utils/getOptions.js +26 -29
  114. package/lib/utils/getServerURL.js +19 -10
  115. package/lib/utils/index.js +147 -126
  116. package/lib/utils/init.js +2 -2
  117. package/lib/utils/initPreCommitHook.js +40 -32
  118. package/lib/utils/jsonHelper.js +37 -21
  119. package/lib/utils/lint/addScripts.js +27 -0
  120. package/lib/utils/lint/checkExistingConfig.js +67 -0
  121. package/lib/utils/lint/copyConfigs.js +24 -0
  122. package/lib/utils/lint/index.js +54 -0
  123. package/lib/utils/lint/lintScripts.js +11 -0
  124. package/lib/utils/lint/lintSetup.js +31 -0
  125. package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
  126. package/lib/utils/lint/question.js +30 -0
  127. package/lib/utils/lintReporter.js +70 -56
  128. package/lib/utils/mailSender.js +12 -27
  129. package/lib/utils/pullOrigin.js +21 -18
  130. package/lib/utils/reinstallDependencies.js +76 -85
  131. package/lib/utils/removeAttributes.js +25 -23
  132. package/lib/utils/repoClone.js +47 -45
  133. package/lib/utils/request.js +64 -77
  134. package/lib/utils/rtl.js +22 -29
  135. package/lib/utils/setEnvVariables.js +5 -6
  136. package/lib/utils/ssTestHack.js +21 -19
  137. package/lib/utils/switchBranch.js +21 -20
  138. package/lib/utils/urlConcat.js +22 -0
  139. package/package.json +72 -67
@@ -1,25 +1,28 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _child_process = require('child_process');
8
+ var _child_process = require("child_process");
8
9
 
9
- var _utils = require('../utils');
10
+ var _utils = require("../utils");
10
11
 
11
- exports.default = function () {
12
- var type = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'git';
13
- var branchName = arguments[1];
14
- return new Promise(function (resolve) {
15
- if (type === 'git') {
16
- (0, _child_process.spawnSync)('git', ['pull', 'origin', branchName], { encoding: 'utf8' });
17
- (0, _utils.log)(branchName, 'Branch Pulled!');
18
- resolve();
19
- } else if (type === 'hg') {
20
- (0, _child_process.spawnSync)('hg', ['pull'], { encoding: 'utf8' });
21
- (0, _utils.log)(branchName, 'Branch Pulled!');
22
- resolve();
23
- }
24
- });
25
- };
12
+ var _default = (type = 'git', branchName) => new Promise(resolve => {
13
+ if (type === 'git') {
14
+ (0, _child_process.spawnSync)('git', ['pull', 'origin', branchName], {
15
+ encoding: 'utf8'
16
+ });
17
+ (0, _utils.log)(branchName, 'Branch Pulled!');
18
+ resolve();
19
+ } else if (type === 'hg') {
20
+ (0, _child_process.spawnSync)('hg', ['pull'], {
21
+ encoding: 'utf8'
22
+ });
23
+ (0, _utils.log)(branchName, 'Branch Pulled!');
24
+ resolve();
25
+ }
26
+ });
27
+
28
+ exports.default = _default;
@@ -1,118 +1,99 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.reinstallDependencies = exports.reinstallDependencies1 = exports.collectPackageDiff = undefined;
6
+ exports.reinstallDependencies1 = exports.reinstallDependencies = exports.collectPackageDiff = void 0;
7
7
 
8
- var _fs = require('fs');
8
+ var _fs = _interopRequireDefault(require("fs"));
9
9
 
10
- var _fs2 = _interopRequireDefault(_fs);
10
+ var _path = _interopRequireDefault(require("path"));
11
11
 
12
- var _path = require('path');
12
+ var _child_process = require("child_process");
13
13
 
14
- var _path2 = _interopRequireDefault(_path);
14
+ var _gitRootDir = _interopRequireDefault(require("git-root-dir"));
15
15
 
16
- var _child_process = require('child_process');
17
-
18
- var _gitRootDir = require('git-root-dir');
19
-
20
- var _gitRootDir2 = _interopRequireDefault(_gitRootDir);
21
-
22
- var _index = require('./index');
16
+ var _index = require("./index");
23
17
 
24
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
19
 
26
- var packageJsons = {};
20
+ let packageJsons = {};
27
21
 
28
- var packageDiffChecker = function packageDiffChecker(pre, current) {
29
- var _current$dependencies = current.dependencies,
30
- dependencies = _current$dependencies === undefined ? {} : _current$dependencies,
31
- _current$devDependenc = current.devDependencies,
32
- devDependencies = _current$devDependenc === undefined ? {} : _current$devDependenc;
22
+ let packageDiffChecker = (pre, current) => {
23
+ let {
24
+ dependencies = {},
25
+ devDependencies = {}
26
+ } = current;
27
+ let diffs = {};
28
+ Object.keys(dependencies).forEach(pack => {
29
+ let version = dependencies[pack];
33
30
 
34
- var diffs = {};
35
- Object.keys(dependencies).forEach(function (pack) {
36
- var version = dependencies[pack];
37
31
  if (version !== pre.dependencies && pre.dependencies[pack]) {
38
32
  diffs[pack] = version;
39
33
  }
40
34
  });
35
+ Object.keys(devDependencies).forEach(pack => {
36
+ let version = devDependencies[pack];
41
37
 
42
- Object.keys(devDependencies).forEach(function (pack) {
43
- var version = devDependencies[pack];
44
38
  if (version !== pre.devDependencies && pre.devDependencies[pack]) {
45
39
  diffs[pack] = version;
46
40
  }
47
41
  });
48
-
49
42
  return diffs;
50
43
  };
51
44
 
52
- var collectPackageDiff = exports.collectPackageDiff = function collectPackageDiff(pathToSubProjects) {
53
- return new Promise(function (resolve) {
54
- (0, _gitRootDir2.default)(process.cwd()).then(function (rootDir) {
55
- var projects = _fs2.default.readdirSync(_path2.default.join(rootDir, pathToSubProjects));
56
- projects.forEach(function (project) {
57
- var packageJson = _path2.default.join(_path2.default.join(rootDir, pathToSubProjects), project, 'package.json');
58
- if (_fs2.default.existsSync(packageJson)) {
59
- packageJsons[project] = require(packageJson);
60
- }
61
- });
62
- resolve();
45
+ let collectPackageDiff = pathToSubProjects => new Promise(resolve => {
46
+ (0, _gitRootDir.default)(process.cwd()).then(rootDir => {
47
+ let projects = _fs.default.readdirSync(_path.default.join(rootDir, pathToSubProjects));
48
+
49
+ projects.forEach(project => {
50
+ let packageJson = _path.default.join(_path.default.join(rootDir, pathToSubProjects), project, 'package.json');
51
+
52
+ if (_fs.default.existsSync(packageJson)) {
53
+ packageJsons[project] = require(packageJson);
54
+ }
63
55
  });
56
+ resolve();
64
57
  });
65
- };
58
+ });
59
+
60
+ exports.collectPackageDiff = collectPackageDiff;
61
+
62
+ let reinstallDependencies1 = pathToSubProjects => {
63
+ (0, _gitRootDir.default)(process.cwd()).then(rootDir => {
64
+ let projects = _fs.default.readdirSync(_path.default.join(rootDir, pathToSubProjects));
65
+
66
+ projects.forEach(project => {
67
+ let prePackageJson = packageJsons[project];
68
+ let currentPackageJson;
66
69
 
67
- var reinstallDependencies1 = exports.reinstallDependencies1 = function reinstallDependencies1(pathToSubProjects) {
68
- (0, _gitRootDir2.default)(process.cwd()).then(function (rootDir) {
69
- var projects = _fs2.default.readdirSync(_path2.default.join(rootDir, pathToSubProjects));
70
- projects.forEach(function (project) {
71
- var prePackageJson = packageJsons[project];
72
- var currentPackageJson = void 0;
73
70
  if (prePackageJson) {
74
- currentPackageJson = _path2.default.join(_path2.default.join(rootDir, pathToSubProjects), project, 'package.json');
75
- if (_fs2.default.existsSync(currentPackageJson)) {
71
+ currentPackageJson = _path.default.join(_path.default.join(rootDir, pathToSubProjects), project, 'package.json');
72
+
73
+ if (_fs.default.existsSync(currentPackageJson)) {
76
74
  currentPackageJson = require(currentPackageJson);
77
75
  }
78
76
  }
79
- var projPath = _path2.default.join(_path2.default.join(rootDir, pathToSubProjects), project);
80
- var diffs = packageDiffChecker(prePackageJson, currentPackageJson);
77
+
78
+ let projPath = _path.default.join(_path.default.join(rootDir, pathToSubProjects), project);
79
+
80
+ let diffs = packageDiffChecker(prePackageJson, currentPackageJson);
81
+
81
82
  if (Object.keys(diffs).length) {
82
- (0, _index.log)(diffs, 'package diffs between branches for ' + project + ' project');
83
+ (0, _index.log)(diffs, `package diffs between branches for ${project} project`);
83
84
  (0, _child_process.spawnSync)('rm', ['-rf', 'package-lock.json'], {
84
85
  cwd: projPath,
85
86
  stdio: 'inherit'
86
87
  });
87
- var packages = Object.keys(diffs);
88
- var dummy = [];
89
- var _iteratorNormalCompletion = true;
90
- var _didIteratorError = false;
91
- var _iteratorError = undefined;
92
-
93
- try {
94
- for (var _iterator = packages[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
95
- var name = _step.value;
96
-
97
- var version = diffs[name];
98
- dummy.push(name + '@' + version);
99
- }
100
- } catch (err) {
101
- _didIteratorError = true;
102
- _iteratorError = err;
103
- } finally {
104
- try {
105
- if (!_iteratorNormalCompletion && _iterator.return) {
106
- _iterator.return();
107
- }
108
- } finally {
109
- if (_didIteratorError) {
110
- throw _iteratorError;
111
- }
112
- }
88
+ let packages = Object.keys(diffs);
89
+ let dummy = [];
90
+
91
+ for (let name of packages) {
92
+ let version = diffs[name];
93
+ dummy.push(`${name}@${version}`);
113
94
  }
114
95
 
115
- (0, _index.log)('npm ' + ['install'].concat(dummy).join(' '));
96
+ (0, _index.log)(`npm ${['install'].concat(dummy).join(' ')}`);
116
97
  (0, _child_process.spawnSync)('npm', ['install'].concat(dummy), {
117
98
  cwd: projPath,
118
99
  stdio: 'inherit'
@@ -122,21 +103,31 @@ var reinstallDependencies1 = exports.reinstallDependencies1 = function reinstall
122
103
  cwd: projPath,
123
104
  stdio: 'inherit'
124
105
  });
125
- (0, _child_process.spawnSync)('npm', ['install'], { cwd: projPath, stdio: 'inherit' });
106
+ (0, _child_process.spawnSync)('npm', ['install'], {
107
+ cwd: projPath,
108
+ stdio: 'inherit'
109
+ });
126
110
  }
127
111
  });
128
112
  });
129
113
  };
130
114
 
131
- var reinstallDependencies = exports.reinstallDependencies = function reinstallDependencies(pathToSubProjects) {
132
- return new Promise(function (resolve) {
133
- (0, _gitRootDir2.default)(process.cwd()).then(function (rootDir) {
134
- var projects = _fs2.default.readdirSync(_path2.default.join(rootDir, pathToSubProjects));
135
- projects.forEach(function (project) {
136
- var projPath = _path2.default.join(_path2.default.join(rootDir, pathToSubProjects), project);
137
- (0, _child_process.spawnSync)('npm', ['install'], { cwd: projPath, stdio: 'inherit' });
138
- resolve();
115
+ exports.reinstallDependencies1 = reinstallDependencies1;
116
+
117
+ let reinstallDependencies = pathToSubProjects => new Promise(resolve => {
118
+ (0, _gitRootDir.default)(process.cwd()).then(rootDir => {
119
+ let projects = _fs.default.readdirSync(_path.default.join(rootDir, pathToSubProjects));
120
+
121
+ projects.forEach(project => {
122
+ let projPath = _path.default.join(_path.default.join(rootDir, pathToSubProjects), project);
123
+
124
+ (0, _child_process.spawnSync)('npm', ['install'], {
125
+ cwd: projPath,
126
+ stdio: 'inherit'
139
127
  });
128
+ resolve();
140
129
  });
141
130
  });
142
- };
131
+ });
132
+
133
+ exports.reinstallDependencies = reinstallDependencies;
@@ -1,32 +1,34 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _getOptions = require('./getOptions');
4
-
5
- var _getOptions2 = _interopRequireDefault(_getOptions);
3
+ var _getOptions = _interopRequireDefault(require("./getOptions"));
6
4
 
7
5
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
6
 
9
- var options = (0, _getOptions2.default)();
7
+ let options = (0, _getOptions.default)();
8
+ let {
9
+ app: {
10
+ attrbuteNames
11
+ }
12
+ } = options;
10
13
 
11
- var attrbuteNames = options.app.attrbuteNames;
14
+ module.exports = () => ({
15
+ visitor: {
16
+ Program(path, state) {
17
+ let properties = state.opts.properties || [];
12
18
 
19
+ if (properties.length === 0) {
20
+ properties = properties.concat(attrbuteNames);
21
+ }
13
22
 
14
- module.exports = function () {
15
- return {
16
- visitor: {
17
- Program: function Program(path, state) {
18
- var properties = state.opts.properties || [];
19
- if (properties.length === 0) {
20
- properties = properties.concat(attrbuteNames);
21
- }
22
- path.traverse({
23
- JSXIdentifier: function JSXIdentifier(path2) {
24
- if (properties.indexOf(path2.node.name.toLowerCase()) > -1) {
25
- path2.parentPath.remove();
26
- }
23
+ path.traverse({
24
+ JSXIdentifier(path2) {
25
+ if (properties.indexOf(path2.node.name.toLowerCase()) > -1) {
26
+ path2.parentPath.remove();
27
27
  }
28
- });
29
- }
28
+ }
29
+
30
+ });
30
31
  }
31
- };
32
- };
32
+
33
+ }
34
+ });
@@ -1,88 +1,89 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var _os = require('os');
3
+ var _os = require("os");
4
4
 
5
- var _path = require('path');
5
+ var _path = _interopRequireDefault(require("path"));
6
6
 
7
- var _path2 = _interopRequireDefault(_path);
7
+ var _fs = _interopRequireDefault(require("fs"));
8
8
 
9
- var _fs = require('fs');
9
+ var _child_process = require("child_process");
10
10
 
11
- var _fs2 = _interopRequireDefault(_fs);
12
-
13
- var _child_process = require('child_process');
14
-
15
- var _index = require('./index');
11
+ var _index = require("./index");
16
12
 
17
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
14
 
19
- var options = (0, _index.getOptions)();
20
-
21
- var _options$clone = options.clone,
22
- type = _options$clone.type,
23
- url = _options$clone.url,
24
- branch = _options$clone.branch,
25
- revision = _options$clone.revision,
26
- projectName = _options$clone.projectName,
27
- cacheDir = _options$clone.cacheDir,
28
- remoteName = _options$clone.remoteName,
29
- shouldDelete = _options$clone.shouldDelete;
30
-
15
+ let options = (0, _index.getOptions)();
16
+ let {
17
+ clone: {
18
+ type,
19
+ url,
20
+ branch,
21
+ revision,
22
+ projectName,
23
+ cacheDir,
24
+ remoteName,
25
+ shouldDelete
26
+ }
27
+ } = options;
31
28
 
32
29
  if (type && (type === 'git' || type === 'hg')) {
33
- (0, _index.log)('Going to clone ' + type + ' repository');
30
+ (0, _index.log)(`Going to clone ${type} repository`);
34
31
  } else {
35
32
  throw new Error('You must give valid type to clone a repository');
36
33
  }
37
34
 
38
35
  if (!cacheDir) {
39
- cacheDir = _path2.default.join((0, _os.homedir)(), '.react-cli');
36
+ cacheDir = _path.default.join((0, _os.homedir)(), '.react-cli');
40
37
  } else {
41
- cacheDir = _path2.default.join(process.cwd(), cacheDir);
38
+ cacheDir = _path.default.join(process.cwd(), cacheDir);
42
39
  }
43
40
 
44
41
  if (!projectName) {
45
- var _path$parse = _path2.default.parse(url),
46
- name = _path$parse.name;
42
+ let {
43
+ name
44
+ } = _path.default.parse(url);
47
45
 
48
46
  projectName = name;
49
47
  }
50
48
 
51
- var projectPath = _path2.default.join(cacheDir, projectName);
49
+ let projectPath = _path.default.join(cacheDir, projectName);
52
50
 
53
- var cloneRepo = function cloneRepo() {
54
- if (!_fs2.default.existsSync(cacheDir)) {
55
- _fs2.default.mkdirSync(cacheDir);
51
+ let cloneRepo = () => {
52
+ if (!_fs.default.existsSync(cacheDir)) {
53
+ _fs.default.mkdirSync(cacheDir);
56
54
  }
57
- var revisionOrBranch = void 0;
55
+
56
+ let revisionOrBranch;
58
57
 
59
58
  if (type === 'git') {
60
- revisionOrBranch = '-b' + branch;
59
+ revisionOrBranch = `-b${branch}`;
61
60
  } else {
62
61
  if (revision) {
63
- revisionOrBranch = '-r' + revision;
62
+ revisionOrBranch = `-r${revision}`;
64
63
  } else {
65
- revisionOrBranch = '-b' + branch;
64
+ revisionOrBranch = `-b${branch}`;
66
65
  }
67
66
  }
68
- (0, _index.log)('Going to clone ' + url + ' repo to ' + cacheDir + ' path');
67
+
68
+ (0, _index.log)(`Going to clone ${url} repo to ${cacheDir} path`);
69
69
  (0, _child_process.spawnSync)(type, ['clone', url, revisionOrBranch, projectName], {
70
70
  cwd: cacheDir,
71
71
  stdio: 'inherit'
72
72
  });
73
73
 
74
- _fs2.default.writeFileSync(_path2.default.join(projectPath, type === 'hg' ? '.hg' : '.git', 'remoteUrl'), url);
74
+ _fs.default.writeFileSync(_path.default.join(projectPath, type === 'hg' ? '.hg' : '.git', 'remoteUrl'), url);
75
75
 
76
76
  (0, _index.log)('Repository cloned!');
77
77
  };
78
78
 
79
- var getRemoteURL = function getRemoteURL() {
80
- var remoteUrl = _fs2.default.readFileSync(_path2.default.join(projectPath, type === 'hg' ? '.hg' : '.git', 'remoteUrl')).toString();
79
+ let getRemoteURL = () => {
80
+ let remoteUrl = _fs.default.readFileSync(_path.default.join(projectPath, type === 'hg' ? '.hg' : '.git', 'remoteUrl')).toString();
81
+
81
82
  return remoteUrl.trim();
82
83
  };
83
84
 
84
- if (_fs2.default.existsSync(projectPath)) {
85
- var remoteUrl = getRemoteURL();
85
+ if (_fs.default.existsSync(projectPath)) {
86
+ let remoteUrl = getRemoteURL();
86
87
 
87
88
  if (remoteUrl === url) {
88
89
  if (type === 'git') {
@@ -91,12 +92,14 @@ if (_fs2.default.existsSync(projectPath)) {
91
92
  stdio: 'inherit'
92
93
  });
93
94
  } else {
94
- var revisionOrBranch = void 0;
95
+ let revisionOrBranch;
96
+
95
97
  if (revision) {
96
- revisionOrBranch = '-r' + revision;
98
+ revisionOrBranch = `-r${revision}`;
97
99
  } else {
98
- revisionOrBranch = '-b' + branch;
100
+ revisionOrBranch = `-b${branch}`;
99
101
  }
102
+
100
103
  (0, _child_process.spawnSync)(type, ['pull', revisionOrBranch, '-u', url], {
101
104
  cwd: projectPath,
102
105
  stdio: 'inherit'
@@ -107,7 +110,6 @@ if (_fs2.default.existsSync(projectPath)) {
107
110
  cwd: cacheDir,
108
111
  stdio: 'inherit'
109
112
  });
110
-
111
113
  (0, _index.log)('Existing repository deleted!');
112
114
  cloneRepo();
113
115
  }
@@ -1,93 +1,80 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
- var https = require('https');
4
- var http = require('http');
5
- var url = require('url');
6
- var querystring = require('querystring');
3
+ const https = require('https');
7
4
 
8
- var isObject = function isObject(data) {
9
- return data && data.toString && data.toString() === '[object Object]';
10
- };
5
+ const http = require('http');
11
6
 
12
- var isArray = function isArray(data) {
13
- return data && Array.isArray(data);
14
- };
7
+ const url = require('url');
15
8
 
16
- process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
9
+ const querystring = require('querystring');
17
10
 
18
- var callback = function callback(resolve) {
19
- return function (res) {
20
- res.setEncoding('utf8');
21
- var str = '';
11
+ let isObject = data => data && data.toString && data.toString() === '[object Object]';
22
12
 
23
- res.on('data', function (chunk) {
24
- str += chunk;
25
- });
13
+ let isArray = data => data && Array.isArray(data);
26
14
 
27
- res.on('end', function () {
28
- resolve({
29
- body: str,
30
- response: res
31
- });
32
- });
15
+ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
33
16
 
34
- res.on('error', function (err) {
35
- process.stdout.write(err);
17
+ let callback = resolve => res => {
18
+ res.setEncoding('utf8');
19
+ let str = '';
20
+ res.on('data', chunk => {
21
+ str += chunk;
22
+ });
23
+ res.on('end', () => {
24
+ resolve({
25
+ body: str,
26
+ response: res
36
27
  });
37
- };
28
+ });
29
+ res.on('error', err => {
30
+ process.stdout.write(err);
31
+ });
38
32
  };
39
33
 
40
- var request = function request(options) {
41
- return new Promise(function (resolve, reject) {
42
- var _url$parse = url.parse(options.url),
43
- protocol = _url$parse.protocol,
44
- hostname = _url$parse.hostname,
45
- path = _url$parse.path,
46
- port = _url$parse.port;
47
-
48
- var _options$method = options.method,
49
- method = _options$method === undefined ? 'GET' : _options$method,
50
- _options$headers = options.headers,
51
- headers = _options$headers === undefined ? {} : _options$headers,
52
- _options$payload = options.payload,
53
- payload = _options$payload === undefined ? null : _options$payload,
54
- _options$formdata = options.formdata,
55
- formdata = _options$formdata === undefined ? null : _options$formdata;
56
-
57
-
58
- var newOptions = {
59
- host: hostname,
60
- port: port,
61
- path: path,
62
- method: method,
63
- headers: headers
64
- };
65
- var req = void 0;
66
-
67
- if (protocol === 'https:') {
68
- req = https.request(newOptions, callback(resolve));
69
- } else if (protocol === 'http:') {
70
- req = http.request(newOptions, callback(resolve));
71
- }
72
-
73
- if (method.toUpperCase() === 'POST') {
74
- if (isObject(payload) || isArray(payload)) {
75
- payload = JSON.stringify(payload);
76
- req.write(payload);
77
- } else if (isObject(formdata)) {
78
- formdata = querystring.stringify(formdata);
79
- req.write(formdata);
80
- }
34
+ let request = options => new Promise((resolve, reject) => {
35
+ let {
36
+ protocol,
37
+ hostname,
38
+ path,
39
+ port
40
+ } = url.parse(options.url);
41
+ let {
42
+ method = 'GET',
43
+ headers = {},
44
+ payload = null,
45
+ formdata = null
46
+ } = options;
47
+ let newOptions = {
48
+ host: hostname,
49
+ port: port,
50
+ path: path,
51
+ method: method,
52
+ headers: headers
53
+ };
54
+ let req;
55
+
56
+ if (protocol === 'https:') {
57
+ req = https.request(newOptions, callback(resolve));
58
+ } else if (protocol === 'http:') {
59
+ req = http.request(newOptions, callback(resolve));
60
+ }
61
+
62
+ if (method.toUpperCase() === 'POST') {
63
+ if (isObject(payload) || isArray(payload)) {
64
+ payload = JSON.stringify(payload);
65
+ req.write(payload);
66
+ } else if (isObject(formdata)) {
67
+ formdata = querystring.stringify(formdata);
68
+ req.write(formdata);
81
69
  }
70
+ }
82
71
 
83
- req.on('error', function (err) {
84
- //eslint-disable-next-line
85
- console.log(err);
86
- reject();
87
- });
88
-
89
- req.end();
72
+ req.on('error', err => {
73
+ //eslint-disable-next-line
74
+ console.log(err);
75
+ reject();
90
76
  });
91
- };
77
+ req.end();
78
+ });
92
79
 
93
80
  module.exports = request;