@nxext/stencil
Version:
Nx plugin for stenciljs
95 lines • 3.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareConfigAndOutputargetPaths = prepareConfigAndOutputargetPaths;
const tslib_1 = require("tslib");
const e2e_testing_1 = require("./e2e-testing");
const fileutils_1 = require("@nx/workspace/src/utilities/fileutils");
const devkit_1 = require("@nx/devkit");
const fs_1 = require("fs");
function copyOrCreatePackageJson(pathCollection) {
const libPackageJson = {
name: pathCollection.projectName,
version: '0.0.0',
main: './dist/index.cjs.js',
module: './dist/index.js',
es2015: './dist/esm/index.mjs',
es2017: './dist/esm/index.mjs',
types: './dist/types/index.d.ts',
collection: './dist/collection/collection-manifest.json',
'collection:main': './dist/collection/index.js',
unpkg: `./dist/${pathCollection.projectName}/${pathCollection.projectName}.js`,
files: ['dist/', 'loader/'],
};
if ((0, fileutils_1.fileExists)(pathCollection.pkgJson)) {
if (pathCollection.projectRoot !== pathCollection.distDir) {
(0, fileutils_1.copyFile)(pathCollection.pkgJson, pathCollection.distDir);
}
}
else {
(0, devkit_1.writeJsonFile)((0, devkit_1.joinPathFragments)(pathCollection.distDir, 'package.json'), libPackageJson);
}
}
function calculateOutputTargetPathVariables(config, pathCollection, pathVariables) {
return config.outputTargets.map((outputTarget) => {
// don't change the angular, react, vue or svelte output targets
if (outputTarget.type === 'custom') {
return outputTarget;
}
pathVariables.forEach((pathVar) => {
if (outputTarget[pathVar] != null &&
!outputTarget[pathVar].endsWith('src')) {
const origPath = outputTarget[pathVar];
outputTarget = Object.assign(outputTarget, {
[pathVar]: origPath.replace(pathCollection.projectRoot, pathCollection.distDir),
});
}
});
return outputTarget;
});
}
function prepareDistDirAndPkgJson(pathCollection) {
if (!(0, fs_1.existsSync)(pathCollection.distDir)) {
(0, fileutils_1.createDirectory)(pathCollection.distDir);
}
copyOrCreatePackageJson(pathCollection);
}
function prepareConfigAndOutputargetPaths(config, pathCollection) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
prepareDistDirAndPkgJson(pathCollection);
if (config.flags.e2e) {
(0, e2e_testing_1.prepareE2eTesting)(pathCollection);
}
const pathVariables = [
'dir',
'appDir',
'buildDir',
'indexHtml',
'esmDir',
'systemDir',
'systemLoaderFile',
'file',
'esmLoaderPath',
'collectionDir',
'typesDir',
'legacyLoaderFile',
'esmEs5Dir',
'cjsDir',
'cjsIndexFile',
'esmIndexFile',
'componentDts',
];
const outputTargets = calculateOutputTargetPathVariables(config, pathCollection, pathVariables);
const devServerConfig = Object.assign(config.devServer, {
root: config.devServer.root.replace(pathCollection.projectRoot, pathCollection.distDir),
openBrowser: config.flags.open,
});
if (!config.flags.e2e) {
config.packageJsonFilePath = config.packageJsonFilePath.replace(pathCollection.projectRoot, pathCollection.distDir);
}
else {
config.packageJsonFilePath = config.packageJsonFilePath.replace('package.json', 'package.e2e.json');
}
return Object.assign(Object.assign({}, config), { outputTargets: outputTargets, devServer: devServerConfig });
});
}
//# sourceMappingURL=prepare-config-and-outputarget-paths.js.map