-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
113 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
package-lock.json | ||
index.js | ||
*.tgz | ||
pdfs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const process = require('process'); | ||
const path = require('path'); | ||
const { program } = require('commander'); | ||
const dl = require('../lib/amba-pdf-dl.js'); | ||
|
||
const specPath = path.resolve(__dirname, '../specs'); | ||
const main = async () => { | ||
program | ||
.option('--amba-pdf-dl <folder>', 'download AMBA spec PDFs') | ||
.parse(process.argv); | ||
|
||
const opts = program.opts(); | ||
if (opts.ambaPdfDl) { | ||
await dl(opts.ambaPdfDl); | ||
return; | ||
} | ||
const specPath = path.resolve(__dirname, '../specs'); | ||
console.log(specPath); | ||
}; | ||
|
||
main(); | ||
|
||
console.log(specPath); | ||
/* eslint no-console:0 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict'; | ||
|
||
const { createWriteStream, existsSync } = require('fs'); | ||
const { mkdir } = require("fs/promises"); | ||
const path = require('path'); | ||
const { Readable } = require('stream'); | ||
const { finished } = require('stream/promises'); | ||
|
||
const specs = require('./amba-specs.js'); | ||
|
||
const dl = async (ambaSpecsDl) => { | ||
const dlFolderPath = path.resolve('.', ambaSpecsDl); | ||
if (!existsSync(dlFolderPath)) { | ||
await mkdir(dlFolderPath); | ||
} | ||
for (const spec of specs) { | ||
const url = `https://documentation-service.arm.com/static/${spec.id}?token=`; | ||
const res = await fetch(url); | ||
const headers = res.headers.entries(); | ||
let fileName; | ||
for (const [key, val] of headers) { | ||
if (key === 'content-disposition') { | ||
const m = val.match(/^attachment; filename=(?<baseName>[\w_-]+).pdf$/); | ||
fileName = m.groups.baseName + '.pdf'; | ||
} | ||
} | ||
const fullFileName = path.resolve('.', dlFolderPath, fileName); | ||
if (!existsSync(fullFileName)) { | ||
const fileStream = createWriteStream(fullFileName, { flags: 'wx'}); | ||
await finished(Readable.fromWeb(res.body).pipe(fileStream)); | ||
console.log(fileName + ' - downloded'); | ||
} else { | ||
console.log(fileName + ' - exists'); | ||
} | ||
} | ||
}; | ||
|
||
module.exports = dl; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,7 @@ | |
"nyc": "^15.1.0" | ||
}, | ||
"dependencies": { | ||
"commander": "^12.1.0", | ||
"json5": "^2.2.3" | ||
} | ||
} |