Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions packages/core/update/Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
let guideLink = "";
let logicFilesExtension = "";
let styleExtensions = [];
let shouldUpgradeHTML = false;

const config = ProjectConfig.getConfig();
const framework = config.project.framework;
Expand All @@ -31,6 +32,7 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
case "webcomponents":
guideLink = "https://www.infragistics.com/products/ignite-ui-web-components/web-components/components/general-licensing";
logicFilesExtension = "ts";
shouldUpgradeHTML = true;
break;
default:
break;
Expand Down Expand Up @@ -61,8 +63,16 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
const logicFiles = [];
const styleFiles = [];
const pkgJsonFiles = [];
const htmlFiles = [];
pkgJsonFiles.push(...fs.glob(rootPath, `package.json`, ['node_modules', 'dist']));

if (shouldUpgradeHTML) {
const filePaths = fs.glob(rootPath, `*.html`, ['node_modules', 'dist']);
if (filePaths && filePaths.length > 0) {
htmlFiles.push(...filePaths);
}
}

let workspaceConfig = null;
switch (framework.toLowerCase()) {
case "angular":
Expand Down Expand Up @@ -106,6 +116,9 @@ export async function updateWorkspace(rootPath: string): Promise<boolean> {
}

updateFileImports(logicFiles, styleFiles, upgradeable, fs);
if (shouldUpgradeHTML) {
updateHTMLImports(htmlFiles, upgradeable, fs);
}
updatePackageJsonFiles(pkgJsonFiles, upgradeable, fs);
createNpmrc(rootPath, fs);
updateWorkflows(fs);
Expand Down Expand Up @@ -149,8 +162,11 @@ function updateFileImports(
let fileChange = false;
for (const packageDef of packageDefs) {
if (fileContent.includes(packageDef.trial)) {
const newContent = updateFileContent(fileContent,
createExpressions(RegularExpressionType.LOGIC, packageDef.trial), packageDef.licensed);
// Because when including a theme inside a WC render method we need to update its import path too #1386
const regExpressions = [...createExpressions(RegularExpressionType.LOGIC, packageDef.trial),
...createExpressions(RegularExpressionType.STYLE, packageDef.trial)
]
const newContent = updateFileContent(fileContent, regExpressions, packageDef.licensed);
fileChange = fileContent !== newContent;
fileContent = newContent;
}
Expand Down Expand Up @@ -231,3 +247,21 @@ function createNpmrc(
fs.writeFile(npmrcPath, fileContent);
}
}

function updateHTMLImports(htmlFiles: string[], packageDefs: PackageDefinition[], fs: IFileSystem): void {
for (const file of htmlFiles) {
let fileContent = fs.readFile(file);
let fileChange = false;
for (const packageDef of packageDefs) {
if (fileContent.includes(packageDef.trial)) {
const newContent = updateFileContent(fileContent,
createExpressions(RegularExpressionType.STYLE, packageDef.trial), packageDef.licensed);
fileChange = fileContent !== newContent;
fileContent = newContent;
}
}
if (fileChange) {
fs.writeFile(file, fileContent);
}
}
}
54 changes: 49 additions & 5 deletions spec/unit/update-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,7 @@ export default function Home() {
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
([ "package.json" ], // root package.json
[], //index.html
[], // logic files
[ "./project/package.json" ]); // inner package.json files
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
Expand All @@ -827,7 +828,7 @@ export default function Home() {
}
}));
expect(fsSpy.writeFile).toHaveBeenCalledTimes(2);
expect(fsSpy.glob).toHaveBeenCalledTimes(3);
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
});

it("Should update import paths in files correctly", async () => {
Expand All @@ -839,6 +840,7 @@ export default function Home() {
"dependencies": {
"igniteui-webcomponents": "^4.7.0",
"igniteui-webcomponents-core": "^4.7.0",
"igniteui-webcomponents-grids": "^4.7.0",
"igniteui-dockmanager": "^1.0.0",
"some-package": "^0.0.0"
}
Expand All @@ -849,6 +851,7 @@ export default function Home() {
"dependencies": {
"@infragistics/igniteui-dockmanager": "^1.0.0",
"@infragistics/igniteui-webcomponents-core": "^4.7.0",
"@infragistics/igniteui-webcomponents-grids": "^4.7.0",
"igniteui-webcomponents": "^4.7.0",
"some-package": "^0.0.0"
}
Expand All @@ -874,7 +877,8 @@ import { ModuleManager } from '@infragistics/igniteui-webcomponents-core';

export default class App extends LitElement {
const title = 'igniteui-webcomponents example';
}`}, {
}`},
{
path: ".github/workflows/node.js.yml",
content:
`# start content
Expand Down Expand Up @@ -903,9 +907,48 @@ export default class App extends LitElement {
- run: echo "//packages.infragistics.com/npm/js-licensed/:always-auth=true" >> ~/.npmrc
- run: npm i # replace with 'npm ci' after committing lock file from first install
# end content
`}];
`},
{
path: "index.html",
content:
`<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<base href="/">
<title>Ignite UI for Web Components</title>
<link rel="stylesheet" href="./node_modules/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css">
<link rel="stylesheet" href="./styles.css">
</head>
<body class="ig-scrollbar">
<app-root></app-root>

<script type="module" src="./dist/src/index.js"></script>
</body>
</html>
`,
expected:
`<!doctype html>
<html lang="en-GB">
<head>
<meta charset="utf-8">
<base href="/">
<title>Ignite UI for Web Components</title>
<link rel="stylesheet" href="./node_modules/@infragistics/igniteui-webcomponents-grids/grids/themes/light/bootstrap.css">
<link rel="stylesheet" href="./styles.css">
</head>
<body class="ig-scrollbar">
<app-root></app-root>

<script type="module" src="./dist/src/index.js"></script>
</body>
</html>
`

},];
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
([ "package.json" ], // root package.json
["index.html"], // html file
["src/app.ts"], // logic files
[]); // inner package.json files
(fsSpy.readFile as jasmine.Spy).and.callFake((filePath: string) => {
Expand All @@ -921,7 +964,7 @@ export default class App extends LitElement {
for (const fileEntry of mockFileArray) {
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
}
expect(fsSpy.glob).toHaveBeenCalledTimes(3);
expect(fsSpy.glob).toHaveBeenCalledTimes(4);
});

it("Should update package.json files from workspaces", async () => {
Expand Down Expand Up @@ -1012,6 +1055,7 @@ export default class App extends LitElement {
(fsSpy.fileExists as jasmine.Spy).and.returnValue(true);
(fsSpy.glob as jasmine.Spy).and.returnValues // per workspace
([ "package.json" ], // root package.json
[], //index.html
[], // projectA logic files
[ "./projectA/package.json" ], // projectA package.json
[], // projectB logic files
Expand All @@ -1031,7 +1075,7 @@ export default class App extends LitElement {
for (const fileEntry of mockFileArray) {
expect((fsSpy.writeFile as jasmine.Spy)).toHaveBeenCalledWith(fileEntry.path, fileEntry.expected);
}
expect(fsSpy.glob).toHaveBeenCalledTimes(5);
expect(fsSpy.glob).toHaveBeenCalledTimes(6);
});
});
});
Loading