Skip to content

Commit

Permalink
Adding shared template option (#717)
Browse files Browse the repository at this point in the history
* Adding shared template option

* Fixing single host bug

* Removed must specify excel message

* Changing case handling to configure project

* Fixing typo

* Fix formatting

* Fixing formatting

* Checking for empty host and scriptType

* Adding all initialization to one part

* PR Fixes

* Commenting SSO tests
  • Loading branch information
igor-ribeiiro committed Jul 25, 2022
1 parent 3e8be45 commit bb3e3cf
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 114 deletions.
57 changes: 38 additions & 19 deletions src/app/config/projectProperties.json
Expand Up @@ -23,17 +23,17 @@
"Project",
"Word"]
},
"angular": {
"displayname": "Office Add-in Task Pane project using Angular framework",
"react": {
"displayname": "Office Add-in Task Pane project using React framework",
"manifestPath": "manifest.xml",
"templates": {
"javascript": {
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-Angular-JS",
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-React-JS",
"branch": "yo-office",
"prerelease": "yo-office-prerelease"
},
"typescript": {
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-Angular",
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-React",
"branch": "yo-office",
"prerelease": "yo-office-prerelease"
}
Expand All @@ -47,17 +47,17 @@
"Word"
]
},
"react": {
"displayname": "Office Add-in Task Pane project using React framework",
"angular": {
"displayname": "Office Add-in Task Pane project using Angular framework",
"manifestPath": "manifest.xml",
"templates": {
"javascript": {
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-React-JS",
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-Angular-JS",
"branch": "yo-office",
"prerelease": "yo-office-prerelease"
},
"typescript": {
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-React",
"repository": "https://github.com/OfficeDev/Office-Addin-TaskPane-Angular",
"branch": "yo-office",
"prerelease": "yo-office-prerelease"
}
Expand All @@ -71,25 +71,27 @@
"Word"
]
},
"manifest": {
"displayname": "Office Add-in project containing the manifest only",
"excel-functions-shared": {
"displayname": "Excel Custom Functions using a Shared Runtime",
"manifestPath": "manifest.xml",
"templates": {
"manifestonly": {
"repository": ""
"javascript": {
"repository": "https://github.com/OfficeDev/Excel-Custom-Functions-JS",
"branch": "shared-runtime-yo-office",
"prerelease": "shared-runtime-yo-office-prerelease"
},
"typescript": {
"repository": "https://github.com/OfficeDev/Excel-Custom-Functions",
"branch": "shared-runtime-yo-office",
"prerelease": "shared-runtime-yo-office-prerelease"
}
},
"supportedHosts": [
"Excel",
"Onenote",
"Outlook",
"Powerpoint",
"Project",
"Word"
"Excel"
]
},
"excel-functions": {
"displayname": "Excel Custom Functions Add-in project",
"displayname": "Excel Custom Functions using a JavaScript-only Runtime",
"manifestPath": "manifest.xml",
"templates": {
"javascript": {
Expand Down Expand Up @@ -120,6 +122,23 @@
"supportedHosts": [
"Outlook"
]
},
"manifest": {
"displayname": "Office Add-in project containing the manifest only",
"manifestPath": "manifest.xml",
"templates": {
"manifestonly": {
"repository": ""
}
},
"supportedHosts": [
"Excel",
"Onenote",
"Outlook",
"Powerpoint",
"Project",
"Word"
]
}
},
"hostTypes": {
Expand Down
34 changes: 22 additions & 12 deletions src/app/index.ts
Expand Up @@ -29,6 +29,7 @@ let language;
const manifest = 'manifest';
const sso = 'single-sign-on';
const typescript = `TypeScript`;
let jsonData;

let usageDataObject: usageData.OfficeAddinUsageData;
const usageDataOptions: usageData.IUsageDataOptions = {
Expand Down Expand Up @@ -138,7 +139,7 @@ module.exports = class extends yo {
usageDataOptions.usageDataLevel = usageData.readUsageDataLevel(usageDataOptions.groupName);
}

const jsonData = new projectsJsonData(this.templatePath());
jsonData = new projectsJsonData(this.templatePath());
let isManifestProject = false;
let isExcelFunctionsProject = false;

Expand Down Expand Up @@ -286,14 +287,26 @@ module.exports = class extends yo {

_configureProject(answerForProjectType, answerForScriptType, answerForHost, answerForName, isManifestProject, isExcelFunctionsProject): void {
try {
const projType = _.toLower(this.options.projectType) || _.toLower(answerForProjectType.projectType)

this.project = {
folder: this.options.output || answerForName.name || this.options.name,
host: answerForHost.host
? answerForHost.host
: this.options.host
? this.options.host
: jsonData?.getHostTemplateNames(projType)[0],
name: this.options.name || answerForName.name,
host: this.options.host || answerForHost.host,
projectType: _.toLower(this.options.projectType) || _.toLower(answerForProjectType.projectType),
projectType: projType,
scriptType: answerForScriptType.scriptType
? answerForScriptType.scriptType
: this.options.ts
? typescript
: this.options.js
? javascript
: jsonData?.getSupportedScriptTypes(projType)[0],
isManifestOnly: isManifestProject,
isExcelFunctionsProject: isExcelFunctionsProject,
scriptType: answerForScriptType.scriptType ? answerForScriptType.scriptType : this.options.ts ? typescript : javascript
};

/* Set folder if to output param if specified */
Expand All @@ -307,13 +320,8 @@ module.exports = class extends yo {
this.project.projectInternalName = _.kebabCase(this.project.name);
this.project.projectDisplayName = this.project.name;
this.project.projectId = uuidv4();
if (this.project.projectType === excelCustomFunctions) {
this.project.host = 'Excel';
this.project.hostInternalName = 'Excel';
}
else {
this.project.hostInternalName = this.project.host;
}
this.project.hostInternalName = this.project.host;

this.destinationRoot(this.project.folder);
process.chdir(this._destinationRoot);
this.env.cwd = this._destinationRoot;
Expand Down Expand Up @@ -425,10 +433,12 @@ module.exports = class extends yo {
this.log(`NOTE: ${chalk.bgGreen('Arguments')} must be specified in the order below, and ${chalk.bgMagenta('Options')} must follow ${chalk.bgGreen('Arguments')}.\n`);
this.log(` ${chalk.bgGreen('projectType')}:Specifies the type of project to create. Valid project types include:`);
this.log(` ${chalk.yellow('angular:')} Creates an Office add-in using Angular framework.`);
this.log(` ${chalk.yellow('excel-functions:')} Creates an Office add-in for Excel custom functions. Must specify 'Excel' as host parameter.`);
this.log(` ${chalk.yellow('excel-functions-shared:')} Creates an Office add-in for Excel custom functions using a Shared Runtime.`);
this.log(` ${chalk.yellow('excel-functions:')} Creates an Office add-in for Excel custom functions using a JavaScript-only Runtime.`);
this.log(` ${chalk.yellow('jquery:')} Creates an Office add-in using Jquery framework.`);
this.log(` ${chalk.yellow('manifest:')} Creates an only the manifest file for an Office add-in.`);
this.log(` ${chalk.yellow('react:')} Creates an Office add-in using React framework.\n`);
this.log(` ${chalk.yellow('teams-manifest:')} Creates Outlook Add-in with Teams Manifest (Developer preview).\n`);
this.log(` ${chalk.bgGreen('name')}:Specifies the name for the project that will be created.\n`);
this.log(` ${chalk.bgGreen('host')}:Specifies the host app in the add-in manifest.`);
this.log(` ${chalk.yellow('excel:')} Creates an Office add-in for Excel. Valid hosts include:`);
Expand Down
166 changes: 83 additions & 83 deletions src/test/convert-to-single-host.ts
Expand Up @@ -207,93 +207,93 @@ describe('Office-Add-Taskpane-React-Ts project', () => {
});
});

// Test to verify converting a project to a single host
// for SSO Typescript project using Excel host
describe('Office-Add-Taskpane-SSO-TS project', () => {
const expectedFiles = [
packageJsonFile,
manifestFile,
'.ENV',
'src/taskpane/taskpane.ts',
'src/taskpane/taskpane.html',
'src/taskpane/taskpane.css',
'src/helpers/fallbackauthdialog.html',
'src/helpers/fallbackauthdialog.ts',
'src/helpers/fallbackauthhelper.ts',
'src/helpers/ssoauthhelper.ts'
// // Test to verify converting a project to a single host
// // for SSO Typescript project using Excel host
// describe('Office-Add-Taskpane-SSO-TS project', () => {
// const expectedFiles = [
// packageJsonFile,
// manifestFile,
// '.ENV',
// 'src/taskpane/taskpane.ts',
// 'src/taskpane/taskpane.html',
// 'src/taskpane/taskpane.css',
// 'src/helpers/fallbackauthdialog.html',
// 'src/helpers/fallbackauthdialog.ts',
// 'src/helpers/fallbackauthhelper.ts',
// 'src/helpers/ssoauthhelper.ts'

]
const unexpectedFiles = [
'src/taskpane/excel.ts',
'src/taskpane/word.ts',
'src/taskpane/powerpoint.ts',
'manifest.excel.xml',
'manifest.word.xml',
'manifest.powerpoint.xml'
]
const answers = {
projectType: "single-sign-on",
scriptType: "TypeScript",
name: "SSOTypeScriptProject",
host: hosts[0]
};
// ]
// const unexpectedFiles = [
// 'src/taskpane/excel.ts',
// 'src/taskpane/word.ts',
// 'src/taskpane/powerpoint.ts',
// 'manifest.excel.xml',
// 'manifest.word.xml',
// 'manifest.powerpoint.xml'
// ]
// const answers = {
// projectType: "single-sign-on",
// scriptType: "TypeScript",
// name: "SSOTypeScriptProject",
// host: hosts[0]
// };

describe('Office-Add-Taskpane-SSO-TS project', () => {
before((done) => {
helpers.run(path.join(__dirname, '../app')).withOptions({ 'test': true }).withPrompts(answers).on('end', done);
});
// describe('Office-Add-Taskpane-SSO-TS project', () => {
// before((done) => {
// helpers.run(path.join(__dirname, '../app')).withOptions({ 'test': true }).withPrompts(answers).on('end', done);
// });

it('creates expected files', (done) => {
assert.file(expectedFiles);
assert.noFile(unexpectedFiles);
assert.noFile(unexpectedManifestFiles);
done();
});
});
});
// it('creates expected files', (done) => {
// assert.file(expectedFiles);
// assert.noFile(unexpectedFiles);
// assert.noFile(unexpectedManifestFiles);
// done();
// });
// });
// });

// Test to verify converting a project to a single host
// for SSO JavaScript project using PowerPoint host
describe('Office-Add-Taskpane-SSO-JS project', () => {
const expectedFiles = [
packageJsonFile,
manifestFile,
'.ENV',
'src/taskpane/taskpane.js',
'src/taskpane/taskpane.html',
'src/taskpane/taskpane.css',
'src/helpers/documenthelper.js',
'src/helpers/fallbackauthdialog.html',
'src/helpers/fallbackauthdialog.js',
'src/helpers/fallbackauthhelper.js',
'src/helpers/ssoauthhelper.js'
// // Test to verify converting a project to a single host
// // for SSO JavaScript project using PowerPoint host
// describe('Office-Add-Taskpane-SSO-JS project', () => {
// const expectedFiles = [
// packageJsonFile,
// manifestFile,
// '.ENV',
// 'src/taskpane/taskpane.js',
// 'src/taskpane/taskpane.html',
// 'src/taskpane/taskpane.css',
// 'src/helpers/documenthelper.js',
// 'src/helpers/fallbackauthdialog.html',
// 'src/helpers/fallbackauthdialog.js',
// 'src/helpers/fallbackauthhelper.js',
// 'src/helpers/ssoauthhelper.js'

]
const unexpectedFiles = [
'src/taskpane/excel.js',
'src/taskpane/word.js',
'src/taskpane/powerpoint.js',
'manifest.excel.xml',
'manifest.word.xml',
'manifest.powerpoint.xml'
]
const answers = {
projectType: "single-sign-on",
scriptType: "JavaScript",
name: "SSOJavaScriptProject",
host: hosts[3]
};
// ]
// const unexpectedFiles = [
// 'src/taskpane/excel.js',
// 'src/taskpane/word.js',
// 'src/taskpane/powerpoint.js',
// 'manifest.excel.xml',
// 'manifest.word.xml',
// 'manifest.powerpoint.xml'
// ]
// const answers = {
// projectType: "single-sign-on",
// scriptType: "JavaScript",
// name: "SSOJavaScriptProject",
// host: hosts[3]
// };

describe('Office-Add-Taskpane-SSO-JS project', () => {
before((done) => {
helpers.run(path.join(__dirname, '../app')).withOptions({ 'test': true }).withPrompts(answers).on('end', done);
});
// describe('Office-Add-Taskpane-SSO-JS project', () => {
// before((done) => {
// helpers.run(path.join(__dirname, '../app')).withOptions({ 'test': true }).withPrompts(answers).on('end', done);
// });

it('creates expected files', (done) => {
assert.file(expectedFiles);
assert.noFile(unexpectedFiles);
assert.noFile(unexpectedManifestFiles);
done();
});
});
});
// it('creates expected files', (done) => {
// assert.file(expectedFiles);
// assert.noFile(unexpectedFiles);
// assert.noFile(unexpectedManifestFiles);
// done();
// });
// });
// });

0 comments on commit bb3e3cf

Please sign in to comment.