mirror of
https://github.com/facebook/lexical.git
synced 2025-05-18 07:36:37 +08:00
62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
// @ts-check
|
|
'use strict';
|
|
|
|
const fs = require('fs-extra');
|
|
const path = require('node:path');
|
|
const {packagesManager} = require('./shared/packagesManager');
|
|
const npmToWwwName = require('./www/npmToWwwName');
|
|
|
|
const headerTemplate = fs.readFileSync(
|
|
path.resolve(__dirname, 'www', 'headerTemplate.js'),
|
|
'utf8',
|
|
);
|
|
|
|
/** @param {string} filename */
|
|
function wwwStubTemplate(filename) {
|
|
return `
|
|
${headerTemplate}
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
module.exports = require('./dist/${filename}');
|
|
`;
|
|
}
|
|
|
|
function updateWwwStubs() {
|
|
packagesManager.getPublicPackages().forEach((pkg) => {
|
|
const npmName = pkg.getNpmName();
|
|
// Only worry about the entrypoint stub if it has a single module export
|
|
if (pkg.getExportedNpmModuleNames().some((name) => name !== npmName)) {
|
|
return;
|
|
}
|
|
|
|
const filename = `${npmToWwwName(npmName)}.js`;
|
|
const stubPath = pkg.resolve(filename);
|
|
const root = pkg.resolve('..', '..');
|
|
|
|
if (!fs.existsSync(stubPath)) {
|
|
console.log(`Creating ${path.relative(root, stubPath)}`);
|
|
fs.writeFileSync(stubPath, wwwStubTemplate(filename));
|
|
}
|
|
});
|
|
}
|
|
|
|
updateWwwStubs();
|