Skip to content

Commit be7c5b4

Browse files
author
github-actions
committed
Merge branch 'main' into prod
2 parents 0a995ca + 70bec7a commit be7c5b4

File tree

332 files changed

+1584
-2594
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

332 files changed

+1584
-2594
lines changed

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ A collection of code snippets built with [Script Lab](//github.com/OfficeDev/scr
1313
1. [Fork](https://help.github.com/articles/about-forks/) this project into your GitHub account.
1414
1. Clone your fork to your development computer.
1515
1. Ensure that you have Node, version 6.10+, installed. (To check the version run the command `node -v`.)
16-
1. Install `yarn` as a global package `npm install yarn --global`.
17-
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`.)
16+
1. Be sure your CLI is in the root of the office-js-snippets repo and run `npm install` to install all dependencies.
1817
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/).
1918
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.
2019

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

4746
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.
4847
1. Copy your `.yaml` file to the chosen group folder.
49-
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.
48+
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.
5049

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

53-
1. Re-run `yarn start`, and fix errors, until the build succeeds.
52+
1. Re-run `npm start`, and fix errors, until the build succeeds.
5453
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.
5554
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"`.
5655

config/build.documentation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export async function buildReferenceDocSnippetExtracts(
3636
await rmRf('snippet-extractor-output');
3737
await mkDir('snippet-extractor-output');
3838

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

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

124124
const fullSnippetTextArray = script.split('\n')
125125
.map(line => line.replace(/\r/, ''));

config/build.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
import * as path from 'path';
44
import { isNil, isString, isArray, isEmpty, sortBy, cloneDeep } from 'lodash';
5-
import * as chalk from 'chalk';
5+
import chalk from 'chalk';
6+
import escapeStringRegexp from 'escape-string-regexp';
67
import { status } from './status';
78
import {
89
SnippetFileInput, SnippetProcessedData,
@@ -14,7 +15,6 @@ import { getShareableYaml } from './snippet.helpers';
1415
import { processLibraries } from './libraries.processor';
1516
import { startCase, groupBy, map } from 'lodash';
1617
import * as jsyaml from 'js-yaml';
17-
import escapeStringRegexp = require('escape-string-regexp');
1818
import * as fsx from 'fs-extra';
1919

2020

@@ -84,7 +84,7 @@ async function processSnippets(processedSnippets: Dictionary<SnippetProcessedDat
8484

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

8989
// Do validations & auto-corrections
9090
validateStringFieldNotEmptyOrThrow(snippet, 'name');
@@ -103,7 +103,11 @@ async function processSnippets(processedSnippets: Dictionary<SnippetProcessedDat
103103
const additionalFields: ISnippet = <any>{};
104104
additionalFields.id = snippet.id;
105105
additionalFields.api_set = snippet.api_set;
106-
additionalFields.author = snippet.author;
106+
107+
// Only set author field if it has a value
108+
if (snippet.author) {
109+
additionalFields.author = snippet.author;
110+
}
107111

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

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

config/helpers.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as path from 'path';
22
import * as fs from 'fs';
33
import * as os from 'os';
4-
import * as chalk from 'chalk';
4+
import chalk from 'chalk';
55
import * as jsyaml from 'js-yaml';
6-
import { console } from './status';
7-
import * as rimraf from 'rimraf';
6+
import { rimraf } from 'rimraf';
87
import { isObject, isNil, isString, isEmpty } from 'lodash';
98

109
export interface SnippetFileInput {
@@ -39,7 +38,7 @@ export interface SnippetProcessedData {
3938
* @param message Message of the banner.
4039
* @param chalkFunction Chalk color function.
4140
*/
42-
export const banner = (title: string, message: string = null, chalkFn: chalk.ChalkChain = null) => {
41+
export const banner = (title: string, message: string = null, chalkFn: any = null) => {
4342
if (!chalkFn) {
4443
chalkFn = chalk.bold;
4544
}
@@ -55,7 +54,7 @@ export const banner = (title: string, message: string = null, chalkFn: chalk.Cha
5554
};
5655

5756
export function getPrintableDetails(item: any, indent: number) {
58-
const details = jsyaml.safeDump(item, {
57+
const details = jsyaml.dump(item, {
5958
indent: 4,
6059
lineWidth: -1,
6160
skipInvalid: true
@@ -83,16 +82,11 @@ export const mkDir = (dir: string) =>
8382
* Deletes a folder.
8483
* @param dir An absolute path to the directory.
8584
*/
86-
export const rmRf = (dir: string) =>
87-
new Promise<string>((resolve, reject) => {
88-
const location = path.resolve(dir);
89-
rimraf(location, (err) => {
90-
if (err) {
91-
return reject(err);
92-
}
93-
return resolve(location);
94-
});
95-
});
85+
export const rmRf = async (dir: string): Promise<string> => {
86+
const location = path.resolve(dir);
87+
await rimraf(location);
88+
return location;
89+
};
9690

9791
/**
9892
* Load all the files and folders in a given directory.

config/snippet.helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function scrubCarriageReturns(snippet: ISnippet) {
9191
export function getScrubbedSnippet(snippet: ISnippet, keep: SnippetFieldType): ISnippet {
9292
let copy = {};
9393
forIn(snippetFields, (fieldType, fieldName) => {
94-
if (fieldType & keep) {
94+
if (fieldType & keep && snippet[fieldName] !== undefined) {
9595
copy[fieldName] = snippet[fieldName];
9696
}
9797
});
@@ -103,7 +103,7 @@ export function getShareableYaml(rawSnippet: ISnippet, additionalFields: ISnippe
103103
const snippet = { ...getScrubbedSnippet(rawSnippet, SnippetFieldType.PUBLIC), ...additionalFields };
104104
scrubCarriageReturns(snippet);
105105

106-
return jsyaml.safeDump(snippet, {
106+
return jsyaml.dump(snippet, {
107107
indent: 4,
108108
lineWidth: -1,
109109
sortKeys: <any>((a, b) => snippetFieldSortingOrder[a] - snippetFieldSortingOrder[b]),

config/status.ts

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import * as nodeStatus from 'node-status';
2-
import * as chalk from 'chalk';
3-
import { isString, find, isNil, isArray } from 'lodash';
1+
import chalk from 'chalk';
2+
import { isString, isNil, isArray } from 'lodash';
43

54
interface IStage {
65
steps: any[];
@@ -13,16 +12,29 @@ export class Status {
1312
steps: { [step: string]: boolean } = {};
1413

1514
get console() {
16-
return nodeStatus.console();
15+
// Return the global console object methods
16+
return {
17+
log: global.console.log.bind(global.console),
18+
error: global.console.error.bind(global.console),
19+
warn: global.console.warn.bind(global.console),
20+
info: global.console.info.bind(global.console)
21+
};
1722
}
1823

1924
constructor() {
20-
/* Initialize the status library */
21-
this.stages = nodeStatus.addItem('stages', {
22-
steps: []
23-
});
25+
/* Initialize the simple status system */
26+
this.stages = {
27+
steps: [],
28+
count: 0,
29+
doneStep: this.doneStep.bind(this)
30+
};
31+
}
2432

25-
nodeStatus.start();
33+
private doneStep(completed: boolean, message?: string): void {
34+
const symbol = completed ? chalk.green('✓') : chalk.red('✗');
35+
if (message) {
36+
global.console.log(`${symbol} ${message}`);
37+
}
2638
}
2739

2840
/**
@@ -37,22 +49,18 @@ export class Status {
3749
success = success && additionalDetails.findIndex(item => item instanceof Error) < 0;
3850

3951
const messageArray = getDetailsArray();
52+
const symbol = success ? chalk.green('✓') : chalk.red('✗');
4053

41-
if (messageArray.length === 0) {
42-
this.stages.doneStep(success);
43-
} else {
44-
// Add a newline before
45-
messageArray.splice(0, 0, '');
46-
this.stages.doneStep(success, messageArray.join('\n * ') + '\n');
47-
//FIXME `${chalk.bold.red('WARNING: one of the messages above was an error')}`)
48-
}
49-
50-
this.steps[stage] = false;
54+
// Log the completion with symbol
55+
global.console.log(`${symbol} ${stage}`);
5156

52-
if (!find(this.steps as any, (item) => item === true)) {
53-
nodeStatus.stop();
57+
if (messageArray.length > 0) {
58+
messageArray.forEach(msg => {
59+
global.console.log(` * ${msg}`);
60+
});
5461
}
5562

63+
this.steps[stage] = false;
5664

5765
// Helper:
5866
function getDetailsArray() {
@@ -82,12 +90,13 @@ export class Status {
8290
}
8391

8492
/**
85-
* Add a new stage and complete the previous stage.
93+
* Add a new stage and mark it as started.
8694
* @param stage Name of the stage.
8795
*/
8896
add(stage: string) {
8997
this.stages.steps.push(stage);
9098
this.steps[stage] = true;
99+
global.console.log(chalk.cyan(`○ ${stage}`));
91100
}
92101
}
93102

package.json

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,22 @@
2323
},
2424
"homepage": "https://github.com/OfficeDev/office-js-snippets#readme",
2525
"dependencies": {
26-
"chalk": "1.1.3",
27-
"escape-string-regexp": "^2.0.0",
28-
"exceljs": "^4.3.0",
29-
"fs-extra": "3.0.1",
30-
"js-yaml": "^3.13.1",
26+
"chalk": "^4.1.2",
27+
"escape-string-regexp": "^4.0.0",
28+
"exceljs": "^4.4.0",
29+
"fs-extra": "11.3.2",
30+
"js-yaml": "^4.1.0",
3131
"lodash": "^4.17.21",
32-
"node-status": "^1.0.0",
33-
"rimraf": "^3.0.0",
34-
"shelljs": "^0.8.5",
35-
"yarn": "^1.22.19"
32+
"rimraf": "^6.0.1",
33+
"shelljs": "^0.10.0"
3634
},
3735
"devDependencies": {
38-
"@types/chalk": "0.4.31",
39-
"@types/fs-extra": "3.0.1",
40-
"@types/js-yaml": "^3.12.0",
41-
"@types/lodash": "^4.14.175",
42-
"@types/node": "^11.10.5",
43-
"@types/shelljs": "^0.8.3",
44-
"tslint": "^6.1.0",
45-
"typescript": "^3.3.3333"
36+
"@types/fs-extra": "^11.0.4",
37+
"@types/js-yaml": "^4.0.9",
38+
"@types/lodash": "^4.17.20",
39+
"@types/node": "^24.5.2",
40+
"@types/shelljs": "^0.8.17",
41+
"tslint": "^6.1.3",
42+
"typescript": "^5.9.2"
4643
}
4744
}

playlists-prod/excel.yaml

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
- id: excel-chart-axis
3131
name: Axis details
3232
fileName: chart-axis.yaml
33-
description: 'Gets, sets, and removes axis unit, label, and title in a chart.'
33+
description: Gets, sets, and removes axis unit, label, and title in a chart.
3434
rawUrl: >-
3535
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-axis.yaml
3636
group: Chart
@@ -162,7 +162,7 @@
162162
- id: excel-chart-trendlines
163163
name: Trendlines
164164
fileName: chart-trendlines.yaml
165-
description: 'Adds, gets, and formats trendlines in a chart.'
165+
description: Adds, gets, and formats trendlines in a chart.
166166
rawUrl: >-
167167
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/10-chart/chart-trendlines.yaml
168168
group: Chart
@@ -189,7 +189,7 @@
189189
- id: excel-comment-basics
190190
name: Comment basics
191191
fileName: comment-basics.yaml
192-
description: 'Adds, edits, and removes comments.'
192+
description: Adds, edits, and removes comments.
193193
rawUrl: >-
194194
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/comment-basics.yaml
195195
group: Comments And Notes
@@ -207,7 +207,7 @@
207207
- id: excel-comment-replies
208208
name: Comment replies
209209
fileName: comment-replies.yaml
210-
description: 'Adds, edits, and removes comment replies.'
210+
description: Adds, edits, and removes comment replies.
211211
rawUrl: >-
212212
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/comment-replies.yaml
213213
group: Comments And Notes
@@ -225,7 +225,7 @@
225225
- id: excel-note-basics
226226
name: Notes
227227
fileName: excel-note-basics.yaml
228-
description: 'Adds, edits, and removes notes.'
228+
description: Adds, edits, and removes notes.
229229
rawUrl: >-
230230
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/12-comments-and-notes/excel-note-basics.yaml
231231
group: Comments And Notes
@@ -319,7 +319,7 @@
319319
- id: excel-custom-xml-parts-create-set-get-and-delete-custom-xml-parts
320320
name: Using custom XML parts
321321
fileName: create-set-get-and-delete-custom-xml-parts.yaml
322-
description: 'Creates, sets, gets, and deletes a custom XML part.'
322+
description: Creates, sets, gets, and deletes a custom XML part.
323323
rawUrl: >-
324324
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml
325325
group: Custom XML Parts
@@ -625,9 +625,9 @@
625625
api_set:
626626
ExcelAPI: '1.14'
627627
- id: excel-named-item-create-and-remove-named-item
628-
name: 'Create, access, and remove'
628+
name: Create, access, and remove
629629
fileName: create-and-remove-named-item.yaml
630-
description: 'Creates, accesses, and removes named items in a worksheet.'
630+
description: Creates, accesses, and removes named items in a worksheet.
631631
rawUrl: >-
632632
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/34-named-item/create-and-remove-named-item.yaml
633633
group: Named Item
@@ -785,16 +785,16 @@
785785
- id: excel-range-hyperlink
786786
name: Hyperlinks
787787
fileName: range-hyperlink.yaml
788-
description: 'Creates, updates, and clears hyperlinks in a range.'
788+
description: Creates, updates, and clears hyperlinks in a range.
789789
rawUrl: >-
790790
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/range-hyperlink.yaml
791791
group: Range
792792
api_set:
793793
ExcelApi: '1.7'
794794
- id: excel-range-insert-delete-and-clear-range
795-
name: 'Insert, delete, and clear'
795+
name: Insert, delete, and clear
796796
fileName: insert-delete-clear-range.yaml
797-
description: 'Inserts, deletes, and clears a range.'
797+
description: Inserts, deletes, and clears a range.
798798
rawUrl: >-
799799
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/42-range/insert-delete-clear-range.yaml
800800
group: Range
@@ -1217,9 +1217,9 @@
12171217
api_set:
12181218
ExcelApi: '1.1'
12191219
- id: excel-worksheet-add-delete-rename-move-worksheet
1220-
name: 'Add, delete, rename, and move worksheet'
1220+
name: Add, delete, rename, and move worksheet
12211221
fileName: add-delete-rename-move-worksheet.yaml
1222-
description: 'Adds, deletes, renames, and moves a worksheet.'
1222+
description: Adds, deletes, renames, and moves a worksheet.
12231223
rawUrl: >-
12241224
https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/54-worksheet/add-delete-rename-move-worksheet.yaml
12251225
group: Worksheet

0 commit comments

Comments
 (0)