Skip to content

Commit

Permalink
Add wonder-stuff-i18n package. (#216)
Browse files Browse the repository at this point in the history
## Summary:
This moves the i18n logic out of Webapp and into Wonder Stuff so that it can be more-easily shared.

In the process I converted the code to use ES6 imports/exports and also use Flow types.

I had to add some logic to our build-settings so that we can generate bin scripts (since this is the first package to have them).

Issue: FEI-4434

## Test plan:
I confirmed the bin scripts worked by making a simple test file and then running `yarn build` in the root and then the following in `packages/wonder-blocks-i18n`:

```
packages/wonder-stuff-i18n (i18n-pkg) > ./dist/bin/gen-potfile.js foo.js
msgid ""
msgstr ""

#: foo.js:1
msgid "Test String"
msgstr ""

#: foo.js:3
#, python-format
msgid "Singular %(num)s"
msgid_plural "Plural %(num)s"
msgstr[0] ""
msgstr[1] ""

packages/wonder-stuff-i18n (i18n-pkg) > ./dist/bin/all-i18n-strings.js foo.js
Test String
Singular %(num)s (plural: Plural %(num)s)
```

Author: jeresig

Reviewers: kevinbarabash, jeresig

Required Reviewers: 

Approved By: kevinbarabash

Checks: ✅ Test (macOS-latest, 16.x), ✅ Test (macOS-latest, 12.x), ✅ Test (ubuntu-latest, 12.x), ✅ codecov/project, ✅ CodeQL, ✅ Lint, flow, and coverage check (ubuntu-latest, 16.x), ✅ gerald, ✅ Analyze (javascript), ✅ Prime node_modules cache for primary configuration (ubuntu-latest, 16.x), ⏭  dependabot

Pull Request URL: #216
  • Loading branch information
jeresig authored Apr 14, 2022
1 parent b999ba4 commit f6494c0
Show file tree
Hide file tree
Showing 27 changed files with 5,473 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .changeset/large-papayas-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@khanacademy/wonder-stuff-i18n": major
"ws-dev-build-settings": patch
---

Add wonder-stuff-i18n package.
6 changes: 6 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ module.exports = {
"max-lines": "off",
},
},
{
files: ["**/bin/**/*.js"],
rules: {
"no-console": "off",
},
},
],
rules: {
"new-cap": "off",
Expand Down
24 changes: 22 additions & 2 deletions build-settings/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import copy from "rollup-plugin-copy";
import resolve from "@rollup/plugin-node-resolve";
import replace from "@rollup/plugin-replace";
import filesize from "rollup-plugin-filesize";
import {preserveShebangs} from "rollup-plugin-preserve-shebangs";
import rollupExecutable from "rollup-plugin-executable-output";

const createBabelPresets = require("./create-babel-presets.js");
const createBabelPlugins = require("./create-babel-plugins.js");
Expand Down Expand Up @@ -86,7 +88,7 @@ const getFormats = ({configFormats}) =>
*/
const createConfig = (
commandLineArgs,
{name, format, platform, file, plugins},
{name, format, platform, inputFile, file, plugins},
) => {
const valueReplacementMappings = {
__IS_BROWSER__: platform === "browser",
Expand All @@ -103,7 +105,7 @@ const createConfig = (

const config = {
output: createOutputConfig(name, format, file),
input: makePackageBasedPath(name, "./src/index.js"),
input: makePackageBasedPath(name, inputFile || "./src/index.js"),
plugins: [
// We don't want to do process.env.NODE_ENV checks in our main
// builds. Our consumers should handle that. However, if we
Expand Down Expand Up @@ -235,6 +237,24 @@ const getPackageInfo = (commandLineArgs, pkgName) => {
});
}
}

// Figure out if there are any scripts that we need to generate.
const binsPath = makePackageBasedPath(pkgName, "./src/bin");
if (fs.existsSync(binsPath)) {
const binFiles = fs.readdirSync(binsPath);

for (const binFile of binFiles) {
configs.push({
name: pkgName,
format: "cjs",
platform: "node",
file: `dist/bin/${binFile}`,
inputFile: `./src/bin/${binFile}`,
plugins: [preserveShebangs(), rollupExecutable()],
});
}
}

return configs;
};

Expand Down
35 changes: 35 additions & 0 deletions flow-typed/npm/ancesdir_vx.x.x.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// flow-typed signature: 02e095fc2135e742ae3a993ce37b6294
// flow-typed version: <<STUB>>/ancesdir_v1.1.0/flow_v0.176.0

/**
* This is an autogenerated libdef stub for:
*
* 'ancesdir'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/

declare module 'ancesdir' {
declare module.exports: any;
}

/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'ancesdir/dist' {
declare module.exports: any;
}

// Filename aliases
declare module 'ancesdir/dist/index' {
declare module.exports: $Exports<'ancesdir/dist'>;
}
declare module 'ancesdir/dist/index.js' {
declare module.exports: $Exports<'ancesdir/dist'>;
}
Loading

0 comments on commit f6494c0

Please sign in to comment.