-
Notifications
You must be signed in to change notification settings - Fork 29
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
9 changed files
with
312 additions
and
297 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
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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import path from 'node:path'; | ||
import fs from 'node:fs/promises'; | ||
import phpfmt from 'phpfmt'; | ||
import { dirname } from 'dirname-filename-esm'; | ||
|
||
const __dirname = dirname(import.meta); | ||
|
||
try { | ||
const pkgPath = path.join(__dirname, '..'); | ||
const distPath = path.join(pkgPath, 'dist'); | ||
const destPath = path.join(distPath, phpfmt.v2.pharName); | ||
const pharContent = await fs.readFile(phpfmt.v2.pharPath); | ||
await fs.writeFile(destPath, pharContent); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} |
This file was deleted.
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 |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import path from 'node:path'; | ||
import os from 'node:os'; | ||
import fs from 'node:fs/promises'; | ||
import phpfmt from 'phpfmt'; | ||
import { dirname } from 'dirname-filename-esm'; | ||
|
||
const __dirname = dirname(import.meta); | ||
|
||
const pkgJsonPath = path.join(__dirname, '../package.json'); | ||
const readmePath: string = path.join(__dirname, '../README.md'); | ||
|
||
try { | ||
const pkg = JSON.parse(String(await fs.readFile(pkgJsonPath))); | ||
const configuration = pkg.contributes.configuration; | ||
|
||
let config: string = | ||
'| Key | Type | Description | Default |' + | ||
os.EOL + | ||
'| -------- | ----------- | ----------- | ----------- |' + | ||
os.EOL; | ||
|
||
for (const configKey of Object.keys(configuration.properties)) { | ||
const configValue = configuration.properties[configKey]; | ||
config += `| ${configKey} | `; | ||
|
||
if (typeof configValue.type === 'string') { | ||
config += `\`${configValue.type}\``; | ||
} else if (Array.isArray(configValue.type)) { | ||
config += `\`${configValue.type.join(' \\| ')}\``; | ||
} | ||
config += ` | ${configValue.description}`; | ||
|
||
if (typeof configValue.default === 'string') { | ||
config += ` | "${configValue.default}"`; | ||
} else if (typeof configValue.default === 'number') { | ||
config += ` | ${configValue.default}`; | ||
} else if ( | ||
Array.isArray(configValue.default) || | ||
typeof configValue.default === 'boolean' | ||
) { | ||
config += ` | ${JSON.stringify(configValue.default)}`; | ||
} else { | ||
throw new Error('uncovered type'); | ||
} | ||
|
||
config += ' | ' + os.EOL; | ||
} | ||
|
||
let readmeContent = String(await fs.readFile(readmePath)); | ||
readmeContent = readmeContent.replace( | ||
/<!-- Configuration START -->([\s\S]*)<!-- Configuration END -->/, | ||
() => { | ||
return ( | ||
'<!-- Configuration START -->' + | ||
os.EOL + | ||
config + | ||
os.EOL + | ||
'<!-- Configuration END -->' | ||
); | ||
} | ||
); | ||
|
||
const { Transformation } = await import('../src/Transformation'); | ||
const transformation = new Transformation('php', phpfmt.v2); | ||
|
||
const transformations = await transformation.getTransformations(); | ||
|
||
readmeContent = readmeContent.replace( | ||
/<!-- Transformations START -->([\s\S]*)<!-- Transformations END -->/, | ||
() => { | ||
return ( | ||
'<!-- Transformations START -->' + | ||
os.EOL + | ||
'| Key | Description |' + | ||
os.EOL + | ||
'| -------- | ----------- |' + | ||
os.EOL + | ||
transformations | ||
.map(item => { | ||
let row = `| ${item.key} | `; | ||
row += item.description; | ||
row += ' |'; | ||
return row; | ||
}) | ||
.join(os.EOL) + | ||
os.EOL + | ||
'<!-- Transformations END -->' | ||
); | ||
} | ||
); | ||
const passes = transformation.getPasses(); | ||
|
||
const enums = passes.map(pass => { | ||
const p = transformations.find(t => t.key === pass); | ||
return { | ||
enum: pass, | ||
description: p?.description ?? 'Core pass' | ||
}; | ||
}); | ||
|
||
pkg.contributes.configuration.properties['phpfmt.passes'].items.enum = | ||
enums.map(o => o.enum); | ||
pkg.contributes.configuration.properties[ | ||
'phpfmt.passes' | ||
].items.enumDescriptions = enums.map(o => o.description); | ||
pkg.contributes.configuration.properties['phpfmt.exclude'].items.enum = | ||
enums.map(o => o.enum); | ||
pkg.contributes.configuration.properties[ | ||
'phpfmt.exclude' | ||
].items.enumDescriptions = enums.map(o => o.description); | ||
|
||
await fs.writeFile(readmePath, readmeContent); | ||
await fs.writeFile(pkgJsonPath, JSON.stringify(pkg, null, 2) + os.EOL); | ||
} catch (err) { | ||
console.error(err); | ||
process.exit(1); | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.