@sequencemedia/gulp-cli 1.0.48 → 1.1.0

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/index.mjs CHANGED
@@ -7,23 +7,23 @@ import Liftoff from '@sequencemedia/liftoff'
7
7
  import interpret from 'interpret'
8
8
  import v8flags from 'v8flags'
9
9
 
10
- import logger from './lib/logger.mjs'
11
- import ansi from './lib/ansi.mjs'
12
- import exit from './lib/exit.mjs'
13
- import tildify from './lib/tildify.mjs'
14
- import getProcessTitle from './lib/get-process-title.mjs'
15
- import cliOptions from './lib/cli-options.mjs'
16
- import getCompletion from './lib/get-completion.mjs'
17
-
18
- import listenForLevelEvents from './lib/log/listen-for-level-events.mjs'
19
-
20
- import loadConfigFiles from './lib/config/load-files.mjs'
21
- import mergeConfigToCliFlags from './lib/config/cli-flags.mjs'
22
- import mergeConfigToEnvFlags from './lib/config/env-flags.mjs'
23
-
24
- import runVersion from './lib/run-version.mjs'
25
- import runVerify from './lib/run-verify.mjs'
26
- import run from './lib/index.mjs'
10
+ import logger from './src/logger.mjs'
11
+ import ansi from './src/ansi.mjs'
12
+ import exit from './src/exit.mjs'
13
+ import tildify from './src/tildify.mjs'
14
+ import getProcessTitle from './src/get-process-title.mjs'
15
+ import cliOptions from './src/cli-options.mjs'
16
+ import getCompletion from './src/get-completion.mjs'
17
+
18
+ import listenForLevelEvents from './src/log/listen-for-level-events.mjs'
19
+
20
+ import loadConfigFiles from './src/config/load-files.mjs'
21
+ import mergeConfigToCliFlags from './src/config/cli-flags.mjs'
22
+ import mergeConfigToEnvFlags from './src/config/env-flags.mjs'
23
+
24
+ import runVersion from './src/run-version.mjs'
25
+ import runVerify from './src/run-verify.mjs'
26
+ import run from './src/index.mjs'
27
27
 
28
28
  // Set env var for ORIGINAL cwd
29
29
  // before anything touches it
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sequencemedia/gulp-cli",
3
- "version": "1.0.48",
3
+ "version": "1.1.0",
4
4
  "description": "The command line interface to Gulp",
5
5
  "keywords": [
6
6
  "build",
@@ -77,7 +77,7 @@
77
77
  "gulp.1"
78
78
  ],
79
79
  "imports": {
80
- "#gulp-cli/lib/*": "./lib/*.mjs",
80
+ "#gulp-cli/src/*": "./src/*.mjs",
81
81
  "#gulp-cli": "./index.mjs",
82
82
  "#where-am-i": "./where-am-i.mjs"
83
83
  }
package/lib/ansi.mjs DELETED
@@ -1,46 +0,0 @@
1
- import ansiColors from 'ansi-colors'
2
- import colorSupport from 'color-support'
3
-
4
- const HAS_NO_COLOR = process.argv.includes('--no-color')
5
- const HAS_COLOR = process.argv.includes('--color')
6
- const HAS_COLOR_SUPPORT = hasColorSupport(colorSupport())
7
-
8
- function hasColorSupport ({ hasBasic, has256, has16m }) {
9
- return (
10
- hasBasic ||
11
- has256 ||
12
- has16m
13
- )
14
- }
15
-
16
- function hasColor () {
17
- if (HAS_NO_COLOR) {
18
- return false
19
- }
20
-
21
- return (
22
- HAS_COLOR ||
23
- HAS_COLOR_SUPPORT
24
- )
25
- }
26
-
27
- function noColor (message) {
28
- return message
29
- }
30
-
31
- export default (
32
- hasColor()
33
- ? ansiColors
34
- : {
35
- red: noColor,
36
- green: noColor,
37
- blue: noColor,
38
- magenta: noColor,
39
- cyan: noColor,
40
- white: noColor,
41
- gray: noColor,
42
- bgred: noColor,
43
- bold: noColor,
44
- yellow: noColor
45
- }
46
- )
@@ -1,120 +0,0 @@
1
- import ansi from './ansi.mjs'
2
-
3
- export default {
4
- help: {
5
- alias: 'h',
6
- type: 'boolean',
7
- desc: ansi.gray(
8
- 'Show this help.')
9
- },
10
- version: {
11
- alias: 'v',
12
- type: 'boolean',
13
- desc: ansi.gray(
14
- 'Print the global and local gulp versions.')
15
- },
16
- require: {
17
- type: 'string',
18
- requiresArg: true,
19
- desc: ansi.gray(
20
- 'Will require a module before running the gulpfile. ' +
21
- 'This is useful for transpilers but also has other applications.')
22
- },
23
- gulpfile: {
24
- alias: 'f',
25
- type: 'string',
26
- requiresArg: true,
27
- desc: ansi.gray(
28
- 'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' +
29
- 'This will set the CWD to the gulpfile directory as well.')
30
- },
31
- cwd: {
32
- type: 'string',
33
- requiresArg: true,
34
- desc: ansi.gray(
35
- 'Manually set the CWD. The search for the gulpfile, ' +
36
- 'as well as the relativity of all requires will be from here.')
37
- },
38
- verify: {
39
- desc: ansi.gray(
40
- 'Will verify plugins referenced in project\'s package.json against ' +
41
- 'the plugins blacklist.')
42
- },
43
- tasks: {
44
- alias: 'T',
45
- type: 'boolean',
46
- desc: ansi.gray(
47
- 'Print the task dependency tree for the loaded gulpfile.')
48
- },
49
- 'tasks-list': {
50
- type: 'boolean',
51
- desc: ansi.gray(
52
- 'Print a list of tasks for the loaded gulpfile.')
53
- },
54
- 'tasks-json': {
55
- desc: ansi.gray(
56
- 'Print the task dependency tree, ' +
57
- 'in JSON format, for the loaded gulpfile.')
58
- },
59
- 'tasks-depth': {
60
- alias: 'depth',
61
- type: 'number',
62
- requiresArg: true,
63
- default: undefined, // To detect if this cli option is specified.
64
- desc: ansi.gray(
65
- 'Specify the depth of the task dependency tree.')
66
- },
67
- 'compact-tasks': {
68
- type: 'boolean',
69
- default: undefined, // To detect if this cli option is specified.
70
- desc: ansi.gray(
71
- 'Reduce the output of task dependency tree by printing ' +
72
- 'only top tasks and their child tasks.')
73
- },
74
- 'sort-tasks': {
75
- type: 'boolean',
76
- default: undefined, // To detect if this cli option is specified.
77
- desc: ansi.gray(
78
- 'Will sort top tasks of task dependency tree.')
79
- },
80
- color: {
81
- type: 'boolean',
82
- desc: ansi.gray(
83
- 'Will force gulp and gulp plugins to display colors, ' +
84
- 'even when no color support is detected.')
85
- },
86
- 'no-color': {
87
- type: 'boolean',
88
- desc: ansi.gray(
89
- 'Will force gulp and gulp plugins to not display colors, ' +
90
- 'even when color support is detected.')
91
- },
92
- silent: {
93
- alias: 'S',
94
- type: 'boolean',
95
- default: undefined, // To detect if this cli option is specified.
96
- desc: ansi.gray(
97
- 'Suppress all gulp logging.')
98
- },
99
- continue: {
100
- type: 'boolean',
101
- default: undefined, // To detect if this cli option is specified.
102
- desc: ansi.gray(
103
- 'Continue execution of tasks upon failure.')
104
- },
105
- series: {
106
- type: 'boolean',
107
- default: undefined, // To detect if this cli option is specified.
108
- desc: ansi.gray(
109
- 'Run tasks given on the CLI in series (the default is parallel).')
110
- },
111
- 'log-level': {
112
- alias: 'L',
113
- // Type isn't needed because count acts as a boolean
114
- count: true,
115
- default: undefined, // To detect if this cli option is specified.
116
- desc: ansi.gray(
117
- 'Set the loglevel. -L for least verbose and -LLLL for most verbose. ' +
118
- '-LLL is default.')
119
- }
120
- }
@@ -1,21 +0,0 @@
1
- import copyProps from 'copy-props'
2
-
3
- const fromTo = {
4
- 'flags.silent': 'silent',
5
- 'flags.continue': 'continue',
6
- 'flags.series': 'series',
7
- 'flags.logLevel': 'logLevel',
8
- 'flags.compactTasks': 'compactTasks',
9
- 'flags.tasksDepth': 'tasksDepth',
10
- 'flags.sortTasks': 'sortTasks'
11
- }
12
-
13
- export default function mergeConfigToCliFlags (cliProps, configProps) {
14
- return (
15
- copyProps(configProps, cliProps, fromTo, (configProps, cliProps) => {
16
- if (cliProps.value === undefined) {
17
- return configProps.value
18
- }
19
- })
20
- )
21
- }
@@ -1,41 +0,0 @@
1
- import path from 'node:path'
2
- import copyProps from 'copy-props'
3
-
4
- const toFrom = {
5
- configPath: 'flags.gulpfile',
6
- configBase: 'flags.gulpfile',
7
- require: 'flags.require',
8
- nodeFlags: 'flags.nodeFlags'
9
- }
10
-
11
- function getConvert (cliProps) {
12
- return function convert (config, env) {
13
- if (env.keyChain === 'configBase') {
14
- if (cliProps.gulpfile === undefined) {
15
- return path.dirname(config.value)
16
- }
17
- return
18
- }
19
-
20
- if (env.keyChain === 'configPath') {
21
- if (cliProps.gulpfile === undefined) {
22
- return config.value
23
- }
24
- return
25
- }
26
-
27
- if (env.keyChain === 'require') {
28
- return [].concat(env.value, config.value)
29
- }
30
-
31
- if (env.keyChain === 'nodeFlags') {
32
- return [].concat(config.value || [])
33
- }
34
- }
35
- }
36
-
37
- export default function mergeConfigToEnvFlags (envProps, configProps, cliProps) {
38
- return (
39
- copyProps(envProps, configProps, toFrom, getConvert(cliProps), true) // This must reverse because `flags.gulpfile` determines 2 different properties
40
- )
41
- }
@@ -1,50 +0,0 @@
1
- import copyProps from 'copy-props'
2
- import {
3
- join,
4
- extname,
5
- resolve,
6
- dirname
7
- } from 'node:path'
8
-
9
- function getConfig (module) {
10
- if (Reflect.has(module, 'default')) return Reflect.get(module, 'default')
11
- return module
12
- }
13
-
14
- export default async function loadConfigFiles (configFiles = {}, configFileOrder = []) {
15
- const config = {}
16
-
17
- const keyList = (
18
- configFileOrder
19
- .filter((key) => configFiles[key])
20
- )
21
-
22
- while (keyList.length) {
23
- const key = keyList.shift()
24
- const filePath = configFiles[key]
25
-
26
- try {
27
- const module = (
28
- extname(filePath) === '.json'
29
- ? await import(resolve(join(process.cwd(), filePath)), { assert: { type: 'json' } })
30
- : await import(resolve(join(process.cwd(), filePath)))
31
- )
32
-
33
- copyProps(getConfig(module), config, ({ keyChain, value }) => {
34
- if (keyChain === 'flags.gulpfile') {
35
- return resolve(dirname(filePath), value)
36
- }
37
-
38
- return value
39
- })
40
- } catch (e) {
41
- const {
42
- code
43
- } = e
44
-
45
- if (code !== 'ERR_MODULE_NOT_FOUND') console.error(e)
46
- }
47
- }
48
-
49
- return config
50
- }
package/lib/exit.mjs DELETED
@@ -1,8 +0,0 @@
1
- // Fix stdout truncation on windows
2
- export default function exit (code) {
3
- if (process.platform === 'win32' && process.stdout.writableLength) {
4
- process.stdout.once('drain', () => { process.exit(code) })
5
- return
6
- }
7
- process.exit(code)
8
- }
@@ -1,19 +0,0 @@
1
- // Format orchestrator errors
2
- export default function formatError (e) {
3
- if (!e.error) {
4
- return e.message
5
- }
6
-
7
- // PluginError
8
- if (typeof e.error.showStack === 'boolean') {
9
- return e.error.toString()
10
- }
11
-
12
- // Normal error
13
- if (e.error.stack) {
14
- return e.error.stack
15
- }
16
-
17
- // Unknown (string, number, etc.)
18
- return new Error(String(e.error)).stack
19
- }
@@ -1,7 +0,0 @@
1
- const URL = 'https://raw.githubusercontent.com/gulpjs/plugins/master/src/blackList.json'
2
-
3
- export default async function getBlacklist () {
4
- const response = await fetch(URL)
5
-
6
- return response.json()
7
- }
@@ -1,21 +0,0 @@
1
- import path from 'node:path'
2
-
3
- import {
4
- readFile
5
- } from 'node:fs/promises'
6
-
7
- export default async function getCompletion (completionType) {
8
- if (typeof completionType !== 'string') {
9
- throw new Error('Completion type not provided')
10
- }
11
-
12
- try {
13
- const filePath = path.join('./completion', completionType)
14
- const fileData = await readFile(filePath, 'utf8')
15
- console.log(fileData.toString().trim())
16
- process.exit(0)
17
- } catch (e) {
18
- console.error(`echo "Completion type "${completionType}" not found"`)
19
- process.exit(5)
20
- }
21
- }
@@ -1,80 +0,0 @@
1
- const DEFAULT_NODE_FACTORY = {
2
- topNode: getDuplicateOf,
3
- taskNode: getDuplicateOf,
4
- childNode: getDuplicateOf
5
- }
6
-
7
- function getDuplicateOf (node) {
8
- return Object.fromEntries(Object.entries(node))
9
- }
10
-
11
- function hasCompactTasks ({ compactTasks = false }) {
12
- return String(compactTasks) === 'true'
13
- }
14
-
15
- function getTasksDepth ({ tasksDepth }) {
16
- return (
17
- typeof tasksDepth === 'number' && !isNaN(tasksDepth)
18
- ? Math.max(1, tasksDepth)
19
- : null
20
- )
21
- }
22
-
23
- function nonRecursiveDuplicateNode (child, parent, nodeFactory) {
24
- const dupe = nodeFactory.childNode(child)
25
- dupe.nodes = []
26
-
27
- parent.nodes.push(dupe)
28
-
29
- if (child.branch) {
30
- duplicateNodesFor(child, nonRecursiveDuplicateNode, dupe, nodeFactory)
31
- }
32
- }
33
-
34
- function recursiveDuplicateNode (child, parent, maximumDepth, currentDepth, nodeFactory) {
35
- const dupe = nodeFactory.childNode(child)
36
- dupe.nodes = []
37
-
38
- parent.nodes.push(dupe)
39
-
40
- if (!maximumDepth || maximumDepth > currentDepth) {
41
- duplicateNodesFor(child, recursiveDuplicateNode, dupe, maximumDepth, currentDepth + 1, nodeFactory)
42
- }
43
- }
44
-
45
- function duplicateNodesFor ({ nodes }, duplicate, ...args) {
46
- if (Array.isArray(nodes)) {
47
- nodes
48
- .forEach((node) => {
49
- duplicate(node, ...args)
50
- })
51
- }
52
- }
53
-
54
- function duplicateNode (node, tree, cliProps, nodeFactory = DEFAULT_NODE_FACTORY) {
55
- const dupe = nodeFactory.taskNode(node)
56
- dupe.nodes = []
57
-
58
- tree.nodes.push(dupe)
59
-
60
- if (hasCompactTasks(cliProps)) {
61
- duplicateNodesFor(node, nonRecursiveDuplicateNode, dupe, nodeFactory)
62
- } else {
63
- const maximumDepth = getTasksDepth(cliProps)
64
-
65
- if (!maximumDepth || maximumDepth > 1) {
66
- duplicateNodesFor(node, recursiveDuplicateNode, dupe, maximumDepth, 2, nodeFactory)
67
- }
68
- }
69
- }
70
-
71
- function duplicateTree (tree = {}, cliProps = {}, nodeFactory = DEFAULT_NODE_FACTORY) {
72
- const dupe = nodeFactory.topNode(tree)
73
- dupe.nodes = []
74
-
75
- duplicateNodesFor(tree, duplicateNode, dupe, cliProps, nodeFactory)
76
-
77
- return dupe
78
- }
79
-
80
- export default duplicateTree
@@ -1,23 +0,0 @@
1
- import matchdep from 'matchdep'
2
-
3
- /**
4
- * Given a collection of plugin names verifies this collection against
5
- * the blacklist. Returns an object with:
6
- * [plugin name]=>[blacklisting reason]
7
- * or an empty object if none of the dependencies to check are blacklisted.
8
- *
9
- * @param packageJson - The package JSON
10
- * @param blacklistJson - The blacklist JSON
11
- */
12
- function getPackageBlacklist (packageJson, blacklistJson) {
13
- return (
14
- matchdep
15
- .filterAll(Object.keys(blacklistJson), packageJson)
16
- .reduce((blacklist, dependency) => {
17
- blacklist[dependency] = blacklistJson[dependency]
18
- return blacklist
19
- }, {})
20
- )
21
- }
22
-
23
- export default getPackageBlacklist
@@ -1,3 +0,0 @@
1
- export default function getProcessTitle (argv = []) {
2
- return ['gulp'].concat(argv).join(' ').trim()
3
- }
package/lib/get-task.mjs DELETED
@@ -1,41 +0,0 @@
1
- import isObject from 'isobject'
2
-
3
- function isString (value) {
4
- return typeof value === 'string'
5
- }
6
-
7
- function isFunction (value) {
8
- return value instanceof Function
9
- }
10
-
11
- function getDescription (task = {}) {
12
- if (isString(task.description)) {
13
- return task.description
14
- }
15
-
16
- if (isFunction(task.unwrap)) {
17
- return getDescription(task.unwrap())
18
- }
19
- }
20
-
21
- function getFlags (task = {}) {
22
- if (isObject(task.flags)) {
23
- return task.flags
24
- }
25
-
26
- if (isFunction(task.unwrap)) {
27
- return getFlags(task.unwrap())
28
- }
29
- }
30
-
31
- function getTask (gulp) {
32
- return function getTaskFor (name) {
33
- const task = gulp.task(name)
34
- return {
35
- description: getDescription(task),
36
- flags: getFlags(task)
37
- }
38
- }
39
- }
40
-
41
- export default getTask
package/lib/index.mjs DELETED
@@ -1,59 +0,0 @@
1
- import stdout from 'mute-stdout'
2
-
3
- import listenForGulpEvents from './log/listen-for-gulp-events.mjs'
4
- import listenForSyncEvents from './log/listen-for-sync-events.mjs'
5
- import registerGulpTasks from './register-gulp-tasks.mjs'
6
-
7
- import runGulpTasks from './run-gulp-tasks.mjs'
8
-
9
- function getImportFromModulePath (params) {
10
- const {
11
- envProps: {
12
- modulePath
13
- }
14
- } = params
15
-
16
- return (
17
- import(modulePath)
18
- .then(({ default: gulp }) => Object.assign(params, { gulp }))
19
- )
20
- }
21
-
22
- function getImportFromConfigPath (params) {
23
- const {
24
- envProps: {
25
- configPath
26
- }
27
- } = params
28
-
29
- return (
30
- import(configPath)
31
- .then((tasks) => Object.assign(params, { tasks }))
32
- )
33
- }
34
-
35
- function isSilent (cliProps) {
36
- return (cliProps.tasksList || cliProps.tasks || cliProps.tasksJson)
37
- }
38
-
39
- async function run (cliProps, envProps, configProps = {}) {
40
- if (isSilent(cliProps)) stdout.mute()
41
-
42
- const { gulp, tasks } = (
43
- await Promise.resolve({ cliProps, envProps, configProps })
44
- .then(getImportFromModulePath)
45
- .then(getImportFromConfigPath)
46
- )
47
-
48
- listenForGulpEvents(gulp)
49
- listenForSyncEvents(gulp, cliProps)
50
- registerGulpTasks(gulp, tasks)
51
-
52
- stdout.unmute()
53
-
54
- return (
55
- runGulpTasks(gulp, cliProps, envProps, configProps)
56
- )
57
- }
58
-
59
- export default run
@@ -1,46 +0,0 @@
1
- import prettyHrtime from 'pretty-hrtime'
2
-
3
- import logger from '#gulp-cli/lib/logger'
4
- import ansi from '#gulp-cli/lib/ansi'
5
- import formatError from '#gulp-cli/lib/format-error'
6
-
7
- const errors = new Set()
8
-
9
- function start (event) {
10
- const level = event.branch ? 'debug' : 'info'
11
- logger[level](`Starting '${ansi.cyan(event.name)}'...`)
12
- }
13
-
14
- function stop (event) {
15
- const level = event.branch ? 'debug' : 'info'
16
- logger[level](`Finished '${ansi.cyan(event.name)}' after ${ansi.magenta(prettyHrtime(event.duration))}`)
17
- }
18
-
19
- function error (event) {
20
- const level = event.branch ? 'debug' : 'error'
21
- logger[level](`'${ansi.cyan(event.name)}' ${ansi.red('errored after')} ${ansi.magenta(prettyHrtime(event.duration))}`)
22
-
23
- // Exit if we have logged this before
24
- if (errors.has(event.error)) return
25
-
26
- // If we haven't logged this before, log it and add it to the error list
27
- logger.error(formatError(event))
28
- errors.add(event.error)
29
- }
30
-
31
- function stopListeningForGulpEvents (gulp) {
32
- gulp
33
- .removeListener('start', start)
34
- .removeListener('stop', stop)
35
- .removeListener('error', error)
36
- }
37
-
38
- // Wire up logging events
39
- export default function listenForGulpEvents (gulp) {
40
- stopListeningForGulpEvents(gulp)
41
-
42
- gulp
43
- .on('start', start)
44
- .on('stop', stop)
45
- .on('error', error)
46
- }
@@ -1,49 +0,0 @@
1
- import fancyLog from 'fancy-log'
2
- import logger from '#gulp-cli/lib/logger'
3
-
4
- const noop = () => {}
5
-
6
- // The sorting of the levels is
7
- // significant.
8
- const levels = [
9
- 'error', // -L: Logs error events.
10
- 'warn', // -LL: Logs warn and error events.
11
- 'info', // -LLL: Logs info, warn and error events.
12
- 'debug' // -LLLL: Logs all log levels.
13
- ]
14
-
15
- function stopListeningForLevelEvents () {
16
- levels
17
- .forEach((level) => {
18
- if (level === 'error') {
19
- logger.removeListener(level, noop).removeListener(level, fancyLog.error)
20
- } else {
21
- logger.removeListener(level, fancyLog)
22
- }
23
- })
24
- }
25
-
26
- // Wire up log levels
27
- export default function listenForLevelEvents (cliProps) {
28
- // Remove previous listeners to enable to call this twice.
29
- stopListeningForLevelEvents()
30
-
31
- // Silent?
32
- if (cliProps.tasksList || cliProps.tasksJson || cliProps.help || cliProps.version || cliProps.silent) {
33
- // Keep from crashing process when silent
34
- logger.on('error', noop)
35
- } else {
36
- // Default level is 3 (info)
37
- const loglevel = cliProps.logLevel || 3
38
-
39
- levels
40
- .filter((level, i) => level && i < loglevel)
41
- .forEach((level) => {
42
- if (level === 'error') {
43
- logger.on(level, fancyLog.error)
44
- } else {
45
- logger.on(level, fancyLog)
46
- }
47
- })
48
- }
49
- }
@@ -1,60 +0,0 @@
1
- import logger from '#gulp-cli/lib/logger'
2
- import ansi from '#gulp-cli/lib/ansi'
3
-
4
- const tasks = new Map()
5
-
6
- function warn () {
7
- if (tasks.size) {
8
- const taskNames = Array.from(tasks.values()).join(', ')
9
-
10
- process.exitCode = 1
11
-
12
- logger.warn(
13
- ansi.red('The following tasks did not complete:')
14
- )
15
-
16
- logger.warn(
17
- ansi.cyan(taskNames)
18
- )
19
-
20
- logger.warn(
21
- ansi.red('Did you forget to signal async completion?')
22
- )
23
- }
24
- }
25
-
26
- function start ({ uid, name }) {
27
- tasks.set(uid, name)
28
- }
29
-
30
- function clear ({ uid }) {
31
- tasks.delete(uid)
32
- }
33
-
34
- function clearAll () {
35
- tasks.clear()
36
- }
37
-
38
- function stopListeningForSyncEvents (gulp) {
39
- // Ensure to detach
40
- process
41
- .removeListener('exit', warn)
42
-
43
- gulp
44
- .removeListener('start', start)
45
- .removeListener('stop', clear)
46
- .removeListener('error', clear).removeListener('error', clearAll)
47
- }
48
-
49
- export default function listenForSyncEvents (gulp, cliProps) {
50
- stopListeningForSyncEvents(gulp)
51
-
52
- process
53
- .once('exit', warn)
54
-
55
- // When not running in --continue mode we need to clear everything on error
56
- gulp
57
- .on('start', start)
58
- .on('stop', clear)
59
- .on('error', cliProps.continue ? clear : clearAll)
60
- }
@@ -1,16 +0,0 @@
1
- import {
2
- writeFile
3
- } from 'node:fs/promises'
4
-
5
- import getDuplicate from '#gulp-cli/lib/get-duplicate'
6
-
7
- export default function logTasksJson (tree, cliProps) {
8
- const dupe = getDuplicate(tree, cliProps)
9
- const json = JSON.stringify(dupe)
10
-
11
- // Write to a file if not `true`
12
- if (cliProps.tasksJson !== true) return writeFile(cliProps.tasksJson, json, 'utf8')
13
-
14
- // Otherwise
15
- console.log(json.trim())
16
- }
@@ -1,3 +0,0 @@
1
- export default function logTasksList ({ nodes = [] }) {
2
- console.log(nodes.join('\n').trim())
3
- }
package/lib/log/tasks.mjs DELETED
@@ -1,163 +0,0 @@
1
- import archy from 'archy'
2
-
3
- import sortBy from 'array-sort'
4
- import isObject from 'isobject'
5
-
6
- import logger from '#gulp-cli/lib/logger'
7
- import ansi from '#gulp-cli/lib/ansi'
8
- import getDuplicate from '#gulp-cli/lib/get-duplicate'
9
-
10
- function getLineInfoCollector (lineInfo) {
11
- return {
12
- topTask (node) {
13
- lineInfo.push({
14
- name: node.label,
15
- desc: node.desc,
16
- type: 'top'
17
- })
18
- },
19
- option (opt) {
20
- lineInfo.push({
21
- name: opt.label,
22
- desc: opt.desc,
23
- type: 'option'
24
- })
25
- },
26
- childTask (node) {
27
- lineInfo.push({
28
- name: node.label,
29
- type: 'child'
30
- })
31
- }
32
- }
33
- }
34
-
35
- function getNodeFactory (getTask, entryObserver) {
36
- return {
37
- topNode (node) {
38
- return {
39
- label: node.label
40
- }
41
- },
42
-
43
- taskNode (node) {
44
- const task = getTask(node.label) || {}
45
-
46
- const newNode = {
47
- label: node.label,
48
- desc: typeof task.description === 'string' ? task.description : '',
49
- cliProps: []
50
- }
51
- entryObserver.topTask(newNode)
52
-
53
- if (isObject(task.flags)) {
54
- Object.keys(task.flags)
55
- .sort()
56
- .filter(Boolean)
57
- .forEach((flag) => {
58
- const opt = {
59
- label: flag,
60
- desc: typeof task.flags[flag] === 'string' ? task.flags[flag] : ''
61
- }
62
- entryObserver.option(opt)
63
- newNode.cliProps.push(opt)
64
- newNode.label += '\n' + opt.label // The way of archy for options.
65
- })
66
- }
67
-
68
- return newNode
69
- },
70
-
71
- childNode (node) {
72
- const newChild = {
73
- label: node.label
74
- }
75
- entryObserver.childTask(newChild)
76
- newChild.label = '' // Because don't use child tasks to calc indents.
77
-
78
- return newChild
79
- }
80
- }
81
- }
82
-
83
- function getSpacerForLineIndents (tree, lineInfo) {
84
- let maxSize = 0
85
- const sizes = []
86
-
87
- archy(tree)
88
- .split('\n')
89
- .slice(1, -1)
90
- .forEach((line, index) => {
91
- const info = lineInfo[index]
92
- if (info.type === 'top' || info.type === 'option') {
93
- maxSize = Math.max(maxSize, line.length)
94
- sizes.push(line.length)
95
- } else {
96
- sizes.push(0)
97
- }
98
- })
99
-
100
- maxSize += 3
101
-
102
- return function getSpacerFor (index) {
103
- return Array(maxSize - sizes[index]).join(' ')
104
- }
105
- }
106
-
107
- function getLinesContainingOnlyBranches (tree) {
108
- tree.nodes
109
- .forEach((node) => {
110
- node.label = ''
111
- node.cliProps
112
- .forEach(() => {
113
- node.label += '\n'
114
- })
115
- })
116
-
117
- return archy(tree)
118
- .split('\n')
119
- .slice(1, -1)
120
- }
121
-
122
- function logLines (lines, spacer, lineInfo) {
123
- lines
124
- .forEach((branch, index) => {
125
- const info = lineInfo[index]
126
-
127
- let line = ansi.white(branch)
128
-
129
- if (info.type === 'top') {
130
- line += ansi.cyan(info.name)
131
- if (info.desc.length > 0) {
132
- line += spacer(index) + ansi.white(info.desc)
133
- }
134
- } else if (info.type === 'option') {
135
- line += ansi.magenta(info.name)
136
- if (info.desc.length > 0) {
137
- line += spacer(index) + ansi.white('…' + info.desc)
138
- }
139
- } else { // If (info.type === 'child') {
140
- line += ansi.white(info.name)
141
- }
142
-
143
- logger.info(line)
144
- })
145
- }
146
-
147
- // Wire up logger tasks
148
- export default function logTasks (tree, cliProps, getTask) {
149
- if (cliProps.sortTasks) {
150
- tree.nodes = sortBy(tree.nodes, 'label')
151
- }
152
-
153
- const lineInfo = []
154
- const entryObserver = getLineInfoCollector(lineInfo)
155
- const nodeFactory = getNodeFactory(getTask, entryObserver)
156
-
157
- const dupe = getDuplicate(tree, cliProps, nodeFactory)
158
- const spacer = getSpacerForLineIndents(dupe, lineInfo)
159
- const lines = getLinesContainingOnlyBranches(dupe)
160
-
161
- logger.info(dupe.label)
162
- logLines(lines, spacer, lineInfo)
163
- }
package/lib/logger.mjs DELETED
@@ -1,3 +0,0 @@
1
- import getLogger from '@sequencemedia/gulp-log'
2
-
3
- export default getLogger('gulp-cli')
@@ -1,7 +0,0 @@
1
- export default function registerGulpTasks (gulp, tasks) {
2
- Object.entries(tasks)
3
- .filter(([taskName, task]) => (taskName || task.displayName) && task instanceof Function)
4
- .forEach(([taskName, task]) => {
5
- gulp.task(task.displayName || taskName, task)
6
- })
7
- }
@@ -1,14 +0,0 @@
1
- import tildify from './tildify.mjs'
2
-
3
- import logTasksJson from './log/tasks-json.mjs'
4
-
5
- export default function runGulpTasksJsonTree (gulp, cliProps, envProps, configProps) {
6
- const tree = gulp.tree({ deep: true })
7
- if (configProps.description && typeof configProps.description === 'string') {
8
- tree.label = configProps.description
9
- } else {
10
- tree.label = `Tasks for ${tildify(envProps.configPath)}`
11
- }
12
-
13
- return logTasksJson(tree, cliProps)
14
- }
@@ -1,7 +0,0 @@
1
- import logTasksList from './log/tasks-list.mjs'
2
-
3
- export default function runGulpTasksListTree (gulp) {
4
- const tree = gulp.tree()
5
-
6
- return logTasksList(tree)
7
- }
@@ -1,16 +0,0 @@
1
- import ansi from './ansi.mjs'
2
- import tildify from './tildify.mjs'
3
-
4
- import logTasks from './log/tasks.mjs'
5
- import getTask from './get-task.mjs'
6
-
7
- export default function runGulpTasksTree (gulp, cliProps, envProps, configProps) {
8
- const tree = gulp.tree({ deep: true })
9
- if (configProps.description && typeof configProps.description === 'string') {
10
- tree.label = configProps.description
11
- } else {
12
- tree.label = `Tasks for ${ansi.magenta(tildify(envProps.configPath))}`
13
- }
14
-
15
- return logTasks(tree, cliProps, getTask(gulp))
16
- }
@@ -1,45 +0,0 @@
1
- import logger from './logger.mjs'
2
- import ansi from './ansi.mjs'
3
- import exit from './exit.mjs'
4
- import tildify from './tildify.mjs'
5
-
6
- import runGulpTasksListTree from './run-gulp-tasks-list-tree.mjs'
7
- import runGulpTasksTree from './run-gulp-tasks-tree.mjs'
8
- import runGulpTasksJsonTree from './run-gulp-tasks-json-tree.mjs'
9
-
10
- function getMethodFromCliProps ({ series = false }) {
11
- return series ? 'series' : 'parallel'
12
- }
13
-
14
- function getTasksFromCliProps ({ _: tasks = [] }) {
15
- return (
16
- tasks.length ? [...tasks] : ['default']
17
- )
18
- }
19
-
20
- export default function runGulpTasks (gulp, cliProps, envProps, configProps) {
21
- if (cliProps.tasksList) return runGulpTasksListTree(gulp)
22
-
23
- if (cliProps.tasks) return runGulpTasksTree(gulp, cliProps, envProps, configProps)
24
-
25
- if (cliProps.tasksJson) return runGulpTasksJsonTree(gulp, cliProps, envProps, configProps)
26
-
27
- try {
28
- const {
29
- configPath
30
- } = envProps
31
-
32
- logger.info(`Using gulpfile ${ansi.magenta(tildify(configPath))}`)
33
-
34
- const method = getMethodFromCliProps(cliProps)
35
- const tasks = getTasksFromCliProps(cliProps)
36
-
37
- return (
38
- gulp[method](tasks)((e) => e && exit(1))
39
- )
40
- } catch ({ message }) {
41
- logger.error(ansi.red(message))
42
- logger.error('To list available tasks run: gulp --tasks')
43
- exit(1)
44
- }
45
- }
@@ -1,55 +0,0 @@
1
- import path from 'node:path'
2
-
3
- import {
4
- readFile
5
- } from 'node:fs/promises'
6
-
7
- import logger from './logger.mjs'
8
- import ansi from './ansi.mjs'
9
- import exit from './exit.mjs'
10
- import tildify from './tildify.mjs'
11
-
12
- import getBlacklist from './get-blacklist.mjs'
13
- import getPackageBlacklist from './get-package-blacklist.mjs'
14
-
15
- function getPackagePath (envProps, cliProps) {
16
- let packagePath = cliProps.verify !== true ? cliProps.verify : './package.json'
17
-
18
- if (path.resolve(packagePath) !== path.normalize(packagePath)) {
19
- packagePath = path.join(path.normalize(envProps.cwd), packagePath)
20
- }
21
-
22
- return packagePath
23
- }
24
-
25
- async function getPackageJson (packagePath) {
26
- const fileData = await readFile(packagePath)
27
- return JSON.parse(fileData.toString())
28
- }
29
-
30
- export default async function runVerify (envProps, cliProps) {
31
- const packagePath = getPackagePath(envProps, cliProps)
32
-
33
- logger.info(`Verifying dependencies in ${ansi.magenta(tildify(packagePath))}`)
34
- try {
35
- const blacklistJson = await getBlacklist()
36
- const packageJson = await getPackageJson(packagePath)
37
- const packageBlacklist = getPackageBlacklist(packageJson, blacklistJson)
38
-
39
- const dependencies = Object.entries(packageBlacklist)
40
- if (dependencies.length) {
41
- logger.warn(ansi.red('Blacklisted dependencies in this project:'))
42
- dependencies
43
- .forEach(([name, reason]) => {
44
- logger.warn(`${ansi.bgred(name)}: ${reason}`)
45
- })
46
- exit(1)
47
- }
48
-
49
- logger.info(ansi.green('There are no blacklisted dependencies in this project'))
50
- exit(0)
51
- } catch ({ message }) {
52
- logger.error(`${ansi.red('Failed to verify dependencies.')} Could not get blacklist - ${message}`)
53
- exit(1)
54
- }
55
- }
@@ -1,26 +0,0 @@
1
- import {
2
- join
3
- } from 'node:path'
4
-
5
- import exit from './exit.mjs'
6
-
7
- import ROOT from '#where-am-i'
8
-
9
- async function getGulpCliVersion () {
10
- const {
11
- default: {
12
- version
13
- }
14
- } = await import(join(ROOT, 'package.json'), { assert: { type: 'json' } })
15
- return version
16
- }
17
-
18
- function getGulpVersion ({ modulePackage: { version = 'unknown' } = {} }) {
19
- return version
20
- }
21
-
22
- export default async function runVersion (envProps) {
23
- console.log(`Gulp CLI version: ${await getGulpCliVersion()}`)
24
- console.log(`Gulp version: ${getGulpVersion(envProps)}`)
25
- exit(0)
26
- }
package/lib/tildify.mjs DELETED
@@ -1,5 +0,0 @@
1
- import replaceHomedir from 'replace-homedir'
2
-
3
- export default function tildify (filePath) {
4
- return replaceHomedir(filePath, '~')
5
- }