| |
| |
| |
| |
|
|
| import * as child_process from 'child_process' |
| import * as nodefs from 'fs' |
| import { marked } from 'marked' |
| import * as path from 'path' |
|
|
| |
| const projectRoot = process.cwd() |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| function translateReadmeToHtml( |
| root: string, |
| inputFile: string, |
| outputFile: string, |
| throwIfNotExists: boolean, |
| cn: boolean = false |
| ) { |
| const inputPath = path.join(root, inputFile) |
| if (!nodefs.existsSync(inputPath)) { |
| if (throwIfNotExists) { |
| throw Error(`File ${inputFile} was not found, but it is required.`) |
| } |
| console.log(`File ${inputFile} was not found, skipping transformation...`) |
| return |
| } |
| const fileText = nodefs.readFileSync(path.join(root, inputFile)).toString() |
| const relativePathRegex = /]\(\.\//g |
| let transformedText = fileText.replace(relativePathRegex, '](!!EXTENSIONROOT!!/') |
| if (cn) { |
| transformedText = transformedText.replace(/AWS/g, 'Amazon').replace(/-en.png/g, '-cn.png') |
| } |
|
|
| const r = marked.parse(transformedText, { async: false }) |
| if (typeof r !== 'string') { |
| throw Error() |
| } |
| nodefs.writeFileSync(path.join(root, outputFile), r) |
| } |
|
|
| |
| |
| |
| function generateFileHash(root: string) { |
| try { |
| const response = child_process.execSync('git rev-parse HEAD') |
| nodefs.mkdirSync(root, { recursive: true }) |
| nodefs.writeFileSync(path.join(root, '.gitcommit'), response) |
| } catch (e) { |
| console.log(`Getting commit hash failed ${e}`) |
| } |
| } |
|
|
| try { |
| translateReadmeToHtml(projectRoot, 'README.md', 'quickStartVscode.html', true) |
| generateFileHash(projectRoot) |
| } catch (error) { |
| console.error(error) |
| process.exit(100) |
| } |
|
|