diff --git a/CHANGELOG.md b/CHANGELOG.md index 021e627..ce7b7d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,11 @@ # Change history for stripes-cli -## 3.3.0 IN PROGRESS +## 4.0.0 IN PROGRESS * Prune STS headers, permitting local non-SSL access via proxy. Refs STCLI-248. * Turn off `` when running tests. Refs STCLI-256. * Check for `main` branch in `stripes platform pull` command. Refs STCLI-258. +* **BREAKING** Correctly implment `transpile`. Refs STCLI-259. ## [3.2.0](https://github.com/folio-org/stripes-cli/tree/v3.2.0) (2024-10-09) [Full Changelog](https://github.com/folio-org/stripes-cli/compare/v3.1.0...v3.2.0) diff --git a/lib/commands/transpile-babel.config.json b/lib/commands/transpile-babel.config.json new file mode 100644 index 0000000..be8ef7a --- /dev/null +++ b/lib/commands/transpile-babel.config.json @@ -0,0 +1,22 @@ +{ + "presets": [ + ["@babel/preset-env", { + "targets": "> 0.25%, not dead", + "exclude": ["transform-dynamic-import"] + }], + ["@babel/preset-flow", { "all": true }], + ["@babel/preset-react", { "runtime": "automatic" }], + ["@babel/preset-typescript"] + ], + "plugins": [ + ["@babel/plugin-proposal-decorators", { "legacy": true }], + ["@babel/plugin-transform-class-properties", { "loose": true }], + ["@babel/plugin-transform-private-methods", { "loose": true }], + ["@babel/plugin-transform-private-property-in-object", { "loose": true }], + "@babel/plugin-transform-export-namespace-from", + "@babel/plugin-proposal-function-sent", + "@babel/plugin-transform-numeric-separator", + "@babel/plugin-proposal-throw-expressions", + "@babel/plugin-syntax-import-meta" + ] +} diff --git a/lib/commands/transpile.js b/lib/commands/transpile.js index 1c2b7db..9698b31 100644 --- a/lib/commands/transpile.js +++ b/lib/commands/transpile.js @@ -1,43 +1,43 @@ const importLazy = require('import-lazy')(require); +const path = require('node:path'); +const { spawn } = require('node:child_process'); const { contextMiddleware } = importLazy('../cli/context-middleware'); -const StripesCore = importLazy('../cli/stripes-core'); -const StripesPlatform = importLazy('../platform/stripes-platform'); -const { stripesConfigFile } = importLazy('./common-options'); -const { processError, processStats } = importLazy('../webpack-common'); - -let _stripesPlatform; -let _stripesCore; - -// stripesPlatform and stripesCore overrides primarily used as injection for unit tests -function stripesOverrides(stripesPlatform, stripesCore) { - _stripesPlatform = stripesPlatform; - _stripesCore = stripesCore; -} +/** + * transpile + * @param {object} argv arguments parsed by yargs + */ function transpileCommand(argv) { - const context = argv.context; // Default transpile command to production env if (!process.env.NODE_ENV) { process.env.NODE_ENV = 'production'; } - const platform = _stripesPlatform || new StripesPlatform(argv.stripesConfig, context, argv); - const webpackOverrides = []; - - if (argv.analyze) { - const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin; // eslint-disable-line - webpackOverrides.push((config) => { - config.plugins.push(new BundleAnalyzerPlugin()); - return config; - }); - } - console.info('Transpiling...'); - const stripes = _stripesCore || new StripesCore(context, platform.aliases); - stripes.api.transpile(Object.assign({}, argv, { webpackOverrides })) - .then(processStats) - .catch(processError); + + const transpile = spawn('babel', [ + argv.files, + '--ignore', `dist,node_modules,.storybook,karma.conf.js,jest.config.js,test,tests,${argv.files}/**/tests,${argv.files}/**/*.test.js`, + '-d', 'dist', // output directory + '-s', // include sourcemaps + '-D', // copy over non-compilable files + '--delete-dir-on-start', // clean + '--no-copy-ignored', // don't copy ignored files + '--config-file', `${__dirname}${path.sep}transpile-babel.config.json`, + ]); + + transpile.stdout.on('data', (data) => { + console.log(`${data}`); + }); + + transpile.stderr.on('data', (data) => { + console.error(`stderr: ${data}`); + }); + + // transpile.on('close', (code) => { + // console.log(`child process exited with code ${code}`); + // }); } module.exports = { @@ -48,13 +48,14 @@ module.exports = { .middleware([ contextMiddleware(), ]) - .positional('configFile', stripesConfigFile.configFile) - .option('analyze', { - describe: 'Run the Webpack Bundle Analyzer after build (launches in browser)', - type: 'boolean', - }) - .example('$0 transpile', 'Transpile a module'); + .example('$0 transpile --files ', 'Transpile files in '); + yargs.option('files', { + describe: 'Path to directory containing files to transpile', + type: 'string', + default: './src', + }); + + return yargs; }, handler: transpileCommand, - stripesOverrides, }; diff --git a/package.json b/package.json index 7e1285f..c6577aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@folio/stripes-cli", - "version": "3.3.0", + "version": "4.0.0", "description": "Stripes Command Line Interface", "repository": "https://github.com/folio-org/stripes-cli", "publishConfig": { @@ -22,8 +22,25 @@ "docs": "node ./lib/doc/generator" }, "dependencies": { + "@babel/cli": "^7.26.4", + "@babel/core": "^7.9.0", + "@babel/plugin-proposal-decorators": "^7.0.0", + "@babel/plugin-proposal-function-sent": "^7.0.0", + "@babel/plugin-proposal-throw-expressions": "^7.0.0", + "@babel/plugin-syntax-import-meta": "^7.0.0", + "@babel/plugin-transform-class-properties": "^7.0.0", + "@babel/plugin-transform-dynamic-import": "^7.25.9", + "@babel/plugin-transform-export-namespace-from": "^7.0.0", + "@babel/plugin-transform-numeric-separator": "^7.0.0", + "@babel/plugin-transform-private-methods": "^7.18.6", + "@babel/plugin-transform-private-property-in-object": "^7.21.0", + "@babel/preset-env": "^7.26.0", + "@babel/preset-flow": "^7.25.9", + "@babel/preset-react": "^7.26.3", + "@babel/preset-typescript": "^7.26.0", + "@babel/register": "^7.25.9", "@folio/stripes-testing": "^3.0.0", - "@folio/stripes-webpack": "^5.2.0", + "@folio/stripes-webpack": "^6.0.0", "@formatjs/cli": "^6.1.3", "@formatjs/cli-lib": "^6.1.3", "@octokit/rest": "^19.0.7",