Skip to content

Instantly share code, notes, and snippets.

@Sinetheta
Last active July 14, 2016 13:45
Show Gist options
  • Save Sinetheta/6003037 to your computer and use it in GitHub Desktop.
Save Sinetheta/6003037 to your computer and use it in GitHub Desktop.
Using Yeoman to make a SharePoint 2010 project with REST.

Setting up a new Yeoman project using the sp2010 rest emulator:

  1. Create a new Yeoman project, eg: $ yo webapp my-project.
  2. Install the SharePoint 2010 rest emulator $ npm install sp2010-rest --save-dev.
  3. Add the rest emulator as middleware to any connect servers in your project's Gruntfile.js.
  4. Create a 'lists' folder in your project, and fill it with a copy of the json REST response (eg: /_vti_bin/listdata.svc/Documents -> demo-list.json) for any SharePoint lists you would like to emulate.

Deploying a Yeoman project to a sp2010 server:

  1. Map a network drive to SharePoint.
  2. Add a new grunt-contrib-copy task to your project's Gruntfile.js which points to a folder (for mac: /Volumes/server/subdomain/SitePages/my-project) in SharePoint.
  3. Build the project as usual $ grunt build.
  4. Create an index.aspx to host the contents of your index.html (either with an iframe or by copy/pasting the appropriate html).
{
"d": {
"results": [
{
"__metadata": {
"uri": "https://theloop.gov.bc.ca/_vti_bin/listdata.svc/Documents(2)",
"etag": "W/\"3\"",
"type": "Microsoft.SharePoint.DataService.DocumentsItem",
"edit_media": "https://theloop.gov.bc.ca/_vti_bin/listdata.svc/Documents(2)/$value",
"media_src": "https://theloop.gov.bc.ca/Documents/Ministry New_eApprovals_Calendar.pdf",
"content_type": "application/octetstream",
"media_etag": "\"{720C2D2B-F7A9-403A-97EC-497510D165BF},3\""
},
"ContentTypeID": "0x010100D8E40731C2136B43B9CF9790FFC41140",
"Name": "Ministry New_eApprovals_Calendar.pdf",
"Title": null,
"Id": 2,
"ContentType": "Document",
"Created": "/Date(1328874708000)/",
"CreatedBy": {
"__deferred": {
"uri": "https://theloop.gov.bc.ca/_vti_bin/listdata.svc/Documents(2)/CreatedBy"
}
},
"CreatedById": 82,
"Modified": "/Date(1328875567000)/",
"ModifiedBy": {
"__deferred": {
"uri": "https://theloop.gov.bc.ca/_vti_bin/listdata.svc/Documents(2)/ModifiedBy"
}
},
"ModifiedById": 82,
"CopySource": null,
"ApprovalStatus": "0",
"Path": "/Documents",
"CheckedOutTo": {
"__deferred": {
"uri": "https://theloop.gov.bc.ca/_vti_bin/listdata.svc/Documents(2)/CheckedOutTo"
}
},
"CheckedOutToId": null,
"VirusStatus": "13789776",
"IsCurrentVersion": true,
"Owshiddenversion": 3,
"Version": "2.0"
}
]
}
}
// require SharePoint 2010 rest emulator
var sp2010rest = require('sp2010-rest');
// ...
// add path to SharePoint project home
var yeomanConfig = {
app: 'app',
dist: 'dist',
sp: '/Volumes/theloop.gov.bc.ca/<subsite?>/SitePages/my-project'
};
// ...
// add REST emulator as middleware to all connect tasks
connect: {
livereload: {
options: {
middleware: function (connect) {
return [
lrSnippet,
sp2010rest(connect, 'lists'),
mountFolder(connect, '.tmp'),
mountFolder(connect, 'app')
];
}
}
}
}
// ...
// new contrib-copy task to duplicate dist folder on SharePoint
copy: {
sp: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.dist %>',
dest: '<%= yeoman.sp %>',
src: ['**']
}]
}
},
<%@ Page Language="C#" masterpagefile="~masterurl/default.master" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:progid="SharePoint.WebPartPage.Document" meta:webpartpageexpansion="full" %>
<asp:Content id="WayTooBigTitleTag" contentplaceholderid="PlaceHolderPageTitle" runat="server">Title</asp:Content>
<asp:Content id="HeadInHere" contentplaceholderid="PlaceHolderAdditionalPageHead" runat="server">
<!-- PlaceHolderAdditionalPageHead -->
<script src="/ssrc/scripts/page-layout/commonAlways.js"></script>
<!-- end PlaceHolderAdditionalPageHead -->
</asp:Content>
<asp:Content id="Content1" runat="server" contentplaceholderid="PlaceHolderMain">
<!-- PlaceHolderMain -->
<!-- end PlaceHolderMain -->
</asp:Content>
<asp:Content id="Content2" runat="server" contentplaceholderid="PlaceHolderPageTitleInTitleArea">
<h1>Title</h1>
</asp:Content>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment