remove old build files
This commit is contained in:
@@ -1,73 +0,0 @@
|
||||
import * as fs from 'fs';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
const libsDistFolder = '../Umbraco.Cms.StaticAssets/wwwroot/umbraco/backoffice/libs';
|
||||
const typesDistFolder = '../Umbraco.Web.UI.New/dts';
|
||||
const libs = fs.readdirSync('./libs');
|
||||
|
||||
for (let i = 0; i < libs.length; i++) {
|
||||
const lib = libs[i];
|
||||
const libFolder = './libs/' + lib;
|
||||
if (fs.statSync(libFolder).isDirectory()) {
|
||||
const libPackage = libFolder + '/rollup.config.js';
|
||||
if (!fs.existsSync(libPackage)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log('Installing ' + lib + '...');
|
||||
exec('npx rollup -c rollup.config.js', { cwd: libFolder }, function (error) {
|
||||
if (error) {
|
||||
console.error('Error installing ' + lib + '!');
|
||||
console.error(error);
|
||||
} else {
|
||||
console.log('Installed ' + lib + '.');
|
||||
|
||||
copyDistFromLib(lib, `${libFolder}/dist`);
|
||||
findAndCopyTypesForLib(lib);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function copyDistFromLib(libName, distPath) {
|
||||
console.log(`Copying ${libName} to StaticAssets`);
|
||||
|
||||
const destPath = `${libsDistFolder}/${libName}`;
|
||||
|
||||
try {
|
||||
fs.readdirSync(distPath).forEach(file => fs.cpSync(`${distPath}/${file}`, `${destPath}/${file}`, { recursive: true }));
|
||||
console.log(`Copied ${libName}`);
|
||||
} catch (err) {
|
||||
console.error(`Error copying ${libName}`);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function copies the content of the index.d.ts file from the lib into
|
||||
* the ${typesDistFolder}/global.d.ts file and wrap it with
|
||||
* a declare module statement using the lib name.
|
||||
*/
|
||||
function findAndCopyTypesForLib(libName) {
|
||||
console.log(`Copying ${libName} types to ${typesDistFolder}`);
|
||||
|
||||
const sourceFile = `${libsDistFolder}/${libName}/index.d.ts`;
|
||||
const destPath = `${typesDistFolder}/${libName}/index.d.ts`;
|
||||
|
||||
try {
|
||||
fs.cpSync(sourceFile, destPath, { recursive: true });
|
||||
const content = fs.readFileSync(destPath, 'utf-8');
|
||||
fs.writeFileSync(destPath, wrapLibTypeContent(libName, content));
|
||||
console.log(`Copied ${libName} types`);
|
||||
} catch (err) {
|
||||
console.error(`Error copying ${libName} types`);
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
function wrapLibTypeContent(libName, content) {
|
||||
return `declare module "@umbraco-cms/${libName}" {
|
||||
${content.replace(/declare/g, '')}
|
||||
}
|
||||
`;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
// Load all .d.ts files from the dist/libs folder
|
||||
// and replace all imports from @umbraco-cms/backoffice with relative imports
|
||||
// Example: import { Foo } from '@umbraco-cms/backoffice/element-api' -> import { Foo } from './element'
|
||||
// This is needed because the d.ts files are not in the same folder as the source files
|
||||
// and the absolute paths are not valid when the d.ts files are copied to the dist folder
|
||||
// This is only used when building the d.ts files.
|
||||
//
|
||||
// This script also copies the package.json and README.md files to the dist/libs folder
|
||||
// and the umbraco-package-schema.json file to the Umbraco.Web.UI.New folder
|
||||
//
|
||||
// Usage: node utils/move-libs.js
|
||||
|
||||
import { readdirSync, readFileSync, writeFileSync, cpSync, mkdirSync } from 'fs';
|
||||
|
||||
const srcDir = './libs';
|
||||
const inputDir = './dist/libs';
|
||||
const outputDir = '../Umbraco.Cms.StaticAssets/wwwroot/umbraco/backoffice/libs';
|
||||
const executableDir = '../Umbraco.Web.UI.New';
|
||||
|
||||
// Copy package files
|
||||
cpSync(`${srcDir}/package.json`, `${inputDir}/package.json`, { recursive: true });
|
||||
console.log(`Copied ${srcDir}/package.json to ${inputDir}/package.json`);
|
||||
cpSync(`${srcDir}/README.md`, `${inputDir}/README.md`, { recursive: true });
|
||||
console.log(`Copied ${srcDir}/README.md to ${inputDir}/README.md`);
|
||||
cpSync(`${inputDir}/umbraco-package-schema.json`, `${executableDir}/umbraco-package-schema.json`, { recursive: true });
|
||||
console.log(`Copied ${inputDir}/umbraco-package-schema.json to ${executableDir}/umbraco-package-schema.json`);
|
||||
|
||||
const libs = readdirSync(inputDir);
|
||||
|
||||
// Create output folder
|
||||
try {
|
||||
mkdirSync(outputDir, { recursive: true });
|
||||
} catch {
|
||||
// Ignore
|
||||
}
|
||||
|
||||
// Transform all .d.ts files and copy all other files to the output folder
|
||||
libs.forEach((lib) => {
|
||||
if (lib.endsWith('.js') === false && lib.endsWith('.js.map') === false) return;
|
||||
|
||||
console.log(`Transforming ${lib}`);
|
||||
|
||||
const dtsFile = `${inputDir}/${lib}`;
|
||||
|
||||
let code = readFileSync(dtsFile, 'utf8');
|
||||
|
||||
// Replace all absolute imports with relative imports
|
||||
if (lib.endsWith('.d.ts')) {
|
||||
code = code.replace(/from '(@umbraco-cms\/backoffice\/[^']+)'/g, (match, p1) => {
|
||||
return `from './${p1.split('/').pop()}'`;
|
||||
});
|
||||
}
|
||||
|
||||
writeFileSync(dtsFile, code, 'utf8');
|
||||
|
||||
cpSync(dtsFile, `${outputDir}/${lib}`, { recursive: true });
|
||||
});
|
||||
Reference in New Issue
Block a user