SAP / ui5-typescript

Tooling to enable TypeScript support in SAPUI5/OpenUI5 projects
https://sap.github.io/ui5-typescript
Apache License 2.0
201 stars 28 forks source link

feat(dts-generator): add download-apijson API and CLI #454

Closed akudev closed 4 months ago

akudev commented 4 months ago

This change consists of these major areas:

  1. Moving the implementation in ui5-metadata.js from the test to dts-generator and converting it to an ES module (plus moving dependencies)
    • the directory preparation has been written anew to prevent accidental deletion of user directory content, which can happen with the old approach which was meant for hardcoded safe paths
  2. Changing the usage of the utils in the test to the moved ones
  3. Creating a new CLI in download-apijson.ts, which is similar like the still existing download script in the test package, but with reduced scope, as no directives are needed (the UI5 libraries do not need to be built, we can get api.json and resulting d.ts files directly)
  4. Defining the CLI arguments and docu in arguments-download-apijson.ts
  5. Lots of documentation extension and adaptation for the new API/CLI
  6. Renaming the downloaded api.json files (also renames the test content) for clearer file names
    • sap.ui.core.designtime.api.json -> sap.ui.core.api.json
  7. Declaring another binary and explicitly naming the existing one - twice

Regarding the binary: Formerly it was not named, so the package name was supposedly the binary name(??). But in fact, the "@ui5" prefix was ignored when the symlink was created. So unintentionally, the binary is simply "dts-generator". Hence the new main binary is named explicitly "ui5-dts-generator" and the new util: "ui5-download-apijson". The old "@ui5/dts-generator" is added for compatibility. Not 100% sure about that.

"bin": {
    "@ui5/dts-generator": "dist/index.js",
    "ui5-dts-generator": "dist/index.js",
    "ui5-download-apijson": "dist/download-apijson.js"
  },
akudev commented 4 months ago

@petermuessig Now I remember why I wrote the imports like I did:


import { writeFile } from "fs-extra";
               ^^^^^^^^^
      SyntaxError: Named export 'writeFile' not found. The requested module 'fs-extra' is a CommonJS module, which may not support all module.exports as named exports.
      CommonJS modules can always be imported via the default export, for example using:

      import pkg from 'fs-extra';
      const { writeFile } = pkg;
akudev commented 4 months ago

I just re-checked: even though "@ui5/dts-generator": "dist/index.js", in the binaries section of package.json gives a warning and the binary (symlink in .bin) is not named like this, only with this entry, users can continue to write npx @ui5/dts-generator, hence I leave it in.