refactor: use American English
This commit is contained in:
parent
bfd08357a2
commit
3c7d318f06
12
README.md
12
README.md
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
🏄🏻 _A collection of opinionated configurations for a building a code bundle via rollup for presetter_
|
🏄🏻 _A collection of opinionated configurations for a building a code bundle via rollup for presetter_
|
||||||
|
|
||||||
• [Quick Start](#quick-start) • [Project Structure](#project-structure) • [Customisation](#customisation) • [Scripts](#script-template-summary) •
|
• [Quick Start](#quick-start) • [Project Structure](#project-structure) • [Customization](#customization) • [Scripts](#script-template-summary) •
|
||||||
|
|
||||||
[![npm](https://img.shields.io/npm/v/presetter-preset-rollup?style=flat-square)](https://github.com/alvis/presetter/releases)
|
[![npm](https://img.shields.io/npm/v/presetter-preset-rollup?style=flat-square)](https://github.com/alvis/presetter/releases)
|
||||||
[![build](https://img.shields.io/github/workflow/status/alvis/presetter/code%20test?style=flat-square)](https://github.com/alvis/presetter/actions)
|
[![build](https://img.shields.io/github/workflow/status/alvis/presetter/code%20test?style=flat-square)](https://github.com/alvis/presetter/actions)
|
||||||
|
@ -76,12 +76,12 @@ After installation, your project file structure should resemble the following or
|
||||||
|
|
||||||
Implement your business logic under `source` and prepare tests under `spec`.
|
Implement your business logic under `source` and prepare tests under `spec`.
|
||||||
|
|
||||||
**TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customisation](https://github.com/alvis/presetter/blob/master/packages/preset-rollup#customisation) section below for more details.
|
**TIPS** You can always change the source directory to other (e.g. src) by setting the `source` variable in `.presetterrc.json`. See the [customization](https://github.com/alvis/presetter/blob/master/packages/preset-rollup#customization) section below for more details.
|
||||||
|
|
||||||
```
|
```
|
||||||
(root)
|
(root)
|
||||||
├─ .git
|
├─ .git
|
||||||
├─ .preseterrc.json
|
├─ .presetterrc.json
|
||||||
├─ node_modules
|
├─ node_modules
|
||||||
├─ source
|
├─ source
|
||||||
│ ├─ <folders>
|
│ ├─ <folders>
|
||||||
|
@ -93,10 +93,10 @@ Implement your business logic under `source` and prepare tests under `spec`.
|
||||||
└─ rollup.config.ts
|
└─ rollup.config.ts
|
||||||
```
|
```
|
||||||
|
|
||||||
## Customisation
|
## Customization
|
||||||
|
|
||||||
By default, this preset exports a handy configuration for rollup for a typescript project.
|
By default, this preset exports a handy configuration for rollup for a typescript project.
|
||||||
But you can further customise (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`).
|
But you can further customize (either extending or replacing) the configuration by specifying the change in the config file (`.presetterrc` or `.presetterrc.json`).
|
||||||
|
|
||||||
These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field.
|
These settings are available in the `config` field in the config file. For directories, the setting is specified in the `variable` field.
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ interface PresetterRC {
|
||||||
|
|
||||||
/** list of plugin and its options */
|
/** list of plugin and its options */
|
||||||
plugins?:
|
plugins?:
|
||||||
| NormalisedRollupConfig['plugins']
|
| NormalizedRollupConfig['plugins']
|
||||||
| Array<
|
| Array<
|
||||||
| string
|
| string
|
||||||
| [name: string]
|
| [name: string]
|
||||||
|
|
|
@ -35,7 +35,6 @@ import type {
|
||||||
ResolvedPresetContext,
|
ResolvedPresetContext,
|
||||||
} from 'presetter';
|
} from 'presetter';
|
||||||
|
|
||||||
|
|
||||||
/** preset configuration for rollup */
|
/** preset configuration for rollup */
|
||||||
export interface RollupConfig {
|
export interface RollupConfig {
|
||||||
[index: string]: unknown | RollupConfig;
|
[index: string]: unknown | RollupConfig;
|
||||||
|
@ -67,17 +66,17 @@ export async function getRollupParameter(
|
||||||
): Promise<Record<'rollupImport' | 'rollupExport', string>> {
|
): Promise<Record<'rollupImport' | 'rollupExport', string>> {
|
||||||
const { config, variable } = context.custom;
|
const { config, variable } = context.custom;
|
||||||
|
|
||||||
const normalisedConfig = template(
|
const normalizedConfig = template(
|
||||||
normaliseConfig(transformConfig({ ...config.rollup })),
|
normalizeConfig(transformConfig({ ...config.rollup })),
|
||||||
variable,
|
variable,
|
||||||
);
|
);
|
||||||
|
|
||||||
return generateRollupParameter(normalisedConfig, context);
|
return generateRollupParameter(normalizedConfig, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* generate template parameters for rollup
|
* generate template parameters for rollup
|
||||||
* @param config normalised rollup config
|
* @param config normalized rollup config
|
||||||
* @param context context about the build environment
|
* @param context context about the build environment
|
||||||
* @returns template parameter related to rollup
|
* @returns template parameter related to rollup
|
||||||
*/
|
*/
|
||||||
|
@ -99,42 +98,42 @@ function generateRollupParameter(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* normalise rollup config with all plugins represented as a list
|
* normalize rollup config with all plugins represented as a list
|
||||||
* @param config transformed config
|
* @param config transformed config
|
||||||
* @returns config that rollup would take
|
* @returns config that rollup would take
|
||||||
*/
|
*/
|
||||||
function normaliseConfig(config: IntermediateRollupConfig): TrueRollupConfig {
|
function normalizeConfig(config: IntermediateRollupConfig): TrueRollupConfig {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.entries(config).map(([key, value]): [string, unknown] => {
|
Object.entries(config).map(([key, value]): [string, unknown] => {
|
||||||
return [
|
return [
|
||||||
key,
|
key,
|
||||||
isDirective(value) ? value : normaliseConfigValue(key, value),
|
isDirective(value) ? value : normalizeConfigValue(key, value),
|
||||||
];
|
];
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* try to normalise any nested configuration
|
* try to normalize any nested configuration
|
||||||
* @param key field name
|
* @param key field name
|
||||||
* @param value value of a field
|
* @param value value of a field
|
||||||
* @returns normalised value
|
* @returns normalized value
|
||||||
*/
|
*/
|
||||||
function normaliseConfigValue(key: string, value: unknown): unknown {
|
function normalizeConfigValue(key: string, value: unknown): unknown {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'plugins':
|
case 'plugins':
|
||||||
return [
|
return [
|
||||||
...Object.entries(value as PluginObject)
|
...Object.entries(value as PluginObject)
|
||||||
.filter(([_, options]) => options !== null)
|
.filter(([_, options]) => options !== null)
|
||||||
.map(([plugin, options]) =>
|
.map(([plugin, options]) =>
|
||||||
[plugin, normaliseConfigValue(plugin, options)].filter(
|
[plugin, normalizeConfigValue(plugin, options)].filter(
|
||||||
(element) => element !== undefined,
|
(element) => element !== undefined,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
default:
|
default:
|
||||||
return isJSON(value)
|
return isJSON(value)
|
||||||
? normaliseConfig(value as IntermediateRollupConfig)
|
? normalizeConfig(value as IntermediateRollupConfig)
|
||||||
: value;
|
: value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -178,12 +177,12 @@ function transformConfigValue(key: string, value: unknown): unknown {
|
||||||
/**
|
/**
|
||||||
* objectify rollup plugins
|
* objectify rollup plugins
|
||||||
* @param plugins rollup plugin config
|
* @param plugins rollup plugin config
|
||||||
* @returns normalised plugin config
|
* @returns normalized plugin config
|
||||||
*/
|
*/
|
||||||
function objectifyPlugins(
|
function objectifyPlugins(
|
||||||
plugins: PluginManifest,
|
plugins: PluginManifest,
|
||||||
): IntermediateRollupConfig['plugins'] {
|
): IntermediateRollupConfig['plugins'] {
|
||||||
const normalisedPlugin: PluginObject = {};
|
const normalizedPlugin: PluginObject = {};
|
||||||
|
|
||||||
const pluginList: PluginConfiguration[] = Array.isArray(plugins)
|
const pluginList: PluginConfiguration[] = Array.isArray(plugins)
|
||||||
? arrayToPluginConfiguration(plugins)
|
? arrayToPluginConfiguration(plugins)
|
||||||
|
@ -191,18 +190,18 @@ function objectifyPlugins(
|
||||||
|
|
||||||
for (const [name, options] of pluginList) {
|
for (const [name, options] of pluginList) {
|
||||||
Object.assign(
|
Object.assign(
|
||||||
normalisedPlugin,
|
normalizedPlugin,
|
||||||
merge(normalisedPlugin, { [name]: options }),
|
merge(normalizedPlugin, { [name]: options }),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return normalisedPlugin;
|
return normalizedPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* normalise rollup plugin config in array form
|
* normalize rollup plugin config in array form
|
||||||
* @param plugins rollup plugin config in array form
|
* @param plugins rollup plugin config in array form
|
||||||
* @returns normalised plugin config
|
* @returns normalized plugin config
|
||||||
*/
|
*/
|
||||||
function arrayToPluginConfiguration(
|
function arrayToPluginConfiguration(
|
||||||
plugins: PluginList,
|
plugins: PluginList,
|
||||||
|
@ -213,9 +212,9 @@ function arrayToPluginConfiguration(
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* normalise rollup plugin config in object form
|
* normalize rollup plugin config in object form
|
||||||
* @param plugins rollup plugin config in object form
|
* @param plugins rollup plugin config in object form
|
||||||
* @returns normalised plugin config
|
* @returns normalized plugin config
|
||||||
*/
|
*/
|
||||||
function objectToPluginConfiguration(
|
function objectToPluginConfiguration(
|
||||||
plugins: PluginObject,
|
plugins: PluginObject,
|
||||||
|
|
Loading…
Reference in New Issue