Skip to content

Commit 7a5c309

Browse files
authored
Bundle js (#790)
* #169 modules register it's javascript using bundleconfig.json
1 parent 5326354 commit 7a5c309

File tree

190 files changed

+4543
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+4543
-698
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,5 @@ $RECYCLE.BIN/
160160

161161
src/Modules/**/launchSettings.json
162162
PublishProfiles/
163-
logs/
163+
logs/
164+
src/Modules/**/wwwroot/admin/*.min.js

build/SimplCommerce.MSBuildTasks/CopyModuleTask.cs

Lines changed: 50 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ namespace SimplCommerce.MSBuildTasks
1010
{
1111
public class CopyModuleTask : Task
1212
{
13+
private readonly string modulesFileName = "modules.json";
14+
private readonly string moduleFileName = "module.json";
15+
private readonly string bundleConfigFileName = "bundleconfig.json";
16+
1317
[Required]
1418
public string ProjectDir { get; set; }
1519

@@ -21,8 +25,6 @@ public class CopyModuleTask : Task
2125

2226
public override bool Execute()
2327
{
24-
var modulesFileName = "modules.json";
25-
var moduleFileName = "module.json";
2628
var modulesFilePath = Path.Combine(ProjectDir, modulesFileName);
2729
if (!File.Exists(modulesFilePath))
2830
{
@@ -33,49 +35,67 @@ public override bool Execute()
3335
var modules = new List<Module>();
3436
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(modulesFileName))))
3537
{
36-
var ser = new DataContractJsonSerializer(modules.GetType());
37-
modules = ser.ReadObject(ms) as List<Module>;
38+
var dataContractJsonSerializer = new DataContractJsonSerializer(modules.GetType());
39+
modules = dataContractJsonSerializer.ReadObject(ms) as List<Module>;
3840
}
3941

4042
foreach (var module in modules)
4143
{
42-
var sourceRoot = Path.Combine(new DirectoryInfo(ProjectDir).Parent.FullName, "Modules", module.Id);
43-
var moduleManifestFile = Path.Combine(sourceRoot, moduleFileName);
44-
if (!File.Exists(moduleManifestFile))
44+
var isSuccess = CopyModule(module);
45+
if (!isSuccess)
4546
{
46-
Log.LogError($"{moduleFileName} is not fould for {module.Id}");
4747
return false;
4848
}
49+
}
4950

50-
ModuleManifest moduleManifest = null;
51-
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(moduleManifestFile))))
52-
{
53-
var ser = new DataContractJsonSerializer(typeof(ModuleManifest));
54-
moduleManifest = ser.ReadObject(ms) as ModuleManifest;
55-
}
51+
return true;
52+
}
53+
54+
private bool CopyModule(Module module)
55+
{
56+
var sourceRoot = Path.Combine(new DirectoryInfo(ProjectDir).Parent.FullName, "Modules", module.Id);
57+
var moduleManifestFile = Path.Combine(sourceRoot, moduleFileName);
58+
if (!File.Exists(moduleManifestFile))
59+
{
60+
Log.LogError($"{moduleFileName} is not fould for {module.Id}");
61+
return false;
62+
}
63+
64+
ModuleManifest moduleManifest = null;
65+
using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(File.ReadAllText(moduleManifestFile))))
66+
{
67+
var ser = new DataContractJsonSerializer(typeof(ModuleManifest));
68+
moduleManifest = ser.ReadObject(ms) as ModuleManifest;
69+
}
5670

57-
var destination = Path.Combine(ProjectDir, "Modules", module.Id);
58-
var destinationWwwroot = Path.Combine(ProjectDir, "wwwroot", "modules", module.Id.Split('.').Last().ToLower());
71+
var destination = Path.Combine(ProjectDir, "Modules", module.Id);
72+
var destinationWwwroot = Path.Combine(ProjectDir, "wwwroot", "modules", module.Id.Split('.').Last().ToLower());
5973

60-
CreateOrCleanDirectory(destinationWwwroot);
61-
CreateOrCleanDirectory(destination);
74+
CreateOrCleanDirectory(destinationWwwroot);
75+
CreateOrCleanDirectory(destination);
6276

63-
File.Copy(Path.Combine(sourceRoot, moduleFileName),
64-
Path.Combine(destination, moduleFileName), true);
65-
CopyDirectory(Path.Combine(sourceRoot, "wwwroot"), destinationWwwroot);
66-
if (!moduleManifest.IsBundledWithHost)
67-
{
68-
CopyDirectory(Path.Combine(sourceRoot, "bin", BuildConfiguration, TargetFramework), Path.Combine(destination, "bin"));
69-
}
77+
File.Copy(Path.Combine(sourceRoot, moduleFileName),
78+
Path.Combine(destination, moduleFileName), true);
7079

71-
if (module.Id == "SimplCommerce.Module.SampleData")
72-
{
73-
CopyDirectory(Path.Combine(sourceRoot, "SampleContent"), Path.Combine(destination, "SampleContent"));
74-
}
80+
var bundleConfigFile = Path.Combine(sourceRoot, bundleConfigFileName);
81+
if (File.Exists(bundleConfigFile))
82+
{
83+
File.Copy(Path.Combine(bundleConfigFile),
84+
Path.Combine(destination, bundleConfigFileName), true);
85+
}
86+
87+
CopyDirectory(Path.Combine(sourceRoot, "wwwroot"), destinationWwwroot);
88+
if (!moduleManifest.IsBundledWithHost)
89+
{
90+
CopyDirectory(Path.Combine(sourceRoot, "bin", BuildConfiguration, TargetFramework), Path.Combine(destination, "bin"));
91+
}
7592

76-
Log.LogMessage(MessageImportance.High, $"Copied module {module.Id}");
93+
if (module.Id == "SimplCommerce.Module.SampleData")
94+
{
95+
CopyDirectory(Path.Combine(sourceRoot, "SampleContent"), Path.Combine(destination, "SampleContent"));
7796
}
7897

98+
Log.LogMessage(MessageImportance.High, $"Copied module {module.Id}");
7999
return true;
80100
}
81101

0 Bytes
Binary file not shown.

build/netcoreapp2.0/SimplCommerce.MSBuildTasks.deps.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@
270270
"System.Collections.Immutable/1.5.0": {
271271
"type": "package",
272272
"serviceable": true,
273-
"sha512": "sha512-RGxi2aQoXgZ5ge0zxrKqI4PU9LrYYoLC+cnEnWXKsSduCOUhE1GEAAoTexUVT8RZOILQyy1B27HC8Xw/XLGzdQ==",
273+
"sha512": "sha512-EXKiDFsChZW0RjrZ4FYHu9aW6+P4MCgEDCklsVseRfhoO0F+dXeMSsMRAlVXIo06kGJ/zv+2w1a2uc2+kxxSaQ==",
274274
"path": "system.collections.immutable/1.5.0",
275275
"hashPath": "system.collections.immutable.1.5.0.nupkg.sha512"
276276
},
512 Bytes
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"outputFileName": "wwwroot/admin/activitylog.min.js",
4+
"inputFiles": [
5+
"wwwroot/admin/activitylog.module.js",
6+
"wwwroot/admin/activitylog-service.js",
7+
"wwwroot/admin/most-viewed-products.directive.js"
8+
],
9+
"minify": {
10+
"enabled": true,
11+
"renameLocals": true
12+
},
13+
"sourceMap": false
14+
}
15+
]

src/Modules/SimplCommerce.Module.ActivityLog/wwwroot/admin/activitylog-service.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.activityLog')
5-
.factory('activityLogService', activityLogService);
5+
.factory('activityLogService', ['$http', activityLogService]);
66

7-
/* @ngInject */
87
function activityLogService($http) {
98
var service = {
109
getMostViewedEntities: getMostViewedEntities
@@ -15,4 +14,4 @@
1514
return $http.get('api/activitylog/most-viewed-entities/' + entityTypeId);
1615
}
1716
}
18-
})();
17+
})();

src/Modules/SimplCommerce.Module.ActivityLog/wwwroot/admin/most-viewed-products.directive.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
restrict: 'E',
99
templateUrl: 'modules/activitylog/admin/most-viewed-products.directive.html',
1010
scope: {},
11-
controller: MostMostViewedProductCtrl,
11+
controller: ['activityLogService', 'translateService', MostMostViewedProductCtrl],
1212
controllerAs: 'vm',
1313
bindToController: true
1414
};
1515

1616
return directive;
1717
}
1818

19-
/* @ngInject */
2019
function MostMostViewedProductCtrl(activityLogService, translateService) {
2120
var vm = this;
2221
vm.translate = translateService;
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
[
2+
{
3+
"outputFileName": "wwwroot/admin/catalog.min.js",
4+
"inputFiles": [
5+
"wwwroot/admin/catalog.module.js",
6+
"wwwroot/admin/brand/brand-service.js",
7+
"wwwroot/admin/brand/brand-list.js",
8+
"wwwroot/admin/brand/brand-form.js",
9+
"wwwroot/admin/category/category-service.js",
10+
"wwwroot/admin/category/category-list.js",
11+
"wwwroot/admin/category/category-form.js",
12+
"wwwroot/admin/category/category-translation-form.js",
13+
"wwwroot/admin/product-option/product-option-service.js",
14+
"wwwroot/admin/product-option/product-option-list.js",
15+
"wwwroot/admin/product-option/product-option-form.js",
16+
"wwwroot/admin/product-attribute-group/product-attribute-group-service.js",
17+
"wwwroot/admin/product-attribute-group/product-attribute-group-list.js",
18+
"wwwroot/admin/product-attribute-group/product-attribute-group-form.js",
19+
"wwwroot/admin/product-attribute/product-attribute-service.js",
20+
"wwwroot/admin/product-attribute/product-attribute-list.js",
21+
"wwwroot/admin/product-attribute/product-attribute-form.js",
22+
"wwwroot/admin/product-template/product-template-service.js",
23+
"wwwroot/admin/product-template/product-template-list.js",
24+
"wwwroot/admin/product-template/product-template-form.js",
25+
"wwwroot/admin/product/product-service.js",
26+
"wwwroot/admin/product/product-list.js",
27+
"wwwroot/admin/product/product-option-display-directive.js",
28+
"wwwroot/admin/product/product-selection-directive.js",
29+
"wwwroot/admin/product/product-form.js",
30+
"wwwroot/admin/product/product-translation-form.js",
31+
"wwwroot/admin/product-widget/product-widget-service.js",
32+
"wwwroot/admin/product-widget/product-widget-form.js",
33+
"wwwroot/admin/category-widget/category-widget-service.js",
34+
"wwwroot/admin/category-widget/category-widget-form.js",
35+
"wwwroot/admin/simple-product-widget/simple-product-widget-service.js",
36+
"wwwroot/admin/simple-product-widget/simple-product-widget-form.js",
37+
"wwwroot/admin/product-price/product-price-service.js",
38+
"wwwroot/admin/product-price/product-price-form.js",
39+
"wwwroot/admin/product-clone/product-clone-service.js",
40+
"wwwroot/admin/product-clone/product-clone-form.js"
41+
],
42+
"minify": {
43+
"enabled": true,
44+
"renameLocals": true
45+
},
46+
"sourceMap": false
47+
}
48+
]

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-form.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('BrandFormCtrl', BrandFormCtrl);
5+
.controller('BrandFormCtrl', ['$state', '$stateParams', 'brandService', 'translateService', BrandFormCtrl]);
66

7-
/* @ngInject */
87
function BrandFormCtrl($state, $stateParams, brandService, translateService) {
98
var vm = this;
109
vm.translate = translateService;
@@ -51,4 +50,4 @@
5150

5251
init();
5352
}
54-
})();
53+
})();

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-list.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('BrandListCtrl', BrandListCtrl);
5+
.controller('BrandListCtrl', ['brandService', 'translateService', BrandListCtrl]);
66

7-
/* @ngInject */
87
function BrandListCtrl(brandService, translateService) {
98
var vm = this;
109
vm.translate = translateService;
@@ -33,4 +32,4 @@
3332

3433
vm.getBrands();
3534
}
36-
})();
35+
})();

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/brand/brand-service.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.factory('brandService', brandService);
5+
.factory('brandService', ['$http', brandService]);
66

7-
/* @ngInject */
87
function brandService($http) {
98
var service = {
109
getBrand: getBrand,
@@ -35,4 +34,4 @@
3534
return $http.delete('api/brands/' + brand.id, null);
3635
}
3736
}
38-
})();
37+
})();

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category-widget/category-widget-form.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function ($) {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('CategoryWidgetFormCtrl', CategoryWidgetFormCtrl);
5+
.controller('CategoryWidgetFormCtrl', ['$state', '$stateParams', 'categoryWidgetService', 'translateService', CategoryWidgetFormCtrl]);
66

7-
/* @ngInject */
87
function CategoryWidgetFormCtrl($state, $stateParams, categoryWidgetService , translateService) {
98
var vm = this;
109
vm.translate = translateService;
@@ -80,4 +79,4 @@
8079

8180
init();
8281
}
83-
})(jQuery);
82+
})(jQuery);

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category-widget/category-widget-service.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.factory('categoryWidgetService', categoryWidgetService);
5+
.factory('categoryWidgetService', ['$http', categoryWidgetService]);
66

7-
/* @ngInject */
87
function categoryWidgetService($http) {
98
var service = {
109
getWidgetZones: getWidgetZones,
@@ -40,4 +39,4 @@
4039
return $http.get('api/widget-instances/number-of-widgets');
4140
}
4241
}
43-
})();
42+
})();

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-form.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('CategoryFormCtrl', CategoryFormCtrl);
5+
.controller('CategoryFormCtrl', ['$q', '$state', '$stateParams', 'categoryService', 'translateService', CategoryFormCtrl]);
66

7-
/* @ngInject */
87
function CategoryFormCtrl($q, $state, $stateParams, categoryService, translateService) {
98
var vm = this,
109
tableStateRef;

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-list.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('CategoryListCtrl', CategoryLitsCtrl);
5+
.controller('CategoryListCtrl', ['categoryService', 'translateService', '$window', CategoryLitsCtrl]);
66

7-
/* @ngInject */
87
function CategoryLitsCtrl(categoryService, translateService, $window) {
98
var vm = this;
109
vm.translate = translateService;

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-service.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.factory('categoryService', categoryService);
5+
.factory('categoryService', ['$http', 'Upload', categoryService]);
66

7-
/* @ngInject */
87
function categoryService($http, Upload) {
98
var service = {
109
getCategory: getCategory,

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/category/category-translation-form.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('CategoryTranslationFormCtrl', CategoryTranslationFormCtrl);
5+
.controller('CategoryTranslationFormCtrl', ['$state', '$stateParams', 'categoryService', 'translateService', CategoryTranslationFormCtrl]);
66

7-
/* @ngInject */
87
function CategoryTranslationFormCtrl($state, $stateParams, categoryService, translateService) {
98
var vm = this;
109
vm.translate = translateService;

src/Modules/SimplCommerce.Module.Catalog/wwwroot/admin/product-attribute-group/product-attribute-group-form.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
(function () {
33
angular
44
.module('simplAdmin.catalog')
5-
.controller('ProductAttributeGroupFormCtrl', ProductAttributeGroupFormCtrl);
5+
.controller('ProductAttributeGroupFormCtrl', ['$state', '$stateParams', 'productAttributeGroupService', 'translateService', ProductAttributeGroupFormCtrl]);
66

7-
/* @ngInject */
87
function ProductAttributeGroupFormCtrl($state, $stateParams, productAttributeGroupService, translateService) {
98
var vm = this;
109
vm.translate = translateService;
@@ -52,4 +51,4 @@
5251

5352
init();
5453
}
55-
})();
54+
})();

0 commit comments

Comments
 (0)