Skip to content

Commit

Permalink
Merge branch 'release/2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Dec 14, 2020
2 parents 240727b + d28421c commit b803d56
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 19 deletions.
5 changes: 4 additions & 1 deletion bin/Webresource/Webresource.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
</head>
<body class="Webresource">
<link rel="stylesheet" type="text/css" href="./Webresource.css"/>
<script type="text/javascript" src="./Webresource.js"></script>
<script type="text/javascript">
"use strict";
window.Xrm = parent.Xrm;
</script>
<script type="text/javascript" src="./Webresource.js"></script>
<script type="text/javascript">
"use strict";
window.addEventListener("load", function() {
<%= publisher %>.<%= namespace %>.Webresource.onLoad();
});
Expand Down
2 changes: 1 addition & 1 deletion bin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/root/tools/deploy.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bin/root/tools/resx.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/root/tools/setFormCustomizable.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hso/d365-cli",
"version": "2.0.2",
"version": "2.1.0",
"author": "HSO Innovation <[email protected]> (http://www.hso.com)",
"description": "HSO D365 Command Line Interface",
"repository": {
Expand Down
18 changes: 17 additions & 1 deletion src/Update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export class Update {
private static async update(): Promise<void> {
console.log(`Updating D365 Project...`);
const variables = await Variables.get();
Update.updateWebresources();
Update.updateSrcFolder();
Update.updateProjectRootFolder();
Update.updatePackageJson(variables);
Expand Down Expand Up @@ -47,6 +48,22 @@ export class Update {
shell.exec('git add tsconfig.json');
}

private static updateWebresources(): void {
console.log('Updating Webresource files...');
shell.ls(`src/**/*.html`).forEach(function (filepath) {
const file = shell.ls(filepath)[0];
const fileData = String(fs.readFileSync(filepath));
if (!fileData.match(new RegExp('<script type="text/javascript">\\s*"use strict";\\s*window.Xrm = parent.Xrm;\\s*</script>'))) {
const match = fileData.match(new RegExp(`<body( [a-zA-Z=" ]*)?>`, 'i'));
shell.sed('-i', new RegExp(match[0], 'i'), `${match[0]}\n` +
` <script type="text/javascript">\n` +
` "use strict";\n` +
` window.Xrm = parent.Xrm;\n` +
` </script>`, file);
}
});
}

private static updateSrcFolder(): void {
if (shell.ls(['./tsconfig.json']).length !== 1) {
console.log(`Remove src/tsconfig.json...`);
Expand Down Expand Up @@ -74,7 +91,6 @@ export class Update {
shell.cp('-R', `${__dirname}/root/src/translation`, './src');
}


private static updatePackageJson(variables: AllVariables): void {
console.log(`Updating package.json...`);
let dlfCoreCheck = shell.grep(`dlf-core`, 'package.json');
Expand Down
33 changes: 21 additions & 12 deletions src/root/tools/Deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,21 +62,21 @@ export class Deploy extends AdalRouter {
}

private async deployFile(filepath: string): Promise<void> {
const filedata = fs.readFileSync(filepath), // String(fs.readFileSync(filepath)),
crmPath = filepath.substr(5),
const crmPath = filepath.substr(5),
webresource = await this.getWebresource(crmPath);
this.log(`${crmPath}`);
if (webresource) {
await this.updateWebresource(webresource, filedata);
await this.updateWebresource(webresource, filepath);
} else {
await this.insertWebresource(filedata, crmPath);
await this.insertWebresource(filepath, crmPath);
}
}

private async updateWebresource(webresource: WebresourceModel, data: Buffer): Promise<void> {
private async updateWebresource(webresource: WebresourceModel, filepath: string): Promise<void> {
const md5Orig = this.md5(webresource.content),
data = fs.readFileSync(filepath),
base64 = data.toString('base64'),
dependencyXML = await this.generateDependencyXML(webresource, data),
dependencyXML = await this.generateDependencyXML(filepath, webresource, data),
md5New = this.md5(base64);
if (md5Orig !== md5New || dependencyXML && dependencyXML !== webresource?.dependencyxml) {
webresource.content = base64;
Expand All @@ -94,16 +94,17 @@ export class Deploy extends AdalRouter {
}
}

private async insertWebresource(data: Buffer, path: string): Promise<WebresourceModel> {
const base64 = data.toString('base64');
private async insertWebresource(filepath: string, path: string): Promise<WebresourceModel> {
const data = fs.readFileSync(filepath),
base64 = data.toString('base64');
try {
const solutionUniqueName = this.settings.crm.solution_name,
webresourceModel: WebresourceModel = {
content: base64,
name: path,
displayname: path
},
dependencyXML = await this.generateDependencyXML(webresourceModel, data);
dependencyXML = await this.generateDependencyXML(filepath, webresourceModel, data);
if (dependencyXML) {
webresourceModel.dependencyxml = dependencyXML;
}
Expand Down Expand Up @@ -131,12 +132,20 @@ export class Deploy extends AdalRouter {
return webresources[0];
}

// Small wrapper method for future support of html files, etc
private async generateDependencyXML(webresource: WebresourceModel, data: Buffer): Promise<string> {
// Small wrapper method for future support of other extensions, etc
private async generateDependencyXML(filepath: string, webresource: WebresourceModel, data: Buffer): Promise<string> {
if (webresource.name.endsWith('.js')) {
const dependencyXML = await this.getDependencyXML(webresource, data);
console.log(`Dependencyxml: ${dependencyXML}`);
return dependencyXML;
} else if (webresource.name.endsWith('.html')) {
const scriptPath = filepath.replace(/.html/g, '.js');
if (fs.existsSync(scriptPath)) {
const jsData = fs.readFileSync(scriptPath);
const dependencyXML = await this.getDependencyXML(webresource, jsData);
return dependencyXML;
} else {
console.log(`script file: ${scriptPath} does not exist`);
}
}
}

Expand Down

0 comments on commit b803d56

Please sign in to comment.