Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update package versions (specifically yeomoan) and adjust code accordingly #853

Merged
merged 8 commits into from
Feb 18, 2025
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
6,782 changes: 4,098 additions & 2,684 deletions package-lock.json

Large diffs are not rendered by default.

42 changes: 21 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"files": [
"generators"
],
"type": "module",
"main": "generators/index.js",
"keywords": [
"office",
Expand All @@ -38,37 +39,36 @@
"project"
],
"dependencies": {
"adm-zip": "0.5.12",
"adm-zip": "0.5.16",
"axios": "^1.7.7",
"chalk": "^4.0.0",
"chalk": "^5.4.1",
"lodash": "^4.17.21",
"office-addin-usage-data": "^1.6.4",
"office-addin-usage-data": "^2.0.3",
"open": "^8.4.0",
"uuid": "^8.3.2",
"yeoman-generator": "^5.8.0",
"yeoman-generator": "^7.0.0",
"yosay": "^2.0.2"
},
"devDependencies": {
"@types/adm-zip": "^0.5.5",
"@types/lodash": "^4.14.182",
"@types/mocha": "^9.1.1",
"@types/node": "^18.16.0",
"@types/adm-zip": "^0.5.7",
"@types/lodash": "^4.17.14",
"@types/mocha": "^10.0.10",
"@types/node": "^22.10.6",
"@types/request": "^2.48.8",
"@types/yeoman-generator": "^5.2.10",
"@typescript-eslint/eslint-plugin": "^5.36.1",
"@typescript-eslint/parser": "^5.36.1",
"concurrently": "^7.1.0",
"@typescript-eslint/eslint-plugin": "^8.0.0",
"@typescript-eslint/parser": "^8.0.0",
"concurrently": "^9.1.2",
"copyfiles": "^2.4.1",
"eslint": "^8.23.0",
"eslint-config-prettier": "8.5.0",
"mocha": "^10.0.0",
"office-addin-manifest": "^1.13.2",
"prettier": "^2.6.2",
"rimraf": "^3.0.2",
"eslint": "^9.0.0",
"eslint-config-prettier": "9.1.0",
"mocha": "^11.0.0",
"office-addin-manifest": "^2.0.3",
"prettier": "^3.4.2",
"rimraf": "^6.0.1",
"ts-node": "^10.7.0",
"typescript": "^4.8.2",
"typescript": "^5.2.2",
"yeoman-assert": "^3.1.1",
"yeoman-environment": "^3.13.0",
"yeoman-test": "^6.3.0"
"yeoman-environment": "^4.4.3",
"yeoman-test": "^10.0.1"
}
}
10 changes: 5 additions & 5 deletions src/app/config/projectsJsonData.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fs from 'fs';
import * as _ from 'lodash';
import fs from 'fs';
import _ from 'lodash';

export default class projectsJsonData {
m_projectJsonDataFile = '/projectProperties.json';
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class projectsJsonData {
getScriptTypeOptions(projectType: string): string[] {
const scriptTypes: string[] = [];
for (const template in this.m_projectJsonData.projectTypes[projectType].templates) {
let scriptType: string;
let scriptType: string = "unknown";
if (template === "javascript") {
scriptType = "JavaScript";
} else if (template === "typescript") {
Expand All @@ -88,7 +88,7 @@ export default class projectsJsonData {
return this.m_projectJsonData.hostTypes[key].displayname;
}
}
return undefined;
return "";
}

getManifestDisplayName(hostKey: string): string {
Expand Down Expand Up @@ -134,7 +134,7 @@ export default class projectsJsonData {

getProjectRepoAndBranch(projectTypeKey: string, scriptType: string, prerelease: boolean) {
scriptType = scriptType === 'ts' ? 'typescript' : 'javascript';
const repoBranchInfo = { repo: <string>null, branch: <string>null };
const repoBranchInfo = { repo: <string|undefined>undefined, branch: <string|undefined>undefined };

repoBranchInfo.repo = this.getProjectTemplateRepository(projectTypeKey, scriptType);
repoBranchInfo.branch = (repoBranchInfo.repo) ? this.getProjectTemplateBranchName(projectTypeKey, scriptType, prerelease) : undefined;
Expand Down
2 changes: 1 addition & 1 deletion src/app/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as chalk from "chalk";
import chalk from "chalk";

export const configurationErrorEventName = "configuration-error-generator-office";
export const copyFilesErrorEventName = "copy-files-error-generator-office";
Expand Down
55 changes: 16 additions & 39 deletions src/app/helpers/helperMethods.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import axios from "axios"
import * as fs from "fs";
import * as path from "path";
import * as AdmZip from "adm-zip";
import AdmZip from "adm-zip";

const zipFile = 'project.zip';

// eslint-disable-next-line @typescript-eslint/no-namespace
export namespace helperMethods {
function deleteFolderRecursively(projectFolder: string) {
export function deleteFolderRecursively(projectFolder: string) {
try {
if (fs.existsSync(projectFolder)) {
fs.readdirSync(projectFolder).forEach(function (file) {
Expand All @@ -34,66 +34,43 @@ export namespace helperMethods {
return false;
};

export async function downloadProjectTemplateZipFile(projectFolder: string, projectRepo: string, projectBranch: string): Promise<void> {
export async function downloadProjectTemplateZipFile(projectFolder: string, projectRepo: string, projectBranch: string): Promise<string> {
const projectTemplateZipFile = `${projectRepo}/archive/${projectBranch}.zip`;
return axios({
method: 'get',
url: projectTemplateZipFile,
responseType: 'stream',
}).then(response => {
return new Promise<void>((resolve, reject) => {
return new Promise<string>((resolve, reject) => {
response.data.pipe(fs.createWriteStream(zipFile))
.on('error', function (err) {
reject(`Unable to download project zip file for "${projectTemplateZipFile}".\n${err}`);
})
.on('close', async () => {
await unzipProjectTemplate(projectFolder);
resolve();
resolve(path.resolve(`${projectFolder}/project.zip`));
});
});
}).catch(err => { console.log(`Unable to download project zip file for "${projectTemplateZipFile}".\n${err}`); });
}).catch(err => {
const error: string = `Unable to download project zip file for "${projectTemplateZipFile}".\n${err}`;
console.log(error)
return Promise.reject(error);
});
}

async function unzipProjectTemplate(projectFolder: string): Promise<void> {
export async function unzipProjectTemplate(projectFolder: string): Promise<string> {
return new Promise(async (resolve, reject) => {
const zipFile = 'project.zip';
const zip = new AdmZip(`${projectFolder}/${zipFile}`);
try {
zip.extractAllTo(/*target path*/projectFolder, /*overwrite*/true);
moveProjectFiles(projectFolder);
resolve();
// get path to unzipped folder
const unzippedFolder = fs.readdirSync(projectFolder).filter(function (file) {
return fs.statSync(`${projectFolder}/${file}`).isDirectory();
});
resolve(unzippedFolder[0]);
} catch (err) {
reject(`Unable to unzip project zip file for "${projectFolder}".\n${err}`);
}
});
}

function moveProjectFiles(projectFolder: string): void {
// delete original zip file
const zipFilePath = path.resolve(`${projectFolder}/${zipFile}`);
if (fs.existsSync(zipFilePath)) {
fs.unlinkSync(zipFilePath);
}

// get path to unzipped folder
const unzippedFolder = fs.readdirSync(projectFolder).filter(function (file) {
return fs.statSync(`${projectFolder}/${file}`).isDirectory();
});

// construct paths to move files out of unzipped folder into project root folder
const moveFromFolder = path.resolve(`${projectFolder}/${unzippedFolder[0]}`);

// loop through all the files and folders in the unzipped folder and move them to project root
fs.readdirSync(moveFromFolder).forEach(function (file) {
const fromPath = path.join(moveFromFolder, file);
const toPath = path.join(projectFolder, file);

if (fs.existsSync(fromPath) && !fromPath.includes(".gitignore")) {
fs.renameSync(fromPath, toPath);
}
});

// delete project zipped folder
deleteFolderRecursively(moveFromFolder);
}
}
Loading
Loading