Skip to content

Commit

Permalink
Add a test case for the loc typings generator plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
iclanton committed Aug 21, 2024
1 parent 1040328 commit a9747a4
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 94 deletions.
21 changes: 0 additions & 21 deletions build-tests/localization-plugin-test-02/build.js

This file was deleted.

42 changes: 42 additions & 0 deletions build-tests/localization-plugin-test-02/config/heft.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Defines configuration used by core Heft.
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/heft.schema.json",

// TODO: Add comments
"phasesByName": {
"build": {
"cleanFiles": [{ "includeGlobs": ["dist", "lib", "lib-commonjs"] }],

"tasksByName": {
"loc-typings": {
"taskPlugin": {
"pluginPackage": "@rushstack/heft-localization-typings-plugin",
"options": {
"generatedTsFolder": "temp/loc-json-ts"
}
}
},
"typescript": {
"taskDependencies": ["loc-typings"],
"taskPlugin": {
"pluginPackage": "@rushstack/heft-typescript-plugin"
}
},
"lint": {
"taskDependencies": ["typescript"],
"taskPlugin": {
"pluginPackage": "@rushstack/heft-lint-plugin"
}
},
"webpack": {
"taskDependencies": ["typescript"],
"taskPlugin": {
"pluginPackage": "@rushstack/heft-webpack4-plugin"
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"operationSettings": [
{
"operationName": "_phase:build",
"outputFolderNames": ["lib", "dist"]
"outputFolderNames": ["lib", "dist-dev", "dist-prod"]
}
]
}
10 changes: 10 additions & 0 deletions build-tests/localization-plugin-test-02/config/typescript.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* Configures the TypeScript plugin for Heft. This plugin also manages linting.
*/
{
"$schema": "https://developer.microsoft.com/json-schemas/heft/v0/typescript.schema.json",

"staticAssetsToCopy": {
"fileExtensions": [".resx", ".json", ".resjson"]
}
}
16 changes: 10 additions & 6 deletions build-tests/localization-plugin-test-02/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "node build.js",
"serve": "node serve.js",
"_phase:build": "node build.js"
"build": "heft build --clean",
"start": "heft start",
"_phase:build": "heft run --only build -- --clean"
},
"dependencies": {
"@rushstack/webpack4-localization-plugin": "workspace:*",
"@rushstack/webpack4-module-minifier-plugin": "workspace:*",
"@rushstack/heft-lint-plugin": "workspace:*",
"@rushstack/heft-localization-typings-plugin": "workspace:*",
"@rushstack/heft-typescript-plugin": "workspace:*",
"@rushstack/heft-webpack4-plugin": "workspace:*",
"@rushstack/heft": "workspace:*",
"@rushstack/node-core-library": "workspace:*",
"@rushstack/set-webpack-public-path-plugin": "^4.1.16",
"@rushstack/webpack4-localization-plugin": "workspace:*",
"@rushstack/webpack4-module-minifier-plugin": "workspace:*",
"@types/lodash": "4.14.116",
"@types/webpack-env": "1.18.0",
"html-webpack-plugin": "~4.5.2",
"lodash": "~4.17.15",
"ts-loader": "6.0.0",
"typescript": "~5.4.2",
"webpack-bundle-analyzer": "~4.5.0",
"webpack-cli": "~3.3.2",
Expand Down
18 changes: 0 additions & 18 deletions build-tests/localization-plugin-test-02/serve.js

This file was deleted.

2 changes: 1 addition & 1 deletion build-tests/localization-plugin-test-02/src/indexA.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { string1 } from './strings1.loc.json';
import * as strings3 from './strings3.loc.json';
import * as strings3 from './strings3.resjson';
import * as strings5 from './strings5.resx';

console.log(string1);
Expand Down
2 changes: 1 addition & 1 deletion build-tests/localization-plugin-test-02/src/indexB.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { string1, string2 } from './strings3.loc.json';
import { string1, string2 } from './strings3.resjson';
const strings4: string = require('./strings4.loc.json');

console.log(string1);
Expand Down
14 changes: 0 additions & 14 deletions build-tests/localization-plugin-test-02/src/strings3.loc.json

This file was deleted.

10 changes: 10 additions & 0 deletions build-tests/localization-plugin-test-02/src/strings3.resjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"string1": "string three with a \\ backslash",
"_string1.comment": "the third string",

"string2": "string four with an ' apostrophe",
"_string2.comment": "the fourth string",

"string3": "UNUSED STRING",
"_string3.comment": "UNUSED STRING"
}
36 changes: 7 additions & 29 deletions build-tests/localization-plugin-test-02/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,13 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
function generateConfiguration(mode, outputFolderName) {
return {
mode: mode,
module: {
rules: [
{
test: /\.tsx?$/,
loader: require.resolve('ts-loader'),
exclude: /(node_modules)/,
options: {
compiler: require.resolve('typescript'),
logLevel: 'ERROR',
configFile: path.resolve(__dirname, 'tsconfig.json')
}
}
]
},
resolve: {
extensions: ['.js', '.jsx', '.json', '.ts', '.tsx']
},
entry: {
'localization-test-A': path.join(__dirname, 'src', 'indexA.ts'),
'localization-test-B': path.join(__dirname, 'src', 'indexB.ts'),
'localization-test-C': path.join(__dirname, 'src', 'indexC.ts')
'localization-test-A': `${__dirname}/lib/indexA.js`,
'localization-test-B': `${__dirname}/lib/indexB.js`,
'localization-test-C': `${__dirname}/lib/indexC.js`
},
output: {
path: path.join(__dirname, outputFolderName),
path: `${__dirname}/${outputFolderName}`,
filename: '[name]_[locale]_[contenthash].js',
chunkFilename: '[id].[name]_[locale]_[contenthash].js'
},
Expand Down Expand Up @@ -84,22 +67,17 @@ function generateConfiguration(mode, outputFolderName) {
normalizeResxNewlines: 'crlf',
ignoreMissingResxComments: true
},
typingsOptions: {
generatedTsFolder: path.resolve(__dirname, 'temp', 'loc-json-ts'),
sourceRoot: path.resolve(__dirname, 'src'),
processComment: (comment) => (comment ? `${comment} (processed)` : comment)
},
localizationStats: {
dropPath: path.resolve(__dirname, 'temp', 'localization-stats.json')
dropPath: `${__dirname}/temp/localization-stats.json`
},
ignoreString: (filePath, stringName) => stringName === '__IGNORED_STRING__'
}),
new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerMode: 'static',
reportFilename: path.resolve(__dirname, 'temp', 'stats.html'),
reportFilename: `${__dirname}/temp/stats.html`,
generateStatsFile: true,
statsFilename: path.resolve(__dirname, 'temp', 'stats.json'),
statsFilename: `${__dirname}/temp/stats.json`,
logLevel: 'error'
}),
new SetPublicPathPlugin({
Expand Down
4 changes: 4 additions & 0 deletions common/config/rush/nonbrowser-approved-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@
"name": "@rushstack/heft-lint-plugin",
"allowedCategories": [ "libraries", "tests" ]
},
{
"name": "@rushstack/heft-localization-typings-plugin",
"allowedCategories": [ "tests" ]
},
{
"name": "@rushstack/heft-node-rig",
"allowedCategories": [ "libraries", "tests", "vscode-extensions" ]
Expand Down
18 changes: 15 additions & 3 deletions common/config/subspaces/default/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a9747a4

Please sign in to comment.