-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate deprecations list from language repo (#300)
- Loading branch information
Showing
5 changed files
with
101 additions
and
145 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
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,24 @@ | ||
// Copyright 2024 Google LLC. Use of this source code is governed by an | ||
// MIT-style license that can be found in the LICENSE file or at | ||
// https://opensource.org/licenses/MIT. | ||
|
||
import * as api from './vendor/sass'; | ||
|
||
export class Version implements api.Version { | ||
constructor( | ||
readonly major: number, | ||
readonly minor: number, | ||
readonly patch: number | ||
) {} | ||
static parse(version: string): Version { | ||
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/); | ||
if (match === null) { | ||
throw new Error(`Invalid version ${version}`); | ||
} | ||
return new Version( | ||
parseInt(match[1]), | ||
parseInt(match[2]), | ||
parseInt(match[3]) | ||
); | ||
} | ||
} |
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,67 @@ | ||
// Generates the list of deprecations from spec/deprecations.yaml in the | ||
// language repo. | ||
|
||
import * as fs from 'fs'; | ||
import {parse} from 'yaml'; | ||
|
||
interface YamlData { | ||
[key: string]: { | ||
description: string; | ||
'dart-sass': { | ||
status: 'active' | 'future' | 'obsolete'; | ||
deprecated?: string; | ||
obsolete?: string; | ||
}; | ||
}; | ||
} | ||
|
||
const yamlFile = 'build/sass/spec/deprecations.yaml'; | ||
|
||
/** | ||
* Converts a version string in the form X.Y.Z to be code calling the Version | ||
* constructor, or null if the string is undefined. | ||
*/ | ||
function toVersionCode(version: string | undefined): string { | ||
if (!version) return 'null'; | ||
const match = version.match(/^(\d+)\.(\d+)\.(\d+)$/); | ||
if (match === null) { | ||
throw new Error(`Invalid version ${version}`); | ||
} | ||
return `new Version(${match[1]}, ${match[2]}, ${match[3]})`; | ||
} | ||
|
||
/** | ||
* Generates the list of deprecations based on the YAML file in the language | ||
* repo. | ||
*/ | ||
export async function getDeprecations(outDirectory: string) { | ||
const yamlText = fs.readFileSync(yamlFile, 'utf8'); | ||
|
||
const deprecations = parse(yamlText) as YamlData; | ||
let tsText = | ||
"import {Deprecations} from './sass';\n" + | ||
"import {Version} from '../version';\n\n" + | ||
'export const deprecations: Deprecations = {\n'; | ||
for (const [id, deprecation] of Object.entries(deprecations)) { | ||
const key = id.includes('-') ? `'${id}'` : id; | ||
const dartSass = deprecation['dart-sass']; | ||
tsText += | ||
` ${key}: {\n` + | ||
` id: '${id}',\n` + | ||
` description: '${deprecation.description}',\n` + | ||
` status: '${dartSass.status}',\n` + | ||
` deprecatedIn: ${toVersionCode(dartSass.deprecated)},\n` + | ||
` obsoleteIn: ${toVersionCode(dartSass.obsolete)},\n` + | ||
' },\n'; | ||
} | ||
tsText += | ||
" 'user-authored': {\n" + | ||
" id: 'user-authored',\n" + | ||
" status: 'user',\n" + | ||
' deprecatedIn: null,\n' + | ||
' obsoleteIn: null,\n' + | ||
' },\n' + | ||
'}\n'; | ||
|
||
fs.writeFileSync(`${outDirectory}/deprecations.ts`, tsText); | ||
} |
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