-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.mjs
164 lines (147 loc) · 3.51 KB
/
rollup.config.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* @package: gistr
* @module: obsidian.md
* @author: Aetherinox
* @url: https://github.com/Aetherinox/obsidian-gistr
*/
/*
* import
*/
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import moment from 'moment';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import license from 'rollup-plugin-license';
import image from '@rollup/plugin-image';
import replace from '@rollup/plugin-replace';
import { v5 as uuidv5 } from 'uuid';
import { readFileSync, writeFileSync } from 'fs';
/*
* declrations > package.json
*/
const
{
name,
author,
version,
repository
} = JSON.parse(readFileSync('./package.json'));
/*
* declrations > constants
*/
const now = moment().milliseconds(0).toISOString();
const build_date = now;
const bIsProd = (process.env.BUILD === 'production');
const bIsDev = (process.env.BUILD === 'dev');
const year = moment(now).year();
const build_guid = uuidv5(` + repository + `, uuidv5.URL)
const build_uuid = uuidv5(version, build_guid)
const path_save_home = './'
const path_save_dist = 'dist/'
/*
* write build id to file
*
* export $(cat .env | xargs)
*/
const ids = `
GUID=${ build_guid }
UUID=${ build_uuid }
`;
/*
* write const ids to .env file
*/
writeFileSync(".env", ids,
{
flag: "w"
})
const asdad = process.env.NAME = "reee"
/*
* banner
*/
const header_banner = `
@name: ${ name } v${ version }
@author: ${ author }
@url: ${ repository.url }
@copyright: (c) ${ year } ${ author }
@license: MIT
@build: ${ build_date }
@guid: ${ build_guid }
@uuid: ${ build_uuid }
`;
/*
* banner output
*/
console.log(header_banner);
console.log(`Running in ${ bIsDev ? 'development' : 'production' } mode`);
/*
* rollup config
*/
export default
{
input: 'src/main.ts',
output:
{
dir: path_save_home,
sourcemap: 'inline',
sourcemapExcludeSources: bIsProd,
format: 'cjs',
exports: 'named'
},
external: [
'obsidian',
'electron',
'uuid',
],
plugins: [
replace(
{
preventAssignment: true,
values:
{
"process.env.NODE_ENV": bIsProd ? '"production"' : '"dev"',
"process.env.ENV": bIsProd ? '"production"' : '"dev"',
"process.env.BUILD": bIsProd ? '"production"' : '"dev"',
"process.env.PLUGIN_VERSION": `"${ version }"`,
"process.env.BUILD_GUID": `"${ build_guid }"`,
"process.env.BUILD_UUID": `"${ build_uuid }"`,
"process.env.BUILD_DATE": JSON.stringify(moment(now)),
"process.env.AUTHOR": `"${ author }"`,
},
}),
typescript(),
nodeResolve(
{
browser: true
}),
commonjs(),
image(),
terser(
{
ecma: 2020,
mangle:
{
toplevel: true
},
compress:
{
module: true,
toplevel: true,
unsafe_arrows: true
},
format:
{
comments: false
}
}),
license(
{
sourcemap: true,
banner:
{
content: `${ header_banner }`,
commentStyle: 'regular',
},
}),
]
};