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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ A collection of code snippets built with [Script Lab](//github.com/OfficeDev/scr
1. [Fork](https://help.github.com/articles/about-forks/) this project into your GitHub account.
1. Clone your fork to your development computer.
1. Ensure that you have Node, version 6.10+, installed. (To check the version run the command `node -v`.)
1. Install `yarn` as a global package `npm install yarn --global`.
1. Be sure your CLI is in the root of the office-js-snippets repo and run `yarn install`. (It's similar to `npm install`.)
1. Be sure your CLI is in the root of the office-js-snippets repo and run `npm install` to install all dependencies.
1. Set up the original \OfficeDev\office-js-snippets as the upstream repo for your local repo by following the steps in [Configuring a remote for a fork](https://help.github.com/articles/configuring-a-remote-for-a-fork/).
1. If you'll be using Visual Studio Code as your editor, install the [TSLint](https://marketplace.visualstudio.com/items?itemName=eg2.tslint) extension for Visual Studio Code.

Expand Down Expand Up @@ -46,11 +45,11 @@ A collection of code snippets built with [Script Lab](//github.com/OfficeDev/scr

1. Open one of the `.yaml` files already in the group folder. If it has an `order` property near the top, then the snippets in the group folder are ordered in a particular sequence in Script Lab. Add an `order` property to the top of your `.yaml` file and give it a number that is between the order numbers of the snippets between which you want it to appear.
1. Copy your `.yaml` file to the chosen group folder.
1. Run `yarn start`. If there are no problems, the output will end with a `Done!`. If there are errors, review the output to check what caused the build validation to fail, and fix as needed. See [**Known errors and fixes**](#known-errors-and-fixes-in-the-build-tool) for more information.
1. Run `npm start`. If there are no problems, the output will end with a `Done!`. If there are errors, review the output to check what caused the build validation to fail, and fix as needed. See [**Known errors and fixes**](#known-errors-and-fixes-in-the-build-tool) for more information.

> **Note**: The `yarn start` command adds an `id` property to the top of the file.
> **Note**: The `npm start` command adds an `id` property to the top of the file.

1. Re-run `yarn start`, and fix errors, until the build succeeds.
1. Re-run `npm start`, and fix errors, until the build succeeds.
1. Run `git status`. You should see that, in addition to your new `.yaml` file (or possibly new folder), a `playlist\{host}.yaml` file (where `{host}` is `excel`, `word`, etc.) has also been changed. This is expected. The build tool you just ran added a reference to your new snippet to this file.
1. Run the following two commands. The commit message should be a brief description of what the snippet demonstrates; for example, `"shows how to use getWhatever method"`.

Expand Down
4 changes: 2 additions & 2 deletions config/build.documentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function buildReferenceDocSnippetExtracts(
await rmRf('snippet-extractor-output');
await mkDir('snippet-extractor-output');

const contents = snippetExtractsPerHost.map(extracts => jsyaml.safeDump(extracts)).join('');
const contents = snippetExtractsPerHost.map(extracts => jsyaml.dump(extracts)).join('');
await writeFile(path.resolve(`snippet-extractor-output/snippets.yaml`), contents);
}

Expand Down Expand Up @@ -119,7 +119,7 @@ function getExtractedDataFromSnippet(
const filename = snippetIdsToFilenames[row.snippetId];
if (filename) {
try {
const script = (jsyaml.safeLoad(fs.readFileSync(filename).toString()) as ISnippet).script.content;
const script = (jsyaml.load(fs.readFileSync(filename).toString()) as ISnippet).script.content;

const fullSnippetTextArray = script.split('\n')
.map(line => line.replace(/\r/, ''));
Expand Down
14 changes: 9 additions & 5 deletions config/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import * as path from 'path';
import { isNil, isString, isArray, isEmpty, sortBy, cloneDeep } from 'lodash';
import * as chalk from 'chalk';
import chalk from 'chalk';
import escapeStringRegexp from 'escape-string-regexp';
import { status } from './status';
import {
SnippetFileInput, SnippetProcessedData,
Expand All @@ -14,7 +15,6 @@ import { getShareableYaml } from './snippet.helpers';
import { processLibraries } from './libraries.processor';
import { startCase, groupBy, map } from 'lodash';
import * as jsyaml from 'js-yaml';
import escapeStringRegexp = require('escape-string-regexp');
import * as fsx from 'fs-extra';


Expand Down Expand Up @@ -84,7 +84,7 @@ async function processSnippets(processedSnippets: Dictionary<SnippetProcessedDat

const fullPath = path.resolve(dir, file.relativePath);
const originalFileContents = fsx.readFileSync(fullPath).toString().trim();
let snippet = jsyaml.safeLoad(originalFileContents) as ISnippet;
let snippet = jsyaml.load(originalFileContents) as ISnippet;

// Do validations & auto-corrections
validateStringFieldNotEmptyOrThrow(snippet, 'name');
Expand All @@ -103,7 +103,11 @@ async function processSnippets(processedSnippets: Dictionary<SnippetProcessedDat
const additionalFields: ISnippet = <any>{};
additionalFields.id = snippet.id;
additionalFields.api_set = snippet.api_set;
additionalFields.author = snippet.author;

// Only set author field if it has a value
if (snippet.author) {
additionalFields.author = snippet.author;
}

if ((typeof (snippet as any).order) !== 'undefined') {
// # for ordering, if present (used for samples only)
Expand Down Expand Up @@ -537,7 +541,7 @@ async function generatePlaylists(processedSnippets: Dictionary<SnippetProcessedD
};
});

let contents = jsyaml.safeDump(modifiedItems, {
let contents = jsyaml.dump(modifiedItems, {
skipInvalid: true /* skip "undefined" (e.g., for "order" on some of the snippets) */
});

Expand Down
23 changes: 9 additions & 14 deletions config/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as path from 'path';
import * as fs from 'fs';
import * as os from 'os';
import * as chalk from 'chalk';
import chalk from 'chalk';
import * as jsyaml from 'js-yaml';
import { console } from './status';
import * as rimraf from 'rimraf';
import { rimraf } from 'rimraf';
import { isObject, isNil, isString, isEmpty } from 'lodash';

export interface SnippetFileInput {
Expand Down Expand Up @@ -39,7 +39,7 @@ export interface SnippetProcessedData {
* @param message Message of the banner.
* @param chalkFunction Chalk color function.
*/
export const banner = (title: string, message: string = null, chalkFn: chalk.ChalkChain = null) => {
export const banner = (title: string, message: string = null, chalkFn: any = null) => {
if (!chalkFn) {
chalkFn = chalk.bold;
}
Expand All @@ -55,7 +55,7 @@ export const banner = (title: string, message: string = null, chalkFn: chalk.Cha
};

export function getPrintableDetails(item: any, indent: number) {
const details = jsyaml.safeDump(item, {
const details = jsyaml.dump(item, {
indent: 4,
lineWidth: -1,
skipInvalid: true
Expand Down Expand Up @@ -83,16 +83,11 @@ export const mkDir = (dir: string) =>
* Deletes a folder.
* @param dir An absolute path to the directory.
*/
export const rmRf = (dir: string) =>
new Promise<string>((resolve, reject) => {
const location = path.resolve(dir);
rimraf(location, (err) => {
if (err) {
return reject(err);
}
return resolve(location);
});
});
export const rmRf = async (dir: string): Promise<string> => {
const location = path.resolve(dir);
await rimraf(location);
return location;
};

/**
* Load all the files and folders in a given directory.
Expand Down
4 changes: 2 additions & 2 deletions config/snippet.helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function scrubCarriageReturns(snippet: ISnippet) {
export function getScrubbedSnippet(snippet: ISnippet, keep: SnippetFieldType): ISnippet {
let copy = {};
forIn(snippetFields, (fieldType, fieldName) => {
if (fieldType & keep) {
if (fieldType & keep && snippet[fieldName] !== undefined) {
copy[fieldName] = snippet[fieldName];
}
});
Expand All @@ -103,7 +103,7 @@ export function getShareableYaml(rawSnippet: ISnippet, additionalFields: ISnippe
const snippet = { ...getScrubbedSnippet(rawSnippet, SnippetFieldType.PUBLIC), ...additionalFields };
scrubCarriageReturns(snippet);

return jsyaml.safeDump(snippet, {
return jsyaml.dump(snippet, {
indent: 4,
lineWidth: -1,
sortKeys: <any>((a, b) => snippetFieldSortingOrder[a] - snippetFieldSortingOrder[b]),
Expand Down
2 changes: 1 addition & 1 deletion config/status.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as nodeStatus from 'node-status';
import * as chalk from 'chalk';
import chalk from 'chalk';
import { isString, find, isNil, isArray } from 'lodash';

interface IStage {
Expand Down
30 changes: 14 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@
},
"homepage": "https://github.com/OfficeDev/office-js-snippets#readme",
"dependencies": {
"chalk": "1.1.3",
"escape-string-regexp": "^2.0.0",
"exceljs": "^4.3.0",
"fs-extra": "3.0.1",
"js-yaml": "^3.13.1",
"chalk": "^4.1.2",
"escape-string-regexp": "^4.0.0",
"exceljs": "^4.4.0",
"fs-extra": "11.3.2",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"node-status": "^1.0.0",
"rimraf": "^3.0.0",
"shelljs": "^0.8.5",
"yarn": "^1.22.19"
"rimraf": "^6.0.1",
"shelljs": "^0.10.0"
},
"devDependencies": {
"@types/chalk": "0.4.31",
"@types/fs-extra": "3.0.1",
"@types/js-yaml": "^3.12.0",
"@types/lodash": "^4.14.175",
"@types/node": "^11.10.5",
"@types/shelljs": "^0.8.3",
"tslint": "^6.1.0",
"typescript": "^3.3.3333"
"@types/fs-extra": "^11.0.4",
"@types/js-yaml": "^4.0.9",
"@types/lodash": "^4.17.20",
"@types/node": "^24.5.2",
"@types/shelljs": "^0.8.17",
"tslint": "^6.1.3",
"typescript": "^5.9.2"
}
}
26 changes: 13 additions & 13 deletions playlists-prod/excel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
- id: excel-chart-axis
name: Axis details
fileName: chart-axis.yaml
description: 'Gets, sets, and removes axis unit, label, and title in a chart.'
description: Gets, sets, and removes axis unit, label, and title in a chart.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-axis.yaml
group: Chart
Expand Down Expand Up @@ -162,7 +162,7 @@
- id: excel-chart-trendlines
name: Trendlines
fileName: chart-trendlines.yaml
description: 'Adds, gets, and formats trendlines in a chart.'
description: Adds, gets, and formats trendlines in a chart.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-trendlines.yaml
group: Chart
Expand All @@ -189,7 +189,7 @@
- id: excel-comment-basics
name: Comment basics
fileName: comment-basics.yaml
description: 'Adds, edits, and removes comments.'
description: Adds, edits, and removes comments.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/comment-basics.yaml
group: Comments And Notes
Expand All @@ -207,7 +207,7 @@
- id: excel-comment-replies
name: Comment replies
fileName: comment-replies.yaml
description: 'Adds, edits, and removes comment replies.'
description: Adds, edits, and removes comment replies.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/comment-replies.yaml
group: Comments And Notes
Expand All @@ -225,7 +225,7 @@
- id: excel-note-basics
name: Notes
fileName: excel-note-basics.yaml
description: 'Adds, edits, and removes notes.'
description: Adds, edits, and removes notes.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/excel-note-basics.yaml
group: Comments And Notes
Expand Down Expand Up @@ -319,7 +319,7 @@
- id: excel-custom-xml-parts-create-set-get-and-delete-custom-xml-parts
name: Using custom XML parts
fileName: create-set-get-and-delete-custom-xml-parts.yaml
description: 'Creates, sets, gets, and deletes a custom XML part.'
description: Creates, sets, gets, and deletes a custom XML part.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml
group: Custom XML Parts
Expand Down Expand Up @@ -625,9 +625,9 @@
api_set:
ExcelAPI: '1.14'
- id: excel-named-item-create-and-remove-named-item
name: 'Create, access, and remove'
name: Create, access, and remove
fileName: create-and-remove-named-item.yaml
description: 'Creates, accesses, and removes named items in a worksheet.'
description: Creates, accesses, and removes named items in a worksheet.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/34-named-item/create-and-remove-named-item.yaml
group: Named Item
Expand Down Expand Up @@ -785,16 +785,16 @@
- id: excel-range-hyperlink
name: Hyperlinks
fileName: range-hyperlink.yaml
description: 'Creates, updates, and clears hyperlinks in a range.'
description: Creates, updates, and clears hyperlinks in a range.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/range-hyperlink.yaml
group: Range
api_set:
ExcelApi: '1.7'
- id: excel-range-insert-delete-and-clear-range
name: 'Insert, delete, and clear'
name: Insert, delete, and clear
fileName: insert-delete-clear-range.yaml
description: 'Inserts, deletes, and clears a range.'
description: Inserts, deletes, and clears a range.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/insert-delete-clear-range.yaml
group: Range
Expand Down Expand Up @@ -1217,9 +1217,9 @@
api_set:
ExcelApi: '1.1'
- id: excel-worksheet-add-delete-rename-move-worksheet
name: 'Add, delete, rename, and move worksheet'
name: Add, delete, rename, and move worksheet
fileName: add-delete-rename-move-worksheet.yaml
description: 'Adds, deletes, renames, and moves a worksheet.'
description: Adds, deletes, renames, and moves a worksheet.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/add-delete-rename-move-worksheet.yaml
group: Worksheet
Expand Down
16 changes: 8 additions & 8 deletions playlists-prod/outlook.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
- id: outlook-roaming-settings-roaming-settings
name: Use add-in settings
fileName: roaming-settings.yaml
description: 'Gets, sets, saves, and removes add-in roaming settings.'
description: Gets, sets, saves, and removes add-in roaming settings.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/10-roaming-settings/roaming-settings.yaml
group: Roaming Settings
Expand Down Expand Up @@ -295,7 +295,7 @@
- id: outlook-categories-work-with-categories
name: Work with item categories
fileName: work-with-categories.yaml
description: 'Gets, adds, and removes categories assigned to the item.'
description: Gets, adds, and removes categories assigned to the item.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-categories.yaml
group: Categories
Expand All @@ -304,7 +304,7 @@
- id: outlook-categories-work-with-master-categories
name: Work with the categories master list
fileName: work-with-master-categories.yaml
description: 'Gets, adds, and removes categories in the master list for the mailbox.'
description: Gets, adds, and removes categories in the master list for the mailbox.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/45-categories/work-with-master-categories.yaml
group: Categories
Expand Down Expand Up @@ -447,7 +447,7 @@
api_set:
Mailbox: '1.8'
- id: outlook-regex-matches-contextual
name: 'Get regex matches (Item Read, contextual)'
name: Get regex matches (Item Read, contextual)
fileName: contextual.yaml
description: Gets regex matches when the add-in is opened as a contextual add-in.
rawUrl: >-
Expand Down Expand Up @@ -639,7 +639,7 @@
- id: outlook-other-item-apis-get-add-remove-enhancedlocation-appointment
name: Manage the locations of an appointment
fileName: get-add-remove-enhancedlocation-appointment.yaml
description: 'Gets, adds, and removes locations on an appointment (enhancedLocation API).'
description: Gets, adds, and removes locations on an appointment (enhancedLocation API).
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/get-add-remove-enhancedlocation-appointment.yaml
group: Other Item APIs
Expand Down Expand Up @@ -704,7 +704,7 @@
- id: outlook-other-item-apis-session-data-apis
name: Work with session data APIs (Compose)
fileName: session-data-apis.yaml
description: 'Sets, gets, gets all, removes, and clears session data in Compose mode.'
description: Sets, gets, gets all, removes, and clears session data in Compose mode.
rawUrl: >-
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/outlook/90-other-item-apis/session-data-apis.yaml
group: Other Item APIs
Expand All @@ -720,7 +720,7 @@
api_set:
Mailbox: '1.13'
- id: outlook-other-item-apis-get-message-properties
name: 'Get properties of selected messages (Message Compose, Message Read)'
name: Get properties of selected messages (Message Compose, Message Read)
fileName: get-message-properties.yaml
description: Gets the properties of multiple selected messages.
rawUrl: >-
Expand Down Expand Up @@ -794,7 +794,7 @@
api_set:
Mailbox: '1.15'
- id: outlook-other-item-apis-get-loaded-message-properties
name: 'Get properties of a loaded message (Message Compose, Message Read)'
name: Get properties of a loaded message (Message Compose, Message Read)
fileName: get-loaded-message-properties.yaml
description: Gets the properties of the currently loaded message.
rawUrl: >-
Expand Down
Loading