From 6c99e48dac76a6787624ae84d13420a387ab4658 Mon Sep 17 00:00:00 2001 From: cipchk Date: Mon, 1 Jul 2024 23:19:22 +0800 Subject: [PATCH] fix(cli): remove `ng-less-javascript-enabled-patch` --- package.json | 6 +- packages/theme/system/mixins/_freak.js | 49 ++++++++++++++++ packages/theme/system/mixins/_freak.less | 58 +------------------ packages/theme/system/utils/_border.less | 41 ++++++++----- packages/theme/system/utils/_color.less | 46 +++++++-------- packages/theme/system/utils/_spacing.less | 35 +++++++---- packages/theme/system/utils/_width.less | 15 +++-- schematics/migration.json | 4 +- schematics/ng-update/index.ts | 3 +- .../ng-update/upgrade-rules/V18/index.spec.ts | 42 ++++++++++++++ .../ng-update/upgrade-rules/V18/index.ts | 29 ++++++++++ ...remove-ng-less-javascript-enabled-patch.ts | 22 +++++++ schematics/test.ts | 2 +- src/assets/yarn.lock.txt | 22 ++----- yarn.lock | 22 ++----- 15 files changed, 244 insertions(+), 152 deletions(-) create mode 100644 packages/theme/system/mixins/_freak.js create mode 100644 schematics/ng-update/upgrade-rules/V18/index.spec.ts create mode 100644 schematics/ng-update/upgrade-rules/V18/index.ts create mode 100644 schematics/ng-update/upgrade-rules/V18/remove-ng-less-javascript-enabled-patch.ts diff --git a/package.json b/package.json index cdbae5623..c8b3d5abe 100644 --- a/package.json +++ b/package.json @@ -38,8 +38,7 @@ "build_artifacts": "bash scripts/ci/build-artifacts.sh", "analyze": "npm run ng-high-memory build -- --source-map", "analyze:view": "source-map-explorer src/dist/browser/*.js", - "site:gen": "node scripts/site/main init", - "site:gen:TODO": "node scripts/site/main init && ng-alain-plugin-theme -t=themeCss && ng-alain-plugin-theme -t=colorLess", + "site:gen": "node scripts/site/main init && ng-alain-plugin-theme -t=themeCss && ng-alain-plugin-theme -t=colorLess", "site:build": "npm run site:gen && ng b site && npm run site:ngsw && npm run site:minify && npm run site:sitemap && npm run site:helper", "site:helper": "bash scripts/ci/helper.sh", "site:minify": "node scripts/build/minify.js", @@ -153,9 +152,8 @@ "mark-twain": "^2.0.3", "mockjs": "^1.1.0", "mustache": "^4.2.0", - "ng-alain-plugin-theme": "^16.0.2", + "ng-alain-plugin-theme": "^18.0.0", "ng-alain-sts": "^0.0.2", - "ng-less-javascript-enabled-patch": "17.0.2", "ng-packagr": "^18.0.0", "parse5": "^7.1.2", "plyr": "^3.7.8", diff --git a/packages/theme/system/mixins/_freak.js b/packages/theme/system/mixins/_freak.js new file mode 100644 index 000000000..4c811a93c --- /dev/null +++ b/packages/theme/system/mixins/_freak.js @@ -0,0 +1,49 @@ +module.exports = { + install: function (less, pluginManager, functions) { + functions.add('genComment', function (value, ...comments) { + return ( + '/* AUTOGENERATE: ' + + comments + .map(c => c.value) + .join('|SPLIT|') + .replace(/(\{0\})/g, '"' + value.value + '"') + + '*/' + ); + }); + functions.add('genCommentColor', function (color, ...comments) { + var imgColor = ' ![Color](https://dummyimage.com/20x20/' + color.value.substring(1) + '/fff.png&text=+)'; + return ( + '/* AUTOGENERATE: ' + + comments + .map(c => c.value + imgColor) + .join('|SPLIT|') + .replace(/(\{0\})/g, '"' + color.value + '"') + + '*/' + ); + }); + functions.add('genCommentTypeColor', function (type, color) { + var comments = []; + switch (type.value) { + case 'text': + comments = ['Set the text color to {0}', '设置文本颜色为 {0}']; + break; + case 'background': + comments = ['Set the background light color to {0}', '设置背景颜色为 {0}']; + break; + case 'hoverBackground': + comments = ['Set the hover background color to {0}', '设置悬停时背景颜色为 {0}']; + break; + } + if (comments.length === 0) return ''; + var imgColor = ' ![Color](https://dummyimage.com/20x20/' + color.value.substring(1) + '/fff.png&text=+)'; + return ( + '/* AUTOGENERATE: ' + + comments + .map(c => c + imgColor) + .join('|SPLIT|') + .replace(/(\{0\})/g, '"' + color.value + '"') + + '*/' + ); + }); + } +}; diff --git a/packages/theme/system/mixins/_freak.less b/packages/theme/system/mixins/_freak.less index afe89d03e..3696a270f 100644 --- a/packages/theme/system/mixins/_freak.less +++ b/packages/theme/system/mixins/_freak.less @@ -1,57 +1 @@ -.freakMixin() { - @functions: ~`(function() { - function toColorList(list) { - list = list.slice(1, list.length - 1).split(','); - var ret = []; - for (var i = 0, c = list.length; i < c; i++) { - ret.push(list[i].trim().split(' ')); - } - return ret; - } - - var catchColors; - function _initColor(list) { - if (!catchColors) catchColors = toColorList(list); - } - - this.getColor = function(list, name, position) { - _initColor(list); - var ret = ''; - for (var i = 0, c = catchColors.length; i < c; i++) { - if (catchColors[i][0] === name) { - ret = catchColors[i][position - 1]; - break; - } - } - return ret; - } - - this.genComment = function(value, ...comments) { - return '/* AUTOGENERATE: ' + comments.join('|SPLIT|').replace(/(\{0\})/g, '"' + value + '"') + '*/'; - } - - this.genCommentColor = function(color, ...comments) { - var imgColor = ' ![Color](https://dummyimage.com/20x20/' + color.substring(1) + '/fff.png&text=+)'; - return '/* AUTOGENERATE: ' + comments.map(c => c + imgColor).join('|SPLIT|').replace(/(\{0\})/g, '"' + color + '"') + '*/'; - } - - this.genCommentTypeColor = function(type, color) { - var comments = []; - switch (type) { - case 'text': - comments = ['Set the text color to {0}', '设置文本颜色为 {0}']; - break; - case 'background': - comments = ['Set the background light color to {0}', '设置背景颜色为 {0}']; - break; - case 'hoverBackground': - comments = ['Set the hover background color to {0}', '设置悬停时背景颜色为 {0}']; - break; - } - if (comments.length === 0) return ''; - var imgColor = ' ![Color](https://dummyimage.com/20x20/' + color.substring(1) + '/fff.png&text=+)'; - return '/* AUTOGENERATE: ' + comments.map(c => c + imgColor).join('|SPLIT|').replace(/(\{0\})/g, '"' + color + '"') + '*/'; - } - })()`; -} -.freakMixin(); +@plugin "./_freak"; \ No newline at end of file diff --git a/packages/theme/system/utils/_border.less b/packages/theme/system/utils/_border.less index 666056d39..7ed1a2f9e 100644 --- a/packages/theme/system/utils/_border.less +++ b/packages/theme/system/utils/_border.less @@ -12,35 +12,42 @@ } @border-width-list: 0, 1; + .for(@border-width-list, { .border-css-mixin(@i) when(@i > 0) { @css-value-comment: ~'1px'; @css-value: ~'@{i}px solid @{border-color}'; } + .border-css-mixin(@i) when(default()) { @css-value-comment: ~'0px'; @css-value: 0; } + .border-css-mixin(@adIndex); .border-@{adIndex} { - e(~`genComment('@{css-value-comment}', 'Set the border size to {0}', '设置边框大小为 {0}')`); + genComment('@{css-value-comment}', 'Set the border size to {0}', '设置边框大小为 {0}'); border: @css-value !important; } + .border-top-@{adIndex} { - e(~`genComment('@{css-value-comment}', 'Set the top border size to {0}', '设置上边框大小为 {0}')`); + genComment('@{css-value-comment}', 'Set the top border size to {0}', '设置上边框大小为 {0}'); border-top: @css-value !important; } + .border-right-@{adIndex} { - e(~`genComment('@{css-value-comment}', 'Set the right border size to {0}', '设置右边框大小为 {0}')`); + genComment('@{css-value-comment}', 'Set the right border size to {0}', '设置右边框大小为 {0}'); border-right: @css-value !important; } + .border-bottom-@{adIndex} { - e(~`genComment('@{css-value-comment}', 'Set the bottom border size to {0}', '设置下边框大小为 {0}')`); + genComment('@{css-value-comment}', 'Set the bottom border size to {0}', '设置下边框大小为 {0}'); border-bottom: @css-value !important; } + .border-left-@{adIndex} { - e(~`genComment('@{css-value-comment}', 'Set the left border size to {0}', '设置左边框大小为 {0}')`); + genComment('@{css-value-comment}', 'Set the left border size to {0}', '设置左边框大小为 {0}'); border-left: @css-value !important; } }); @@ -49,14 +56,14 @@ .for-each(@colors, { .border-@{adKey} { @border-colors-color: extract(@adItem, @color-basic-position); - e(~`genCommentColor('@{border-colors-color}', 'Set the border color to {0}', '设置边框颜色为 {0}')`); + genCommentColor('@{border-colors-color}', 'Set the border color to {0}', '设置边框颜色为 {0}'); border-color: @border-colors-color !important; } }); .for-each(@aliasColors, { .border-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border color to {0}', '设置边框颜色为 {0}')`); + genComment('@{adValue}', 'Set the border color to {0}', '设置边框颜色为 {0}'); border-color: @adValue !important; } }); @@ -64,23 +71,27 @@ // Border-radius .for-each(@border-grids, { .rounded-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border radius to {0}', '设置边框圆角为 {0}')`); + genComment('@{adValue}', 'Set the border radius to {0}', '设置边框圆角为 {0}'); border-radius: @adValue; } + .rounded-top-left-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border top-left corner to {0}', '设置左上角边框圆角为 {0}')`); + genComment('@{adValue}', 'Set the border top-left corner to {0}', '设置左上角边框圆角为 {0}'); border-top-left-radius: @adValue; } + .rounded-top-right-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border top-right corner to {0}', '设置右上角边框圆角为 {0}')`); + genComment('@{adValue}', 'Set the border top-right corner to {0}', '设置右上角边框圆角为 {0}'); border-top-right-radius: @adValue; } + .rounded-bottom-left-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border bottom-left corner to {0}', '设置左下角边框圆角为 {0}')`); + genComment('@{adValue}', 'Set the border bottom-left corner to {0}', '设置左下角边框圆角为 {0}'); border-bottom-left-radius: @adValue; } + .rounded-bottom-right-@{adKey} { - e(~`genComment('@{adValue}', 'Set the border bottom-right corner to {0}', '设置右下角边框圆角为 {0}')`); + genComment('@{adValue}', 'Set the border bottom-right corner to {0}', '设置右下角边框圆角为 {0}'); border-bottom-right-radius: @adValue; } }); @@ -117,11 +128,13 @@ */ .rotate-loop(@i) when (@i > 0) { @num: @i * 15; + .rotate-@{num} { - e(~`genComment('@{num}', 'Element transform to {0} degree', '元素旋转 {0} 度')`); + genComment('@{num}', 'Element transform to {0} degree', '元素旋转 {0} 度'); transform: rotate(~'@{num}deg'); } + .rotate-loop(@i - 1); } -.rotate-loop(@rotate-count); +.rotate-loop(@rotate-count); \ No newline at end of file diff --git a/packages/theme/system/utils/_color.less b/packages/theme/system/utils/_color.less index da93fe7ec..775556e47 100644 --- a/packages/theme/system/utils/_color.less +++ b/packages/theme/system/utils/_color.less @@ -41,25 +41,25 @@ .for-each(@colors, { .bg-@{adKey}-light { @color-bg-light-color: extract(@adItem, @color-light-position); - e(~`genCommentTypeColor('background', '@{color-bg-light-color}')`); + genCommentTypeColor('background', '@{color-bg-light-color}'); background-color: @color-bg-light-color !important; } .bg-@{adKey} { @color-bg-color: extract(@adItem, @color-basic-position); - e(~`genCommentTypeColor('background', '@{color-bg-color}')`); + genCommentTypeColor('background', '@{color-bg-color}'); background-color: @color-bg-color !important; } .bg-@{adKey}-dark { @color-bg-dark-color: extract(@adItem, @color-dark-position); - e(~`genCommentTypeColor('background', '@{color-bg-dark-color}')`); + genCommentTypeColor('background', '@{color-bg-dark-color}'); background-color: @color-bg-dark-color !important; } .bg-@{adKey}-light-h { @color-bg-light-h-color: extract(@adItem, @color-light-position); - e(~`genCommentTypeColor('hoverBackground', '@{color-bg-light-h-color}')`); + genCommentTypeColor('hoverBackground', '@{color-bg-light-h-color}'); transition: background-color 300ms; &:hover { @@ -69,7 +69,7 @@ .bg-@{adKey}-h { @color-bg-basic-h-color: extract(@adItem, @color-basic-position); - e(~`genCommentTypeColor('hoverBackground', '@{color-bg-basic-h-color}')`); + genCommentTypeColor('hoverBackground', '@{color-bg-basic-h-color}'); transition: background-color 300ms; &:hover { @@ -79,7 +79,7 @@ .bg-@{adKey}-dark-h { @color-bg-dark-h-color: extract(@adItem, @color-dark-position); - e(~`genCommentTypeColor('hoverBackground', '@{color-bg-dark-h-color}')`); + genCommentTypeColor('hoverBackground', '@{color-bg-dark-h-color}'); transition: background-color 300ms; &:hover { @@ -89,19 +89,19 @@ .text-@{adKey}-light { @color-text-light-color: extract(@adItem, @color-light-position); - e(~`genCommentTypeColor('text', '@{color-text-light-color}')`); + genCommentTypeColor('text', '@{color-text-light-color}'); color: @color-text-light-color !important; } .text-@{adKey} { @color-text-basic-color: extract(@adItem, @color-basic-position); - e(~`genCommentTypeColor('text', '@{color-text-basic-color}')`); + genCommentTypeColor('text', '@{color-text-basic-color}'); color: @color-text-basic-color !important; } .text-@{adKey}-dark { @color-text-dark-color: extract(@adItem, @color-dark-position); - e(~`genCommentTypeColor('text', '@{color-text-dark-color}')`); + genCommentTypeColor('text', '@{color-text-dark-color}'); color: @color-text-dark-color !important; } }); @@ -109,23 +109,23 @@ .for-each(@aliasColors, { .bg-@{adKey}-light { @alias-bg-light-color: color(colorPalette('@{adValue}', @color-light-index)); - e(~`genCommentTypeColor('background', '@{alias-bg-light-color}')`); + genCommentTypeColor('background', '@{alias-bg-light-color}'); background-color: @alias-bg-light-color !important; } .bg-@{adKey} { - e(~`genCommentTypeColor('background', '@{adValue}')`); + genCommentTypeColor('background', '@{adValue}'); background-color: @adValue !important; } .bg-@{adKey}-dark { @alias-bg-dark-color: color(colorPalette('@{adValue}', @color-dark-index)); - e(~`genCommentTypeColor('background', '@{alias-bg-dark-color}')`); + genCommentTypeColor('background', '@{alias-bg-dark-color}'); background-color: @alias-bg-dark-color !important; } .bg-@{adKey}-h { - e(~`genCommentTypeColor('hoverBackground', '@{adValue}')`); + genCommentTypeColor('hoverBackground', '@{adValue}'); transition: background-color 300ms; &:hover { @@ -135,18 +135,18 @@ .text-@{adKey}-light { @alias-text-light-color: color(colorPalette('@{adValue}', @color-light-index)); - e(~`genCommentTypeColor('text', '@{alias-text-light-color}')`); + genCommentTypeColor('text', '@{alias-text-light-color}'); color: @alias-text-light-color !important; } .text-@{adKey} { - e(~`genCommentTypeColor('text', '@{adValue}')`); + genCommentTypeColor('text', '@{adValue}'); color: @adValue !important; } .text-@{adKey}-dark { @alias-text-dark-color: color(colorPalette('@{adValue}', @color-dark-index)); - e(~`genCommentTypeColor('text', '@{alias-text-dark-color}')`); + genCommentTypeColor('text', '@{alias-text-dark-color}'); color: @alias-text-dark-color !important; } }); @@ -154,12 +154,12 @@ // grey .for-each(@greyColorer, { .bg-grey-@{adKey} { - e(~`genCommentTypeColor('background', '@{adValue}')`); + genCommentTypeColor('background', '@{adValue}'); background-color: @adValue !important; } .bg-grey-@{adKey}-h { - e(~`genCommentTypeColor('hoverBackground', '@{adValue}')`); + genCommentTypeColor('hoverBackground', '@{adValue}'); transition: background-color 300ms; &:hover { @@ -168,7 +168,7 @@ } .text-grey-@{adKey} { - e(~`genCommentTypeColor('text', '@{adValue}')`); + genCommentTypeColor('text', '@{adValue}'); color: @adValue !important; } }); @@ -179,12 +179,12 @@ @nameValue: e(@@name); .bg-@{adKey}-@{i} { - e(~`genCommentTypeColor('background', '@{nameValue}')`); + genCommentTypeColor('background', '@{nameValue}'); background-color: @nameValue !important; } .bg-@{adKey}-@{i}-h { - e(~`genCommentTypeColor('hoverBackground', '@{nameValue}')`); + genCommentTypeColor('hoverBackground', '@{nameValue}'); transition: background-color 300ms; &:hover { @@ -193,7 +193,7 @@ } .text-@{adKey}-@{i} { - e(~`genCommentTypeColor('text', '@{nameValue}')`); + genCommentTypeColor('text', '@{nameValue}'); color: @nameValue !important; } @@ -205,4 +205,4 @@ }); } -.all-colors-minin(@enable-all-colors); +.all-colors-minin(@enable-all-colors); \ No newline at end of file diff --git a/packages/theme/system/utils/_spacing.less b/packages/theme/system/utils/_spacing.less index 185039190..cc818a32d 100644 --- a/packages/theme/system/utils/_spacing.less +++ b/packages/theme/system/utils/_spacing.less @@ -4,33 +4,40 @@ @item: extract(@mp-list, @i); @abbrev: extract(@item, 2); @prop: extract(@item, 1); + .@{abbrev}@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop} size to {0}', '设置 @{prop} 大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop} size to {0}', '设置 @{prop} 大小为 {0}'); @{prop}: @adValue !important; } + .@{abbrev}t@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop}-top size to {0}', '设置 @{prop}-top 大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop}-top size to {0}', '设置 @{prop}-top 大小为 {0}'); @{prop}-top: @adValue !important; } + .@{abbrev}r@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop}-right size to {0}', '设置 @{prop}-right 大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop}-right size to {0}', '设置 @{prop}-right 大小为 {0}'); @{prop}-right: @adValue !important; } + .@{abbrev}b@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop}-bottom size to {0}', '设置 @{prop}-bottom 大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop}-bottom size to {0}', '设置 @{prop}-bottom 大小为 {0}'); @{prop}-bottom: @adValue !important; } + .@{abbrev}l@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop}-left size to {0}', '设置 @{prop}-left 大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop}-left size to {0}', '设置 @{prop}-left 大小为 {0}'); @{prop}-left: @adValue !important; } + .@{abbrev}x@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop} horizontal (left & right) size to {0}', '设置 @{prop} 水平(即左与右)大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop} horizontal (left & right) size to {0}', '设置 @{prop} 水平(即左与右)大小为 {0}'); @{prop}-right: @adValue !important; @{prop}-left: @adValue !important; } + .@{abbrev}y@{infix} { - e(~`genComment('@{adValue}', 'Set the @{prop} vertical (top & bottom) size to {0}', '设置 @{prop} 垂直(即上与下)大小为 {0}')`); + genComment('@{adValue}', 'Set the @{prop} vertical (top & bottom) size to {0}', '设置 @{prop} 垂直(即上与下)大小为 {0}'); @{prop}-top: @adValue !important; @{prop}-bottom: @adValue !important; } @@ -42,12 +49,14 @@ @item: extract(@mp-list, @i); @abbrev: extract(@item, 2); @prop: extract(@item, 1); + // 无须设置注释 [dir="rtl"] { .@{abbrev}r@{infix} { @{prop}-left: @adValue !important; @{prop}-right: inherit !important; } + .@{abbrev}l@{infix} { @{prop}-right: @adValue !important; @{prop}-left: inherit !important; @@ -59,26 +68,32 @@ .spacings-loop(@type) { .for-each(@spacings, { - .infix-mixin(@adKey) when(@adKey = 0) { + .infix-mixin(@adKey) when(@adKey =0) { @infix: 0; } + .infix-mixin(@adKey) when(default()) { @infix: ~'-@{adKey}'; } + .infix-mixin(@adKey); - .loop-mp-fn-mixin(@type) when(@type = 'lrt') { + .loop-mp-fn-mixin(@type) when(@type ='lrt') { .loop-mp(@infix, @adKey, @adValue, 1); } + .loop-mp-fn-mixin(@type) when(default()) { .loop-mp-rtl(@infix, @adKey, @adValue, 1); } + .loop-mp-fn-mixin(@type); }); } .spacings-loop('lrt'); + .spacings-rtl-mixin(@enabled) when(@enabled=true) { .spacings-loop('rtl'); } -.spacings-rtl-mixin(@rtl-enabled); + +.spacings-rtl-mixin(@rtl-enabled); \ No newline at end of file diff --git a/packages/theme/system/utils/_width.less b/packages/theme/system/utils/_width.less index ff4b690f0..cef6ab81f 100644 --- a/packages/theme/system/utils/_width.less +++ b/packages/theme/system/utils/_width.less @@ -1,20 +1,23 @@ .for-each(@widths, { - .width-@{adKey} { - e(~`genComment('@{adValue}', 'Specify the width as {0}', '指定宽度为 {0}')`); + .width-@{adKey} { + genComment('@{adValue}', 'Specify the width as {0}', '指定宽度为 {0}'); width: @adValue !important; } - .max-width-@{adKey} { - e(~`genComment('@{adValue}', 'Specify the maximum width as {0}', '指定最大宽度为 {0}')`); + + .max-width-@{adKey} { + genComment('@{adValue}', 'Specify the maximum width as {0}', '指定最大宽度为 {0}'); max-width: @adValue !important; } - .min-width-@{adKey} { - e(~`genComment('@{adValue}', 'Specify the minimum width as {0}', '指定最小宽度为 {0}')`); + .min-width-@{adKey} { + genComment('@{adValue}', 'Specify the minimum width as {0}', '指定最小宽度为 {0}'); min-width: @adValue !important; } }); @media (max-width: @mobile-max) { + + /* stylelint-disable-next-line rule-empty-line-before */ .width-sm, .max-width-sm, .min-width-sm { diff --git a/schematics/migration.json b/schematics/migration.json index bd9f10a0d..c42e37930 100644 --- a/schematics/migration.json +++ b/schematics/migration.json @@ -1,8 +1,8 @@ { "$schema": "./node_modules/@angular-devkit/schematics/collection-schema.json", "schematics": { - "migration-v17": { - "version": "17", + "migration-v18": { + "version": "18", "description": "Updates NG-ALAIN to v18 [https://github.com/ng-alain/ng-alain/issues/2502]", "factory": "./ng-update/index#updateToV18" }, diff --git a/schematics/ng-update/index.ts b/schematics/ng-update/index.ts index 85c0fa07b..8faceaec2 100644 --- a/schematics/ng-update/index.ts +++ b/schematics/ng-update/index.ts @@ -3,11 +3,12 @@ import { createMigrationSchematicRule, NullableDevkitMigration, TargetVersion } import { chain, Rule, SchematicContext } from '@angular-devkit/schematics'; import { ruleUpgradeData } from './upgrade-data'; +import { v18Rule } from './upgrade-rules/V18'; const migrations: NullableDevkitMigration[] = []; export function updateToV18(): Rule { - return chain([createMigrationSchematicRule(TargetVersion.V18, migrations, ruleUpgradeData, postUpdate)]); + return chain([v18Rule(), createMigrationSchematicRule(TargetVersion.V18, migrations, ruleUpgradeData, postUpdate)]); } /** Post-update schematic to be called when update is finished. */ diff --git a/schematics/ng-update/upgrade-rules/V18/index.spec.ts b/schematics/ng-update/upgrade-rules/V18/index.spec.ts new file mode 100644 index 000000000..94806efd6 --- /dev/null +++ b/schematics/ng-update/upgrade-rules/V18/index.spec.ts @@ -0,0 +1,42 @@ +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; + +import { tryAddFile } from '../../../utils'; +import { createAlainApp, migrationCollection } from '../../../utils/testing'; + +describe('Schematic: ng-update: v18Rule', () => { + let runner: SchematicTestRunner; + let tree: UnitTestTree; + const logs: string[] = []; + + beforeEach(async () => { + ({ runner, tree } = await createAlainApp()); + }); + + async function runMigration(): Promise { + logs.length = 0; + runner = new SchematicTestRunner('schematics', migrationCollection); + runner.logger.subscribe(e => logs.push(e.message)); + await runner.runSchematic('migration-v18', {}, tree); + } + + it('remove ng-less-javascript-enabled-patch', async () => { + const packageJsonPath = '/package.json'; + tryAddFile( + tree, + packageJsonPath, + `{ + "scripts": { + "postinstall": "ng-less-javascript-enabled-patch" + }, + "devDependencies": { + "ng-less-javascript-enabled-patch": "17.0.2" + } + }` + ); + await runMigration(); + const content = tree.readContent(packageJsonPath); + expect(content).not.toContain(`"postinstall": "ng-less-javascript-enabled-patch"`); + expect(content).toContain(`"postinstall": ""`); + expect(content).not.toContain(`"ng-less-javascript-enabled-patch":`); + }); +}); diff --git a/schematics/ng-update/upgrade-rules/V18/index.ts b/schematics/ng-update/upgrade-rules/V18/index.ts new file mode 100644 index 000000000..5b8c4a410 --- /dev/null +++ b/schematics/ng-update/upgrade-rules/V18/index.ts @@ -0,0 +1,29 @@ +import { chain, Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; +import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks'; + +import { logFinished, logInfo, logWarn } from '../../../utils'; +import { UpgradeMainVersions } from '../../../utils/versions'; +import { removeNljep } from './remove-ng-less-javascript-enabled-patch'; + +function finished(): Rule { + return (_tree: Tree, context: SchematicContext) => { + context.addTask(new NodePackageInstallTask()); + + logWarn(context, `Please check the modified files. Some upgrades may have incorrect formats or missing imports.`); + logWarn(context, `Please check the modified files. Some upgrades may have incorrect formats or missing imports.`); + logWarn(context, `Please check the modified files. Some upgrades may have incorrect formats or missing imports.`); + + logFinished( + context, + `Congratulations, Abort more detail please refer to upgrade guide https://github.com/ng-alain/ng-alain/issues/2502` + ); + }; +} + +export function v18Rule(): Rule { + return async (tree: Tree, context: SchematicContext) => { + UpgradeMainVersions(tree); + logInfo(context, `Upgrade dependency version number`); + return chain([removeNljep(), finished()]); + }; +} diff --git a/schematics/ng-update/upgrade-rules/V18/remove-ng-less-javascript-enabled-patch.ts b/schematics/ng-update/upgrade-rules/V18/remove-ng-less-javascript-enabled-patch.ts new file mode 100644 index 000000000..dfaad04c4 --- /dev/null +++ b/schematics/ng-update/upgrade-rules/V18/remove-ng-less-javascript-enabled-patch.ts @@ -0,0 +1,22 @@ +import { Rule, SchematicContext, Tree } from '@angular-devkit/schematics'; + +import { logInfo, readPackage, writePackage } from '../../../utils'; + +const PACKAGE_NAME = 'ng-less-javascript-enabled-patch'; +export function removeNljep(): Rule { + return (tree: Tree, context: SchematicContext) => { + const json = readPackage(tree); + if (json == null) return; + if (!json.devDependencies[PACKAGE_NAME]) return; + const postinstall = json.scripts.postinstall; + if (typeof postinstall !== 'string') return; + if (!postinstall.includes(PACKAGE_NAME)) return; + + json.scripts.postinstall = postinstall.replace(`${PACKAGE_NAME}`, ''); + delete json.devDependencies[PACKAGE_NAME]; + + writePackage(tree, json); + + logInfo(context, `Remove [https://github.com/cipchk/${PACKAGE_NAME}] for devDependencies`); + }; +} diff --git a/schematics/test.ts b/schematics/test.ts index 287ec9e7f..91a5df248 100644 --- a/schematics/test.ts +++ b/schematics/test.ts @@ -13,7 +13,7 @@ const Jasmine = require('jasmine'); const runner = new Jasmine({ projectBaseDir }); // const files = `schematics/**/*.spec.ts`; -const files = `schematics/view/index.spec.ts`; +const files = `schematics/ng-update/upgrade-rules/V18/index.spec.ts`; const tests = glob.sync(files).map(p => relative(projectBaseDir, p)); diff --git a/src/assets/yarn.lock.txt b/src/assets/yarn.lock.txt index 5a64c8956..82f70fc6f 100644 --- a/src/assets/yarn.lock.txt +++ b/src/assets/yarn.lock.txt @@ -7540,10 +7540,9 @@ __metadata: mark-twain: "npm:^2.0.3" mockjs: "npm:^1.1.0" mustache: "npm:^4.2.0" - ng-alain-plugin-theme: "npm:^16.0.2" + ng-alain-plugin-theme: "npm:^18.0.0" ng-alain-sts: "npm:^0.0.2" ng-github-button: "npm:^18.0.0" - ng-less-javascript-enabled-patch: "npm:17.0.2" ng-packagr: "npm:^18.0.0" ng-zorro-antd: "npm:^18.0.1" ngx-countdown: "npm:^18.0.0" @@ -13239,9 +13238,9 @@ __metadata: languageName: node linkType: hard -"ng-alain-plugin-theme@npm:^16.0.2": - version: 16.0.2 - resolution: "ng-alain-plugin-theme@npm:16.0.2" +"ng-alain-plugin-theme@npm:^18.0.0": + version: 18.0.0 + resolution: "ng-alain-plugin-theme@npm:18.0.0" dependencies: jsonc-parser: "npm:^3.2.0" less: "npm:^4.1.3" @@ -13252,7 +13251,7 @@ __metadata: postcss-less: "npm:^6.0.0" bin: ng-alain-plugin-theme: lib/index.js - checksum: 11e8f8298865163164d8e11c7685ea1b482189dc6a43c0acd82e79c42d46d66adfb0b3705852c801ed08d5982c349d13ce24dcdaa654cc280ee75d8d88643275 + checksum: 278700a1bc07b1e8f00cdd02b5e96644d345e394ac35367a8a735c3e8af98dc44616a13f9149e1a61e8bd0da9f7ff5a47ac868980fad175768bfe388241d15b4 languageName: node linkType: hard @@ -13278,17 +13277,6 @@ __metadata: languageName: node linkType: hard -"ng-less-javascript-enabled-patch@npm:17.0.2": - version: 17.0.2 - resolution: "ng-less-javascript-enabled-patch@npm:17.0.2" - peerDependencies: - ansi-colors: ^4.0.0 - bin: - ng-less-javascript-enabled-patch: index.js - checksum: e6db52fbd31378587ae242a07c31af96d5c2ee5fcf0a959a05b9d6f1f82912289b44c51ce3443471362ebbef126f383f1fcc28a1dcd9b0eacc9dc0795c8824ed - languageName: node - linkType: hard - "ng-packagr@npm:^18.0.0": version: 18.0.0 resolution: "ng-packagr@npm:18.0.0" diff --git a/yarn.lock b/yarn.lock index 5a64c8956..82f70fc6f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7540,10 +7540,9 @@ __metadata: mark-twain: "npm:^2.0.3" mockjs: "npm:^1.1.0" mustache: "npm:^4.2.0" - ng-alain-plugin-theme: "npm:^16.0.2" + ng-alain-plugin-theme: "npm:^18.0.0" ng-alain-sts: "npm:^0.0.2" ng-github-button: "npm:^18.0.0" - ng-less-javascript-enabled-patch: "npm:17.0.2" ng-packagr: "npm:^18.0.0" ng-zorro-antd: "npm:^18.0.1" ngx-countdown: "npm:^18.0.0" @@ -13239,9 +13238,9 @@ __metadata: languageName: node linkType: hard -"ng-alain-plugin-theme@npm:^16.0.2": - version: 16.0.2 - resolution: "ng-alain-plugin-theme@npm:16.0.2" +"ng-alain-plugin-theme@npm:^18.0.0": + version: 18.0.0 + resolution: "ng-alain-plugin-theme@npm:18.0.0" dependencies: jsonc-parser: "npm:^3.2.0" less: "npm:^4.1.3" @@ -13252,7 +13251,7 @@ __metadata: postcss-less: "npm:^6.0.0" bin: ng-alain-plugin-theme: lib/index.js - checksum: 11e8f8298865163164d8e11c7685ea1b482189dc6a43c0acd82e79c42d46d66adfb0b3705852c801ed08d5982c349d13ce24dcdaa654cc280ee75d8d88643275 + checksum: 278700a1bc07b1e8f00cdd02b5e96644d345e394ac35367a8a735c3e8af98dc44616a13f9149e1a61e8bd0da9f7ff5a47ac868980fad175768bfe388241d15b4 languageName: node linkType: hard @@ -13278,17 +13277,6 @@ __metadata: languageName: node linkType: hard -"ng-less-javascript-enabled-patch@npm:17.0.2": - version: 17.0.2 - resolution: "ng-less-javascript-enabled-patch@npm:17.0.2" - peerDependencies: - ansi-colors: ^4.0.0 - bin: - ng-less-javascript-enabled-patch: index.js - checksum: e6db52fbd31378587ae242a07c31af96d5c2ee5fcf0a959a05b9d6f1f82912289b44c51ce3443471362ebbef126f383f1fcc28a1dcd9b0eacc9dc0795c8824ed - languageName: node - linkType: hard - "ng-packagr@npm:^18.0.0": version: 18.0.0 resolution: "ng-packagr@npm:18.0.0"