2021-09-30 10:13:13 +00:00
|
|
|
/*
|
|
|
|
* *** MIT LICENSE ***
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
* This code may be modified and distributed under the MIT license.
|
|
|
|
* See the LICENSE file for details.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* @summary Collection of preset assets for bundling a project with rollup
|
|
|
|
*
|
|
|
|
* @author Alvis HT Tang <alvis@hilbert.space>
|
|
|
|
* @license MIT
|
|
|
|
* @copyright Copyright (c) 2021 - All Rights Reserved.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
import { resolve } from 'path';
|
|
|
|
import { loadFile, template } from 'presetter';
|
|
|
|
|
|
|
|
import { getRollupParameter } from './rollup';
|
|
|
|
|
|
|
|
import type { RollupConfig } from './rollup';
|
2022-05-14 10:07:01 +00:00
|
|
|
import type { PresetAsset } from 'presetter';
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
// paths to the template directory
|
|
|
|
const TEMPLATES = resolve(__dirname, '..', 'templates');
|
|
|
|
const CONFIGS = resolve(__dirname, '..', 'configs');
|
|
|
|
|
|
|
|
/** config for this preset */
|
|
|
|
export type PresetConfig = {
|
|
|
|
rollup?: RollupConfig;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** List of configurable variables */
|
|
|
|
export type Variable = {
|
|
|
|
/** the directory containing all source code (default: source) */
|
|
|
|
source: string;
|
|
|
|
/** the directory containing all the compiled files (default: lib) */
|
|
|
|
output: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const DEFAULT_VARIABLE: Variable = {
|
|
|
|
source: 'source',
|
|
|
|
output: 'lib',
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* get the list of templates provided by this preset
|
|
|
|
* @returns list of preset templates
|
|
|
|
*/
|
2022-09-23 12:21:03 +00:00
|
|
|
export default function (): PresetAsset {
|
2021-09-30 10:13:13 +00:00
|
|
|
return {
|
|
|
|
template: {
|
2022-05-14 10:07:01 +00:00
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
2022-09-23 12:21:03 +00:00
|
|
|
'rollup.config.ts': (context) => {
|
2022-09-23 10:44:08 +00:00
|
|
|
const content = loadFile(
|
2021-09-30 10:13:13 +00:00
|
|
|
resolve(TEMPLATES, 'rollup.config.ts'),
|
|
|
|
'text',
|
|
|
|
);
|
2022-09-23 12:21:03 +00:00
|
|
|
const variable = getRollupParameter(context);
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
return template(content, variable);
|
2022-05-14 10:07:01 +00:00
|
|
|
/* eslint-enable @typescript-eslint/naming-convention */
|
2021-09-30 10:13:13 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
scripts: resolve(TEMPLATES, 'scripts.yaml'),
|
|
|
|
noSymlinks: ['rollup.config.ts'],
|
|
|
|
supplementaryConfig: {
|
|
|
|
gitignore: ['/rollup.config.ts'],
|
|
|
|
rollup: resolve(CONFIGS, 'rollup.yaml'),
|
|
|
|
},
|
|
|
|
variable: DEFAULT_VARIABLE,
|
|
|
|
};
|
|
|
|
}
|