nx/packages/vue/src/generators/library/lib/create-library-files.ts
Jack Hsu a8de7df0e0
feat(js): update vue/node app and lib generators to support TS solutions (#29299)
<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #

---------

Co-authored-by: Leosvel Pérez Espinosa <leosvel.perez.espinosa@gmail.com>
2024-12-12 15:43:14 -05:00

69 lines
1.5 KiB
TypeScript

import type { Tree } from '@nx/devkit';
import {
generateFiles,
joinPathFragments,
names,
offsetFromRoot,
toJS,
writeJson,
} from '@nx/devkit';
import { getRelativePathToRootTsConfig } from '@nx/js';
import { NormalizedSchema } from '../schema';
import { createTsConfig } from '../../../utils/create-ts-config';
export function createLibraryFiles(host: Tree, options: NormalizedSchema) {
const relativePathToRootTsConfig = getRelativePathToRootTsConfig(
host,
options.projectRoot
);
const substitutions = {
...options,
...names(options.name),
tmpl: '',
offsetFromRoot: offsetFromRoot(options.projectRoot),
fileName: options.fileName,
};
generateFiles(
host,
joinPathFragments(__dirname, '../files'),
options.projectRoot,
substitutions
);
if (
!options.isUsingTsSolutionConfig &&
(options.publishable || options.bundler !== 'none')
) {
writeJson(host, joinPathFragments(options.projectRoot, 'package.json'), {
name: options.name,
version: '0.0.1',
main: './index.js',
types: './index.d.ts',
exports: {
'.': {
import: './index.mjs',
require: './index.js',
types: './index.d.ts',
},
},
});
}
if (options.unitTestRunner !== 'vitest') {
host.delete(`${options.projectRoot}/tsconfig.spec.json`);
}
if (options.js) {
toJS(host);
}
createTsConfig(
host,
options.projectRoot,
'lib',
options,
relativePathToRootTsConfig
);
}