-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (60 loc) · 1.77 KB
/
index.js
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
'use strict'
const chalk = require('chalk')
const fs = require('fs')
const {join} = require('path')
const pkg = require('./package.json')
const appLink = join(__dirname, 'node_modules', 'APP')
const symlinkError = error =>
`*******************************************************************
${appLink} must point to '..'
This symlink lets you require('APP/some/path') rather than
../../../some/path
I tried to create it, but got this error:
${error.message}
You might try this:
rm ${appLink}
Then run me again.
~ xoxo, bones
********************************************************************`
function makeAppSymlink() {
console.log(`Linking '${appLink}' to '..' ...`)
try {
fs.unlinkSync(appLink)
fs.linkSync(appLink, '..')
} catch (error) {
console.error(chalk.red(nameError))
process.exit(1)
}
console.log(`Ok, created ${appLink}`)
}
function checkAppSymlink() {
try {
const currently = fs.readlinkSync(appLink)
if (currently !== '..') {
throw new Error(`${appLink} is pointing to '${currently}' rather than '..'`)
}
} catch (error) {
makeAppSymlink()
}
}
const nameError =
`*******************************************************************
You need to give your app a proper name.
The package name
${pkg.name}
isn't valid. If you don't change it, things won't work right.
Please change it in ${__dirname}/package.json
~ xoxo, bones
********************************************************************`
const reasonableName = /^[a-z0-9\-_]+$/
if (!reasonableName.test(pkg.name)) {
console.error(chalk.red(nameError))
}
module.exports = {
get name() { return pkg.name },
get isTesting() { return !!global.it },
get isProduction() {
return process.env.NODE_ENV === 'production'
},
package: pkg,
}