@adobe/helix-onedrive-cli 1.10.18 → 1.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/package.json +6 -6
- package/src/onedrive.cmd.js +18 -6
- package/src/onedrive.js +85 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [1.11.3](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.2...v1.11.3) (2022-02-03)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency @adobe/helix-shared-config to v1.7.6 ([#269](https://github.com/adobe/helix-onedrive-cli/issues/269)) ([1b2d5c9](https://github.com/adobe/helix-onedrive-cli/commit/1b2d5c9f4c577ceb709a8700b9ca3127bbfcd572))
|
|
7
|
+
|
|
8
|
+
## [1.11.2](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.1...v1.11.2) (2022-01-31)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **deps:** update dependency dotenv to v15 ([#268](https://github.com/adobe/helix-onedrive-cli/issues/268)) ([5dfbea7](https://github.com/adobe/helix-onedrive-cli/commit/5dfbea7bf5e42e8e164395c8eee76ad4e2cd324f))
|
|
14
|
+
|
|
15
|
+
## [1.11.1](https://github.com/adobe/helix-onedrive-cli/compare/v1.11.0...v1.11.1) (2022-01-29)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* **deps:** update external fixes ([d3b8cf9](https://github.com/adobe/helix-onedrive-cli/commit/d3b8cf912c1b40d4966a9c0138f12f00ea5beb18))
|
|
21
|
+
|
|
22
|
+
# [1.11.0](https://github.com/adobe/helix-onedrive-cli/compare/v1.10.18...v1.11.0) (2022-01-28)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Features
|
|
26
|
+
|
|
27
|
+
* use new sharepoint API on demand ([#265](https://github.com/adobe/helix-onedrive-cli/issues/265)) ([36d250d](https://github.com/adobe/helix-onedrive-cli/commit/36d250d2acf24ef9958b7707db966aa845bf2873))
|
|
28
|
+
|
|
1
29
|
## [1.10.18](https://github.com/adobe/helix-onedrive-cli/compare/v1.10.17...v1.10.18) (2022-01-28)
|
|
2
30
|
|
|
3
31
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-onedrive-cli",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.3",
|
|
4
4
|
"description": "Helix OneDrive CLI",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"@adobe/helix-log": "6.0.0",
|
|
29
29
|
"@adobe/helix-onedrive-support": "6.1.0",
|
|
30
30
|
"chalk-template": "0.3.1",
|
|
31
|
-
"@adobe/helix-shared-config": "1.7.
|
|
31
|
+
"@adobe/helix-shared-config": "1.7.6",
|
|
32
32
|
"cookie-parser": "1.4.6",
|
|
33
|
-
"dotenv": "
|
|
33
|
+
"dotenv": "15.0.0",
|
|
34
34
|
"express": "4.17.2",
|
|
35
35
|
"fs-extra": "10.0.0",
|
|
36
36
|
"open": "8.4.0",
|
|
@@ -43,13 +43,13 @@
|
|
|
43
43
|
"@semantic-release/npm": "9.0.0",
|
|
44
44
|
"c8": "7.11.0",
|
|
45
45
|
"codecov": "3.8.3",
|
|
46
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.8.0",
|
|
47
47
|
"eslint-plugin-header": "3.1.1",
|
|
48
48
|
"eslint-plugin-import": "2.25.4",
|
|
49
49
|
"husky": "7.0.4",
|
|
50
50
|
"junit-report-builder": "3.0.0",
|
|
51
|
-
"lint-staged": "12.3.
|
|
52
|
-
"mocha": "9.
|
|
51
|
+
"lint-staged": "12.3.2",
|
|
52
|
+
"mocha": "9.2.0",
|
|
53
53
|
"nodemon": "2.0.15",
|
|
54
54
|
"semantic-release": "19.0.2"
|
|
55
55
|
},
|
package/src/onedrive.cmd.js
CHANGED
|
@@ -49,17 +49,29 @@ export default async function install(yargs) {
|
|
|
49
49
|
.command({
|
|
50
50
|
command: 'ls [path]',
|
|
51
51
|
desc: 'Lists the contents of the [path]',
|
|
52
|
-
|
|
52
|
+
builder: (y) => y
|
|
53
|
+
.option('sharepoint', {
|
|
54
|
+
alias: 's',
|
|
55
|
+
type: 'boolean',
|
|
56
|
+
description: 'Use the SharePoint API.',
|
|
57
|
+
}),
|
|
58
|
+
handler: (y) => onedrive.ls(y),
|
|
53
59
|
})
|
|
54
60
|
.command({
|
|
55
61
|
command: 'get <path> [local]',
|
|
56
62
|
desc: 'downloads the file at path',
|
|
57
63
|
handler: onedrive.download,
|
|
58
|
-
builder: (y) => y
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
builder: (y) => y
|
|
65
|
+
.option('sharepoint', {
|
|
66
|
+
alias: 's',
|
|
67
|
+
type: 'boolean',
|
|
68
|
+
description: 'Use the SharePoint API.',
|
|
69
|
+
})
|
|
70
|
+
.option('recursive', {
|
|
71
|
+
alias: 'r',
|
|
72
|
+
type: 'boolean',
|
|
73
|
+
description: 'Download recursively',
|
|
74
|
+
}),
|
|
63
75
|
})
|
|
64
76
|
.command({
|
|
65
77
|
command: 'put <local> [path]]',
|
package/src/onedrive.js
CHANGED
|
@@ -104,6 +104,7 @@ async function resolve(args) {
|
|
|
104
104
|
info(chalk` URL: {yellow ${webUrl}}`);
|
|
105
105
|
info(chalk`DriveId: {yellow ${driveId}}`);
|
|
106
106
|
const state = await getState();
|
|
107
|
+
state.link = link;
|
|
107
108
|
state.root = canonicalPath;
|
|
108
109
|
state.cwd = '/';
|
|
109
110
|
await saveState();
|
|
@@ -121,6 +122,38 @@ async function getDriveItem(url) {
|
|
|
121
122
|
};
|
|
122
123
|
}
|
|
123
124
|
|
|
125
|
+
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
|
126
|
+
|
|
127
|
+
function dateFormat(s) {
|
|
128
|
+
const d = new Date(s);
|
|
129
|
+
const date = `${MONTHS[d.getMonth()]} ${d.getDate().toString().padStart(2, ' ')}`;
|
|
130
|
+
const time = `${d.getHours().toString().padStart(2, '0')}:${d.getMinutes().toString().padStart(2, '0')}:${d.getSeconds().toString().padStart(2, '0')}`;
|
|
131
|
+
return `${date} ${time}`;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function graphApiFormatter(item) {
|
|
135
|
+
const user = item.lastModifiedBy.user.email;
|
|
136
|
+
const date = item.lastModifiedDateTime;
|
|
137
|
+
const size = item.folder?.childCount ?? item.size;
|
|
138
|
+
let { name } = item;
|
|
139
|
+
if (item.folder) {
|
|
140
|
+
name = chalk`{blue ${name}}`;
|
|
141
|
+
}
|
|
142
|
+
return `${user.padEnd(18, ' ')}${size.toString().padStart(10, ' ')} ${dateFormat(date)} ${name}\n`;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function sharePointApiFormatter(item) {
|
|
146
|
+
const user = item.ModifiedBy?.UserPrincipalName ?? '';
|
|
147
|
+
const date = item.TimeLastModified;
|
|
148
|
+
const size = item.ItemCount ?? item.Length;
|
|
149
|
+
let { Name: name } = item;
|
|
150
|
+
|
|
151
|
+
if (item.ItemCount) {
|
|
152
|
+
name = chalk`{blue ${name}}`;
|
|
153
|
+
}
|
|
154
|
+
return `${user.padEnd(18, ' ')}${size.toString().padStart(10, ' ')} ${dateFormat(date)} ${name}\n`;
|
|
155
|
+
}
|
|
156
|
+
|
|
124
157
|
async function ls(args) {
|
|
125
158
|
const state = await loadState();
|
|
126
159
|
if (!state.root) {
|
|
@@ -129,19 +162,49 @@ async function ls(args) {
|
|
|
129
162
|
if (args.path && args.path.startsWith('https://')) {
|
|
130
163
|
throw Error(chalk`${args._[0]} does not work on share links directly. use '{grey ${args.$0} resolve}' to set root.`);
|
|
131
164
|
}
|
|
132
|
-
|
|
133
|
-
const
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
165
|
+
|
|
166
|
+
const children = [];
|
|
167
|
+
let formatter;
|
|
168
|
+
|
|
169
|
+
if (args.sharepoint) {
|
|
170
|
+
const od = await getOneDriveClient();
|
|
171
|
+
const site = await od.getSite(state.link);
|
|
172
|
+
|
|
173
|
+
let folder;
|
|
174
|
+
try {
|
|
175
|
+
folder = await site.getFolder(args.path);
|
|
176
|
+
} catch (e) {
|
|
177
|
+
if (e.statusCode !== 404) {
|
|
178
|
+
throw e;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (folder) {
|
|
182
|
+
const result = await site.getFilesAndFolders(args.path);
|
|
183
|
+
children.push(...result.d.Folders.results);
|
|
184
|
+
children.push(...result.d.Files.results);
|
|
185
|
+
children.sort(({ Name: name1 }, { Name: name2 }) => name1.localeCompare(name2));
|
|
186
|
+
} else {
|
|
187
|
+
const result = await site.getFile(args.path);
|
|
188
|
+
children.push(result.d);
|
|
189
|
+
}
|
|
190
|
+
formatter = sharePointApiFormatter;
|
|
191
|
+
} else {
|
|
192
|
+
const p = path.posix.join(state.cwd, args.path || '');
|
|
193
|
+
const driveItem = await getDriveItem(state.root);
|
|
194
|
+
const od = await getOneDriveClient();
|
|
195
|
+
const item = await od.getDriveItem(driveItem, p);
|
|
140
196
|
if (item.folder) {
|
|
141
|
-
|
|
197
|
+
const result = await od.listChildren(driveItem, p);
|
|
198
|
+
children.push(...result.value);
|
|
199
|
+
children.sort(({ name: name1 }, { name: name2 }) => name1.localeCompare(name2));
|
|
200
|
+
} else {
|
|
201
|
+
children.push(item);
|
|
142
202
|
}
|
|
143
|
-
|
|
144
|
-
|
|
203
|
+
formatter = graphApiFormatter;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
children.forEach((child) => {
|
|
207
|
+
process.stdout.write(formatter(child));
|
|
145
208
|
});
|
|
146
209
|
}
|
|
147
210
|
|
|
@@ -204,6 +267,10 @@ async function download(args) {
|
|
|
204
267
|
if (!state.root) {
|
|
205
268
|
throw Error(chalk`${args._[0]} needs path. use '{grey ${args.$0} resolve}' to set root.`);
|
|
206
269
|
}
|
|
270
|
+
if (args.recursive && args.sharepoint) {
|
|
271
|
+
throw Error(chalk`Recursive download via Sharepoint API not supported yet.`);
|
|
272
|
+
}
|
|
273
|
+
|
|
207
274
|
const p = path.posix.join(state.cwd, args.path);
|
|
208
275
|
|
|
209
276
|
let dst = path.resolve('.', path.posix.basename(p));
|
|
@@ -229,7 +296,13 @@ async function download(args) {
|
|
|
229
296
|
await downloadRecursively(od, path.dirname(dst), args.path, result);
|
|
230
297
|
} else {
|
|
231
298
|
info(chalk`saving to {yellow ${path.relative('.', dst)}}`);
|
|
232
|
-
|
|
299
|
+
let result;
|
|
300
|
+
if (args.sharepoint) {
|
|
301
|
+
const site = await od.getSite(state.link);
|
|
302
|
+
result = await site.getFileContents(args.path);
|
|
303
|
+
} else {
|
|
304
|
+
result = await od.getDriveItem(driveItem, p, true);
|
|
305
|
+
}
|
|
233
306
|
await fs.writeFile(dst, result);
|
|
234
307
|
}
|
|
235
308
|
}
|