Skip to content

Commit acde502

Browse files
committed
chore: add postinstall script
1 parent c4fea1c commit acde502

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

npm-postinstall.js

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env node
2+
3+
const pkg = require(require('path').resolve('./package.json'))
4+
5+
let packageJson = null
6+
try {
7+
packageJson = require(require('path').resolve('../../../package.json'))
8+
} catch (e) {
9+
10+
}
11+
12+
const log = console.log
13+
14+
const VERSIONS = {
15+
'@coreui/coreui': {
16+
url: 'https://coreui.io/pro/',
17+
name: 'CoreUI CSS library'
18+
},
19+
'@coreui/angular': {
20+
url: 'https://coreui.io/pro/angular/',
21+
name: 'CoreUI Angular components library',
22+
docs: 'https://coreui.io/angular/docs/'
23+
},
24+
'@coreui/react': {
25+
url: 'https://coreui.io/pro/react/',
26+
name: 'CoreUI React components library',
27+
docs: 'https://coreui.io/react/docs/introduction'
28+
},
29+
'@coreui/vue': {
30+
url: 'https://coreui.io/pro/vue/',
31+
name: 'CoreUI Vue components library',
32+
docs: 'https://coreui.io/vue/docs/introduction/'
33+
},
34+
}
35+
36+
log('\x1b[32m')
37+
log(`\x1b[1mThank you for using ${VERSIONS[pkg.name].name}! \x1b[22m`)
38+
log(`${VERSIONS[pkg.name].name} is an MIT licensed open source project and ` +
39+
`completely free to use. However, the amount of effort needed to maintain ` +
40+
`and develop new features for the project is not sustainable without proper ` +
41+
`financial backing. You can support development by buying Pro Version: ` +
42+
`\x1b[4m${VERSIONS[pkg.name].url}\x1b[24m]`)
43+
log('\x1b[39m')
44+
45+
const isFramework = VERSIONS[pkg.name].name !== '@coreui/coreui'
46+
const haveStyles = packageJson &&
47+
packageJson.dependencies &&
48+
(
49+
packageJson.dependencies['@coreui/coreui'] ||
50+
packageJson.dependencies['@coreui/coreui-pro']
51+
)
52+
53+
if (isFramework && !haveStyles) {
54+
log(`\x1b[1m\x1b[31mError: You don't have '@coreui/coreui' CSS library installed in ` +
55+
`package.json dependencies section. You need to import it in order to style ` +
56+
`CoreUI components. Installation docs: ${VERSIONS[pkg.name].docs} \n \x1b[0m`
57+
)
58+
// ` \x1b[33m`
59+
}

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"src/",
2727
"tests/",
2828
"umd/",
29-
"README.md"
29+
"README.md",
30+
"npm-postinstall.js"
3031
],
3132
"scripts": {
3233
"clean": "nwb clean-module && nwb clean-demo",
@@ -38,7 +39,8 @@
3839
"changelog": "auto-changelog --starting-version 3.0.0-rc.2 --commit-limit false --hide-credit",
3940
"build": "npm run build:lib && npm run build:esm",
4041
"build:lib": "rollup --environment BUNDLE:false --c --sourcemap",
41-
"build:esm": "cross-env BABEL_ENV=esm-dir babel src --out-dir es --copy-files"
42+
"build:esm": "cross-env BABEL_ENV=esm-dir babel src --out-dir es --copy-files",
43+
"postinstall": "node npm-postinstall"
4244
},
4345
"dependencies": {
4446
"@babel/runtime": "^7.10.5",

0 commit comments

Comments
 (0)