@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.
- package/CHANGELOG.md +5 -0
- package/README.md +149 -0
- package/bin/cli.js +34 -29
- package/files/eslintrc.js +57 -0
- package/files/prettierrc.js +3 -0
- package/lib/babel/cmjs-plugins-presets.js +16 -9
- package/lib/babel/es-plugins-presets.js +26 -14
- package/lib/common/getEntries.js +31 -22
- package/lib/common/getPublicPathConfig.js +27 -13
- package/lib/common/index.js +21 -25
- package/lib/common/splitChunks.js +62 -53
- package/lib/common/templateParameters.js +10 -8
- package/lib/configs/jest.config.js +15 -25
- package/lib/configs/webpack.component.umd.config.js +31 -37
- package/lib/configs/webpack.css.umd.config.js +44 -47
- package/lib/configs/webpack.dev.config.js +70 -52
- package/lib/configs/webpack.docs.config.js +106 -106
- package/lib/configs/webpack.prod.config.js +95 -75
- package/lib/hooks/docsProptypeHook.js +32 -38
- package/lib/jest/commitedFilesResult.js +103 -74
- package/lib/jest/coverageCollector.js +41 -21
- package/lib/jest/jsonMaker.js +15 -16
- package/lib/jest/preProcessors/cssPreprocessor.js +16 -18
- package/lib/jest/preProcessors/jsPreprocessor.js +3 -5
- package/lib/jest/preProcessors/otherFilesPreprocessor.js +5 -6
- package/lib/jest/result.js +90 -45
- package/lib/jest/run.js +43 -43
- package/lib/jest/setup.js +102 -95
- package/lib/loaderUtils/getCSSLoaders.js +21 -22
- package/lib/loaderUtils/getDevJsLoaders.js +25 -23
- package/lib/loaderUtils/index.js +11 -13
- package/lib/loaders/docsLoader.js +15 -15
- package/lib/loaders/docsPropsLoader.js +14 -17
- package/lib/loaders/fileLoader.js +33 -35
- package/lib/loaders/scriptInstrumentLoader.js +21 -20
- package/lib/loaders/workerLoader.js +136 -0
- package/lib/middlewares/HMRMiddleware.js +54 -45
- package/lib/middlewares/SSTMiddleware.js +8 -5
- package/lib/pluginUtils/getDevPlugins.js +114 -52
- package/lib/pluginUtils/getDocsPlugins.js +25 -29
- package/lib/pluginUtils/getLibraryPlugins.js +8 -10
- package/lib/pluginUtils/getProdPlugins.js +163 -74
- package/lib/pluginUtils/getServerPlugins.js +8 -11
- package/lib/pluginUtils/getUMDCSSPlugins.js +11 -15
- package/lib/pluginUtils/getUMDComponentPlugins.js +11 -15
- package/lib/pluginUtils/index.js +36 -43
- package/lib/plugins/CdnChangePlugin.js +63 -0
- package/lib/plugins/CleanupStatsPlugin.js +18 -32
- package/lib/plugins/CustomAttributePlugin.js +79 -0
- package/lib/plugins/CustomAttributePlugin.md +35 -0
- package/lib/plugins/EFCPlugin.js +185 -0
- package/lib/plugins/I18NInjectIntoIndexPlugin.js +118 -52
- package/lib/plugins/I18nSplitPlugin/I18nDebugPlugin.js +60 -0
- package/lib/plugins/I18nSplitPlugin/I18nDependency.js +44 -0
- package/lib/plugins/I18nSplitPlugin/I18nDownlodLogic.js +266 -0
- package/lib/plugins/I18nSplitPlugin/I18nFilesEmitter.js +183 -0
- package/lib/plugins/I18nSplitPlugin/I18nKeysIdentifer.js +100 -0
- package/lib/plugins/I18nSplitPlugin/I18nSplit.md +86 -0
- package/lib/plugins/I18nSplitPlugin/README.md +25 -0
- package/lib/plugins/I18nSplitPlugin/index.js +185 -0
- package/lib/plugins/I18nSplitPlugin/utils/collectI18nKeys.js +64 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nFileUrlPathTemplate.js +13 -0
- package/lib/plugins/I18nSplitPlugin/utils/getI18nKeysFormModules.js +26 -0
- package/lib/plugins/I18nSplitPlugin/utils/hashUtils.js +40 -0
- package/lib/plugins/I18nSplitPlugin/utils/index.js +31 -0
- package/lib/plugins/I18nSplitPlugin/utils/propertiesUtils.js +112 -0
- package/lib/plugins/ManifestPlugin.js +52 -63
- package/lib/plugins/ModuleStatsPlugin.js +83 -173
- package/lib/plugins/OptimizeJSPlugin.js +24 -41
- package/lib/plugins/PublicPathCallbackPlugin.js +42 -116
- package/lib/plugins/PublicPathChangePlugin.js +175 -284
- package/lib/plugins/ReportGeneratePlugin.js +150 -151
- package/lib/plugins/ResourceHintsPlugin.js +53 -35
- package/lib/plugins/ScriptInstrumentPlugin.js +22 -37
- package/lib/plugins/ServiceWorkerPlugin.js +81 -57
- package/lib/plugins/ShadowDOMSupportPlugin.js +153 -234
- package/lib/plugins/SourceMapHookPlugin.js +21 -33
- package/lib/plugins/TPHashMappingPlugin.js +67 -0
- package/lib/plugins/UglifyCSSPlugin.js +23 -30
- package/lib/plugins/UnusedFilesFindPlugin.js +137 -152
- package/lib/plugins/index.js +100 -91
- package/lib/plugins/webpackwatchrunplugin.js +18 -30
- package/lib/postcss-plugins/ExcludeRTLPlugin.js +14 -17
- package/lib/schemas/index.js +336 -81
- package/lib/servers/clusterHubServer.js +22 -26
- package/lib/servers/docsServer.js +3 -5
- package/lib/servers/docsServerCore.js +84 -91
- package/lib/servers/helpServer.js +19 -21
- package/lib/servers/impactServer.js +99 -92
- package/lib/servers/mockserver.js +24 -24
- package/lib/servers/scrServer.js +78 -98
- package/lib/servers/server.js +101 -122
- package/lib/servers/ssServer.js +63 -61
- package/lib/sh/reportPublish.sh +1 -2
- package/lib/templates/CoverageScriptTemplate.js +45 -18
- package/lib/templates/WMSTemplate.js +17 -18
- package/lib/templates/linterConstant.js +6 -4
- package/lib/utils/babelPresets.js +12 -5
- package/lib/utils/clean.js +12 -11
- package/lib/utils/copy.js +12 -34
- package/lib/utils/copyTimezones.js +9 -16
- package/lib/utils/createEventStream.js +24 -19
- package/lib/utils/cssClassNameGenerate.js +44 -73
- package/lib/utils/cssURLReplacer.js +62 -56
- package/lib/utils/dependencyPostPublish.js +20 -19
- package/lib/utils/fileUtils.js +66 -54
- package/lib/utils/folderIterator.js +20 -21
- package/lib/utils/getComponents.js +70 -27
- package/lib/utils/getCurrentBranch.js +11 -17
- package/lib/utils/getDependenciesImpactList.js +114 -187
- package/lib/utils/getHash.js +9 -13
- package/lib/utils/getIp.js +9 -9
- package/lib/utils/getOptions.js +26 -29
- package/lib/utils/getServerURL.js +19 -10
- package/lib/utils/index.js +147 -126
- package/lib/utils/init.js +2 -2
- package/lib/utils/initPreCommitHook.js +40 -32
- package/lib/utils/jsonHelper.js +37 -21
- package/lib/utils/lint/addScripts.js +27 -0
- package/lib/utils/lint/checkExistingConfig.js +67 -0
- package/lib/utils/lint/copyConfigs.js +24 -0
- package/lib/utils/lint/index.js +54 -0
- package/lib/utils/lint/lintScripts.js +11 -0
- package/lib/utils/lint/lintSetup.js +31 -0
- package/lib/utils/lint/lintStagedPreCommitHook.js +7 -0
- package/lib/utils/lint/question.js +30 -0
- package/lib/utils/lintReporter.js +70 -56
- package/lib/utils/mailSender.js +12 -27
- package/lib/utils/pullOrigin.js +21 -18
- package/lib/utils/reinstallDependencies.js +76 -85
- package/lib/utils/removeAttributes.js +25 -23
- package/lib/utils/repoClone.js +47 -45
- package/lib/utils/request.js +64 -77
- package/lib/utils/rtl.js +22 -29
- package/lib/utils/setEnvVariables.js +5 -6
- package/lib/utils/ssTestHack.js +21 -19
- package/lib/utils/switchBranch.js +21 -20
- package/lib/utils/urlConcat.js +22 -0
- package/package.json +72 -67
package/lib/utils/pullOrigin.js
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
-
|
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(
|
8
|
+
var _child_process = require("child_process");
|
8
9
|
|
9
|
-
var _utils = require(
|
10
|
+
var _utils = require("../utils");
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.
|
6
|
+
exports.reinstallDependencies1 = exports.reinstallDependencies = exports.collectPackageDiff = void 0;
|
7
7
|
|
8
|
-
var _fs = require(
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
9
|
|
10
|
-
var
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
11
11
|
|
12
|
-
var
|
12
|
+
var _child_process = require("child_process");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _gitRootDir = _interopRequireDefault(require("git-root-dir"));
|
15
15
|
|
16
|
-
var
|
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
|
-
|
20
|
+
let packageJsons = {};
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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 =
|
75
|
-
|
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
|
-
|
80
|
-
|
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,
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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)(
|
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'], {
|
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
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _getOptions = require(
|
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
|
-
|
7
|
+
let options = (0, _getOptions.default)();
|
8
|
+
let {
|
9
|
+
app: {
|
10
|
+
attrbuteNames
|
11
|
+
}
|
12
|
+
} = options;
|
10
13
|
|
11
|
-
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
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
|
+
});
|
package/lib/utils/repoClone.js
CHANGED
@@ -1,88 +1,89 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
var _os = require(
|
3
|
+
var _os = require("os");
|
4
4
|
|
5
|
-
var _path = require(
|
5
|
+
var _path = _interopRequireDefault(require("path"));
|
6
6
|
|
7
|
-
var
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
8
8
|
|
9
|
-
var
|
9
|
+
var _child_process = require("child_process");
|
10
10
|
|
11
|
-
var
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
type
|
23
|
-
url
|
24
|
-
branch
|
25
|
-
revision
|
26
|
-
projectName
|
27
|
-
cacheDir
|
28
|
-
remoteName
|
29
|
-
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)(
|
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 =
|
36
|
+
cacheDir = _path.default.join((0, _os.homedir)(), '.react-cli');
|
40
37
|
} else {
|
41
|
-
cacheDir =
|
38
|
+
cacheDir = _path.default.join(process.cwd(), cacheDir);
|
42
39
|
}
|
43
40
|
|
44
41
|
if (!projectName) {
|
45
|
-
|
46
|
-
|
42
|
+
let {
|
43
|
+
name
|
44
|
+
} = _path.default.parse(url);
|
47
45
|
|
48
46
|
projectName = name;
|
49
47
|
}
|
50
48
|
|
51
|
-
|
49
|
+
let projectPath = _path.default.join(cacheDir, projectName);
|
52
50
|
|
53
|
-
|
54
|
-
if (!
|
55
|
-
|
51
|
+
let cloneRepo = () => {
|
52
|
+
if (!_fs.default.existsSync(cacheDir)) {
|
53
|
+
_fs.default.mkdirSync(cacheDir);
|
56
54
|
}
|
57
|
-
|
55
|
+
|
56
|
+
let revisionOrBranch;
|
58
57
|
|
59
58
|
if (type === 'git') {
|
60
|
-
revisionOrBranch =
|
59
|
+
revisionOrBranch = `-b${branch}`;
|
61
60
|
} else {
|
62
61
|
if (revision) {
|
63
|
-
revisionOrBranch =
|
62
|
+
revisionOrBranch = `-r${revision}`;
|
64
63
|
} else {
|
65
|
-
revisionOrBranch =
|
64
|
+
revisionOrBranch = `-b${branch}`;
|
66
65
|
}
|
67
66
|
}
|
68
|
-
|
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
|
-
|
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
|
-
|
80
|
-
|
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 (
|
85
|
-
|
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
|
-
|
95
|
+
let revisionOrBranch;
|
96
|
+
|
95
97
|
if (revision) {
|
96
|
-
revisionOrBranch =
|
98
|
+
revisionOrBranch = `-r${revision}`;
|
97
99
|
} else {
|
98
|
-
revisionOrBranch =
|
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
|
}
|
package/lib/utils/request.js
CHANGED
@@ -1,93 +1,80 @@
|
|
1
|
-
|
1
|
+
"use strict";
|
2
2
|
|
3
|
-
|
4
|
-
var http = require('http');
|
5
|
-
var url = require('url');
|
6
|
-
var querystring = require('querystring');
|
3
|
+
const https = require('https');
|
7
4
|
|
8
|
-
|
9
|
-
return data && data.toString && data.toString() === '[object Object]';
|
10
|
-
};
|
5
|
+
const http = require('http');
|
11
6
|
|
12
|
-
|
13
|
-
return data && Array.isArray(data);
|
14
|
-
};
|
7
|
+
const url = require('url');
|
15
8
|
|
16
|
-
|
9
|
+
const querystring = require('querystring');
|
17
10
|
|
18
|
-
|
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
|
-
|
24
|
-
str += chunk;
|
25
|
-
});
|
13
|
+
let isArray = data => data && Array.isArray(data);
|
26
14
|
|
27
|
-
|
28
|
-
resolve({
|
29
|
-
body: str,
|
30
|
-
response: res
|
31
|
-
});
|
32
|
-
});
|
15
|
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
33
16
|
|
34
|
-
|
35
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
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
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
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;
|