poops 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "poops",
3
3
  "description": "Straightforward, no-bullshit bundler for the web.",
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "license": "MIT",
6
6
  "main": "poops.js",
7
7
  "repository": "https://github.com/stamat/poops.git",
@@ -49,4 +49,4 @@
49
49
  "eslint-plugin-promise": "^6.1.1",
50
50
  "sulphuris": "^1.0.5"
51
51
  }
52
- }
52
+ }
package/poops.js CHANGED
@@ -19,8 +19,45 @@ const pkg = require('./package.json')
19
19
  const args = process.argv.slice(2)
20
20
  const pstyle = new PrintStyle()
21
21
 
22
+ let build = false
22
23
  let defaultConfigPath = 'poops.json'
23
- if (args.length) defaultConfigPath = args[0]
24
+
25
+ for (let i = 0; i < args.length; i++) {
26
+ const arg = args[i]
27
+ switch (arg) {
28
+ case '-b':
29
+ case '--build':
30
+ build = true
31
+ break
32
+ case '-c':
33
+ case '--config':
34
+ defaultConfigPath = args[i + 1]
35
+ i++
36
+ break
37
+ case '-v':
38
+ case '--version':
39
+ console.log(pkg.version)
40
+ process.exit(0)
41
+ break
42
+ case '-h':
43
+ case '--help':
44
+ console.log(`Usage: ${pkg.name} [config-file] [options]
45
+ -b, --build\t\tBuild the project and exit
46
+ -c, --config\t\tSpecify the config file
47
+ -h, --help\t\tShow this help message
48
+ -v, --version\t\tShow version number`)
49
+ process.exit(0)
50
+ break
51
+ default:
52
+ if (arg.startsWith('-')) {
53
+ console.log(`Unknown option: ${arg}`)
54
+ process.exit(1)
55
+ } else {
56
+ defaultConfigPath = arg
57
+ }
58
+ }
59
+ }
60
+
24
61
  let configPath = path.join(cwd, defaultConfigPath)
25
62
  if (!args.length && !pathExists(configPath)) configPath = path.join(cwd, '💩.json')
26
63
 
@@ -30,6 +67,13 @@ async function poops() {
30
67
  const scripts = new Scripts(config)
31
68
  const markups = new Markups(config)
32
69
 
70
+ if (build || (!config.watch && !config.livereload && !config.serve)) {
71
+ await styles.compile()
72
+ await scripts.compile()
73
+ await markups.compile()
74
+ process.exit(0)
75
+ }
76
+
33
77
  if (config.livereload) {
34
78
  const lrExcludes = ['.git', '.svn', '.hg']
35
79
 
@@ -73,15 +117,12 @@ async function poops() {
73
117
  }
74
118
  })
75
119
  }
76
-
77
- if (!config.watch && !config.livereload && !config.serve) {
78
- process.exit(1)
79
- }
80
120
  }
81
121
 
82
122
  // CLI Header
83
- console.log(`\n${pstyle.color('#8b4513')}💩 Poops — v${pkg.version}
84
- ----------------${pstyle.reset + pstyle.bell}\n`)
123
+ const title = `💩 Poops — v${pkg.version}`
124
+ console.log(`\n${pstyle.color('#8b4513')}${title}
125
+ ${title.replace(/./g, '-')}${pstyle.reset + pstyle.bell}\n`)
85
126
 
86
127
  // Check if poops.json exists
87
128
  if (!pathExists(configPath)) {
@@ -106,7 +147,7 @@ if (config.includePaths) {
106
147
  }
107
148
 
108
149
  // Start the webserver
109
- if (config.serve) {
150
+ if (!build && config.serve) {
110
151
  const app = connect()
111
152
 
112
153
  if (config.serve.base && pathExists(cwd, config.serve.base)) {
package/script/build ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+
3
+ ./poops.js -b
package/script/publish ADDED
@@ -0,0 +1,102 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * This script is used to publish a new version of the package.
5
+ * It can automatically increment the patch version if no version is specified in the package.json and commit the changes.
6
+ * It can also automatically tag and push the tags.
7
+ * Using GH CLI, it can also create a release.
8
+ *
9
+ * Fucking awesome, right?
10
+ *
11
+ * With love, @stamat
12
+ */
13
+ const readline = require('readline')
14
+ const { execSync } = require('child_process')
15
+ const fs = require('fs')
16
+ const path = require('path')
17
+ let version = process.argv[2]
18
+
19
+ const packageJson = require(path.join(process.cwd(), './package.json'))
20
+
21
+ if (!packageJson.version) {
22
+ console.log('No version found in package.json')
23
+ process.exit(1)
24
+ }
25
+
26
+ const rl = readline.createInterface({
27
+ input: process.stdin,
28
+ output: process.stdout
29
+ })
30
+
31
+ if (version && !isValidVersion(version)) {
32
+ console.log('Invalid version: ', version)
33
+ console.log('Current version: ', packageJson.version)
34
+ process.exit(1)
35
+ }
36
+
37
+ if (version && packageJson.version === version) {
38
+ console.log('Version is already set to ', version)
39
+ process.exit(1)
40
+ }
41
+
42
+ if (!version) {
43
+ console.log('Current version: ', packageJson.version)
44
+ version = incrementPatchVersion(packageJson.version)
45
+ rl.question(`Do you want to increment the version to ${version}? (y/n) `, (answer) => {
46
+ if (answer === 'y') {
47
+ publish(version)
48
+ } else {
49
+ console.log('Aborted')
50
+ process.exit(0)
51
+ }
52
+ rl.close()
53
+ })
54
+ } else {
55
+ publish(version)
56
+ }
57
+
58
+ function isValidVersion(version) {
59
+ return /^(\d+)\.(\d+)\.(\d+)(?:-([\w-]+(?:\.[\w-]+)*))?(?:\+([\w-]+(?:\.[\w-]+)*))?$/.test(version)
60
+ }
61
+
62
+ function incrementPatchVersion(version) {
63
+ const parts = version.split('.')
64
+ const patch = parseInt(parts[2]) + 1
65
+ return `${parts[0]}.${parts[1]}.${patch}`
66
+ }
67
+
68
+ function run(cmd) {
69
+ console.log(cmd)
70
+ const out = execSync(cmd)
71
+ console.log(out.toString())
72
+ }
73
+
74
+ function publish(version) {
75
+ if (fs.existsSync(path.join(process.cwd(), 'script/build'))) {
76
+ run('script/build')
77
+ }
78
+
79
+ packageJson.version = version
80
+ fs.writeFileSync('package.json', JSON.stringify(packageJson, null, 2))
81
+
82
+ run('git add package.json')
83
+ run(`git commit -m "Bump version to ${version}"`)
84
+ run(`git tag v${version}`)
85
+ run('git push')
86
+ run('git push --tags')
87
+
88
+ rl.question('Do you want to create a release on GitHub? (y/n) ', (answer) => {
89
+ if (answer === 'y') {
90
+ let notesArg = '--generate-notes'
91
+ rl.question('Enter notes for the release (optional): ', (notes) => {
92
+ if (notes.trim() !== '') {
93
+ notesArg = `--notes "${notes}"`
94
+ }
95
+ rl.close()
96
+ })
97
+ run(`gh release create v${version} --title "v${version}" ${notesArg} --latest`)
98
+ }
99
+ })
100
+
101
+ run('npm publish')
102
+ }