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.
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
import { dirname, resolve } from 'node:path';
|
|
|
|
import { fileURLToPath } from 'node:url';
|
2023-05-05 11:20:29 +00:00
|
|
|
|
2021-09-30 10:13:13 +00:00
|
|
|
import { loadFile, template } from 'presetter';
|
|
|
|
|
|
|
|
import { getRollupParameter } from './rollup';
|
|
|
|
|
2023-06-05 12:55:42 +00:00
|
|
|
import type { PresetAsset } from 'presetter-types';
|
|
|
|
|
2021-09-30 10:13:13 +00:00
|
|
|
import type { RollupConfig } from './rollup';
|
|
|
|
|
2023-06-08 09:50:25 +00:00
|
|
|
const DIR = fileURLToPath(dirname(import.meta.url));
|
|
|
|
|
2021-09-30 10:13:13 +00:00
|
|
|
// paths to the template directory
|
2023-06-08 09:50:25 +00:00
|
|
|
const TEMPLATES = resolve(DIR, '..', 'templates');
|
|
|
|
const CONFIGS = resolve(DIR, '..', 'configs');
|
2021-09-30 10:13:13 +00:00
|
|
|
|
|
|
|
/** 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;
|
2023-06-30 07:45:26 +00:00
|
|
|
buildSource: string;
|
2021-09-30 10:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
export const DEFAULT_VARIABLE: Variable = {
|
2023-06-30 07:45:26 +00:00
|
|
|
source: 'build',
|
2021-09-30 10:13:13 +00:00
|
|
|
output: 'lib',
|
2023-06-30 08:12:23 +00:00
|
|
|
buildSource: 'src',
|
2021-09-30 10:13:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 {
|
2023-07-02 04:19:09 +00:00
|
|
|
extends: ['presetter-preset-strict'],
|
2021-09-30 10:13:13 +00:00
|
|
|
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
|
|
|
},
|
2023-06-30 05:11:14 +00:00
|
|
|
'tsconfig.config.json': resolve(TEMPLATES, 'tsconfig.config.yaml'),
|
2021-09-30 10:13:13 +00:00
|
|
|
},
|
|
|
|
scripts: resolve(TEMPLATES, 'scripts.yaml'),
|
|
|
|
noSymlinks: ['rollup.config.ts'],
|
|
|
|
supplementaryConfig: {
|
2023-06-30 07:45:26 +00:00
|
|
|
'gitignore': ['/rollup.config.ts'],
|
|
|
|
'rollup': resolve(CONFIGS, 'rollup.yaml'),
|
|
|
|
'tsconfig.build': {
|
|
|
|
include: ['{buildSource}'],
|
2023-06-30 08:35:37 +00:00
|
|
|
compilerOptions: {
|
|
|
|
outDir: '{source}',
|
2023-07-02 04:40:34 +00:00
|
|
|
compilerOptions: {
|
|
|
|
moduleResolution: 'nodenext',
|
|
|
|
},
|
2023-06-30 08:35:37 +00:00
|
|
|
},
|
2023-06-30 07:45:26 +00:00
|
|
|
},
|
2021-09-30 10:13:13 +00:00
|
|
|
},
|
|
|
|
variable: DEFAULT_VARIABLE,
|
|
|
|
};
|
|
|
|
}
|