@newlogic-digital/cli 1.3.0 → 1.4.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
@@ -2,102 +2,102 @@
2
2
 
3
3
  import init from './src/commands/init/index.mjs'
4
4
  import cms from './src/commands/cms/index.mjs'
5
- import pc from 'picocolors'
5
+ import { styleText } from 'node:util'
6
6
  import { version, name } from './src/utils.mjs'
7
7
 
8
8
  function normalizeOptionName(name) {
9
- return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
9
+ return name.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase())
10
10
  }
11
11
 
12
12
  function parseCommandArgs(args) {
13
- const positionals = []
14
- const options = {}
15
-
16
- for (let i = 0; i < args.length; i++) {
17
- const arg = args[i]
18
-
19
- if (arg === '-y') {
20
- options.y = true
21
- continue
22
- }
23
-
24
- if (!arg.startsWith('--')) {
25
- positionals.push(arg)
26
- continue
27
- }
28
-
29
- if (arg.startsWith('--no-')) {
30
- options[normalizeOptionName(arg.slice(5))] = false
31
- continue
32
- }
33
-
34
- if (arg.includes('=')) {
35
- const splitIndex = arg.indexOf('=')
36
- const key = normalizeOptionName(arg.slice(2, splitIndex))
37
- const value = arg.slice(splitIndex + 1)
38
-
39
- options[key] = value || true
40
- continue
41
- }
42
-
43
- const key = normalizeOptionName(arg.slice(2))
44
- const nextArg = args[i + 1]
45
-
46
- if (nextArg && !nextArg.startsWith('-')) {
47
- options[key] = nextArg
48
- i++
49
- continue
50
- }
51
-
52
- options[key] = true
13
+ const positionals = []
14
+ const options = {}
15
+
16
+ for (let i = 0; i < args.length; i++) {
17
+ const arg = args[i]
18
+
19
+ if (arg === '-y') {
20
+ options.y = true
21
+ continue
22
+ }
23
+
24
+ if (!arg.startsWith('--')) {
25
+ positionals.push(arg)
26
+ continue
53
27
  }
54
28
 
55
- return { positionals, options }
29
+ if (arg.startsWith('--no-')) {
30
+ options[normalizeOptionName(arg.slice(5))] = false
31
+ continue
32
+ }
33
+
34
+ if (arg.includes('=')) {
35
+ const splitIndex = arg.indexOf('=')
36
+ const key = normalizeOptionName(arg.slice(2, splitIndex))
37
+ const value = arg.slice(splitIndex + 1)
38
+
39
+ options[key] = value || true
40
+ continue
41
+ }
42
+
43
+ const key = normalizeOptionName(arg.slice(2))
44
+ const nextArg = args[i + 1]
45
+
46
+ if (nextArg && !nextArg.startsWith('-')) {
47
+ options[key] = nextArg
48
+ i++
49
+ continue
50
+ }
51
+
52
+ options[key] = true
53
+ }
54
+
55
+ return { positionals, options }
56
56
  }
57
57
 
58
58
  const rawArgs = process.argv.slice(2)
59
59
  const command = rawArgs[0]
60
60
 
61
61
  if (!command) {
62
- console.log(`
63
- ${pc.blue(`${name} v${version}`)}
62
+ console.log(`
63
+ ${styleText('blue', `${name} v${version}`)}
64
64
 
65
65
  Usage:
66
66
 
67
67
  -- init --
68
- ${pc.green('newlogic init')} - Creates a new project in current directory
69
- ${pc.green('newlogic init')} ${pc.yellow('<directory>')} - Creates a new project in new directory with the name ${pc.yellow('<directory>')}
70
- ${pc.green('newlogic init ui')} - Creates a new ${pc.blue('@newlogic-digital/ui')} project in current directory
71
- ${pc.green('newlogic init ui')} ${pc.yellow('<directory>')} - Creates a new ${pc.blue('@newlogic-digital/ui')} project in new directory with the name ${pc.yellow('<directory>')}
72
- ${pc.green('newlogic init cms')} - Creates a new ${pc.blue('@newlogic-digital/cms')} project in current directory
73
- ${pc.green('newlogic init cms')} ${pc.yellow('<directory>')} - Creates a new ${pc.blue('@newlogic-digital/cms')} project in new directory with the name ${pc.yellow('<directory>')}
74
- ${pc.green('newlogic init ui')} ${pc.yellow('<directory>')} ${pc.cyan('--branch=dev --clone=https --git --remote=<git-url> --install')}
75
- ${pc.green('newlogic init cms')} ${pc.yellow('<directory>')} ${pc.cyan('--branch=dev --clone=https --variant=cms-web --install --prepare --dev --migrations')}
76
- ${pc.green('newlogic init ui')} ${pc.yellow('<directory>')} ${pc.cyan('-y')} - Runs with default options without prompts
68
+ ${styleText('green', 'newlogic init')} - Creates a new project in current directory
69
+ ${styleText('green', 'newlogic init')} ${styleText('yellow', '<directory>')} - Creates a new project in new directory with the name ${styleText('yellow', '<directory>')}
70
+ ${styleText('green', 'newlogic init ui')} - Creates a new ${styleText('blue', '@newlogic-digital/ui')} project in current directory
71
+ ${styleText('green', 'newlogic init ui')} ${styleText('yellow', '<directory>')} - Creates a new ${styleText('blue', '@newlogic-digital/ui')} project in new directory with the name ${styleText('yellow', '<directory>')}
72
+ ${styleText('green', 'newlogic init cms')} - Creates a new ${styleText('blue', '@newlogic-digital/cms')} project in current directory
73
+ ${styleText('green', 'newlogic init cms')} ${styleText('yellow', '<directory>')} - Creates a new ${styleText('blue', '@newlogic-digital/cms')} project in new directory with the name ${styleText('yellow', '<directory>')}
74
+ ${styleText('green', 'newlogic init ui')} ${styleText('yellow', '<directory>')} ${styleText('cyan', '--branch=dev --clone=https --scope=blank --git --remote=<git-url> --install')}
75
+ ${styleText('green', 'newlogic init cms')} ${styleText('yellow', '<directory>')} ${styleText('cyan', '--branch=dev --clone=https --variant=cms-web --install --prepare --dev --migrations')}
76
+ ${styleText('green', 'newlogic init ui')} ${styleText('yellow', '<directory>')} ${styleText('cyan', '-y')} - Runs with default options without prompts
77
77
 
78
78
  -- cms --
79
- ${pc.green('newlogic cms prepare')} - Copies templates and components from ${pc.blue('@newlogic-digital/ui')} project to ${pc.blue('@newlogic-digital/cms')}
80
- ${pc.green('newlogic cms prepare views')} - Copies views from ${pc.blue('@newlogic-digital/ui')} project to ${pc.blue('@newlogic-digital/cms')} even if they already exists
81
- ${pc.green('newlogic cms prepare components')} - Copies components from ${pc.blue('@newlogic-digital/ui')} project to ${pc.blue('@newlogic-digital/cms')} even if they already exists
82
- ${pc.green('newlogic cms new-component')} ${pc.yellow('<name>')} - Creates a new ${pc.blue('@newlogic-digital/cms')} section with name ${pc.yellow('<name>')}
83
- ${pc.red('newlogic cms prepare templates')} - (deprecated) Copies templates from ${pc.blue('@newlogic-digital/ui')} project to ${pc.blue('@newlogic-digital/cms')} even if they already exists
84
- ${pc.red('newlogic cms prepare sections')} - (deprecated) Copies sections from ${pc.blue('@newlogic-digital/ui')} project to ${pc.blue('@newlogic-digital/cms')} even if they already exists
85
- ${pc.red('newlogic cms new-section')} ${pc.yellow('<name>')} - (deprecated) Creates a new ${pc.blue('@newlogic-digital/cms')} section with name ${pc.yellow('<name>')}
79
+ ${styleText('green', 'newlogic cms prepare')} - Copies templates and components from ${styleText('blue', '@newlogic-digital/ui')} project to ${styleText('blue', '@newlogic-digital/cms')}
80
+ ${styleText('green', 'newlogic cms prepare views')} - Copies views from ${styleText('blue', '@newlogic-digital/ui')} project to ${styleText('blue', '@newlogic-digital/cms')} even if they already exists
81
+ ${styleText('green', 'newlogic cms prepare components')} - Copies components from ${styleText('blue', '@newlogic-digital/ui')} project to ${styleText('blue', '@newlogic-digital/cms')} even if they already exists
82
+ ${styleText('green', 'newlogic cms new-component')} ${styleText('yellow', '<name>')} - Creates a new ${styleText('blue', '@newlogic-digital/cms')} section with name ${styleText('yellow', '<name>')}
83
+ ${styleText('red', 'newlogic cms prepare templates')} - (deprecated) Copies templates from ${styleText('blue', '@newlogic-digital/ui')} project to ${styleText('blue', '@newlogic-digital/cms')} even if they already exists
84
+ ${styleText('red', 'newlogic cms prepare sections')} - (deprecated) Copies sections from ${styleText('blue', '@newlogic-digital/ui')} project to ${styleText('blue', '@newlogic-digital/cms')} even if they already exists
85
+ ${styleText('red', 'newlogic cms new-section')} ${styleText('yellow', '<name>')} - (deprecated) Creates a new ${styleText('blue', '@newlogic-digital/cms')} section with name ${styleText('yellow', '<name>')}
86
86
  `)
87
87
  }
88
88
 
89
89
  if (command === 'init') {
90
- const { positionals, options } = parseCommandArgs(rawArgs.slice(1))
91
- const action = positionals[0]
92
- const name = positionals[1]
90
+ const { positionals, options } = parseCommandArgs(rawArgs.slice(1))
91
+ const action = positionals[0]
92
+ const name = positionals[1]
93
93
 
94
- await init(action, name, options)
94
+ await init(action, name, options)
95
95
  }
96
96
 
97
97
  if (command === 'cms') {
98
- const { positionals } = parseCommandArgs(rawArgs.slice(1))
99
- const action = positionals[0]
100
- const name = positionals[1]
98
+ const { positionals } = parseCommandArgs(rawArgs.slice(1))
99
+ const action = positionals[0]
100
+ const name = positionals[1]
101
101
 
102
- await cms(action, name)
102
+ await cms(action, name)
103
103
  }
package/package.json CHANGED
@@ -1,31 +1,32 @@
1
1
  {
2
2
  "name": "@newlogic-digital/cli",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "main": "index.mjs",
5
5
  "bin": {
6
6
  "newlogic-cli": "index.mjs",
7
7
  "newlogic": "index.mjs"
8
8
  },
9
9
  "scripts": {
10
- "eslint": "eslint '**/*.mjs' --fix"
10
+ "oxlint": "oxlint",
11
+ "oxlint-fix": "oxlint --fix"
11
12
  },
12
13
  "dependencies": {
13
- "lodash": "^4.17.23",
14
- "prompts": "^2.4.2",
15
- "fs-extra": "^11.3.3",
16
- "picocolors": "^1.1.1",
14
+ "@clack/prompts": "^1.1.0",
15
+ "dedent": "^1.7.2",
16
+ "es-toolkit": "^1.45.1",
17
17
  "fast-glob": "^3.3.3",
18
- "dedent": "^1.7.1"
19
- },
20
- "devDependencies": {
21
- "eslint-config-standard": "^17.1.0"
18
+ "fs-extra": "^11.3.4"
22
19
  },
23
20
  "files": [
24
21
  "index.js",
25
22
  "src"
26
23
  ],
27
24
  "engines": {
28
- "node": ">=16.0.0",
29
- "npm": ">=8.0.0"
25
+ "node": ">=22.0.0",
26
+ "npm": ">=10.0.0"
27
+ },
28
+ "devDependencies": {
29
+ "@stylistic/eslint-plugin": "^5.10",
30
+ "oxlint": "^1.56.0"
30
31
  }
31
32
  }
@@ -1,67 +1,67 @@
1
1
  import prepare from './prepare.mjs'
2
- import pc from 'picocolors'
3
2
  import fs from 'fs'
4
3
  import fse from 'fs-extra'
4
+ import { styleText } from 'node:util'
5
5
  import { join, resolve } from 'path'
6
6
 
7
7
  export const options = {
8
- path: {
9
- src: {
10
- templates: resolve(process.cwd(), 'src/templates'),
11
- components: resolve(process.cwd(), 'src/templates/components'),
12
- sections: resolve(process.cwd(), 'src/templates/Sections'),
13
- views: resolve(process.cwd(), 'src/views'),
14
- pages: resolve(process.cwd(), 'src/pages')
15
- },
16
- app: {
17
- templates: resolve(process.cwd(), 'app/Templates'),
18
- components: resolve(process.cwd(), 'app/Components'),
19
- componentsFactory: resolve(process.cwd(), 'app/Components/Factory'),
20
- sections: resolve(process.cwd(), 'app/Sections'),
21
- sectionsFactory: resolve(process.cwd(), 'app/Sections/Factory'),
22
- tempCache: resolve(process.cwd(), 'temp/cache')
23
- }
24
- }
8
+ path: {
9
+ src: {
10
+ templates: resolve(process.cwd(), 'src/templates'),
11
+ components: resolve(process.cwd(), 'src/templates/components'),
12
+ sections: resolve(process.cwd(), 'src/templates/Sections'),
13
+ views: resolve(process.cwd(), 'src/views'),
14
+ pages: resolve(process.cwd(), 'src/pages'),
15
+ },
16
+ app: {
17
+ templates: resolve(process.cwd(), 'app/Templates'),
18
+ components: resolve(process.cwd(), 'app/Components'),
19
+ componentsFactory: resolve(process.cwd(), 'app/Components/Factory'),
20
+ sections: resolve(process.cwd(), 'app/Sections'),
21
+ sectionsFactory: resolve(process.cwd(), 'app/Sections/Factory'),
22
+ tempCache: resolve(process.cwd(), 'temp/cache'),
23
+ },
24
+ },
25
25
  }
26
26
 
27
27
  export default async function cms(action, name) {
28
- if (action === 'prepare') {
29
- await prepare(options).copy(name)
30
- }
31
-
32
- if (action === 'new-component') {
33
- const nameFormatted = name.replaceAll('/', '')
28
+ if (action === 'prepare') {
29
+ await prepare(options).copy(name)
30
+ }
34
31
 
35
- if (fs.existsSync(join(options.path.app.components, `${nameFormatted}.php`))) {
36
- console.log(`${pc.red('')} section ${nameFormatted} already exists`)
37
- process.exit(1)
38
- }
32
+ if (action === 'new-component') {
33
+ const nameFormatted = name.replaceAll('/', '')
39
34
 
40
- prepare(options).writeComponent(name)
41
- prepare(options).writeComponentFactory(nameFormatted)
35
+ if (fs.existsSync(join(options.path.app.components, `${nameFormatted}.php`))) {
36
+ console.log(`${styleText('red', '✖')} section ${nameFormatted} already exists`)
37
+ process.exit(1)
38
+ }
42
39
 
43
- if (fs.existsSync(options.path.app.tempCache)) {
44
- fse.removeSync(options.path.app.tempCache)
45
- }
40
+ prepare(options).writeComponent(name)
41
+ prepare(options).writeComponentFactory(nameFormatted)
46
42
 
47
- console.log(`${pc.green('✔')} component ${nameFormatted} created`)
43
+ if (fs.existsSync(options.path.app.tempCache)) {
44
+ fse.removeSync(options.path.app.tempCache)
48
45
  }
49
46
 
50
- if (action === 'new-section') {
51
- const nameFormatted = name.replaceAll('/', '')
47
+ console.log(`${styleText('green', '')} component ${nameFormatted} created`)
48
+ }
52
49
 
53
- if (fs.existsSync(join(options.path.app.sections, `${nameFormatted}.php`))) {
54
- console.log(`${pc.red('')} section ${nameFormatted} already exists`)
55
- process.exit(1)
56
- }
50
+ if (action === 'new-section') {
51
+ const nameFormatted = name.replaceAll('/', '')
57
52
 
58
- prepare(options).writeSection(name)
59
- prepare(options).writeSectionFactory(nameFormatted)
53
+ if (fs.existsSync(join(options.path.app.sections, `${nameFormatted}.php`))) {
54
+ console.log(`${styleText('red', '✖')} section ${nameFormatted} already exists`)
55
+ process.exit(1)
56
+ }
60
57
 
61
- if (fs.existsSync(options.path.app.tempCache)) {
62
- fse.removeSync(options.path.app.tempCache)
63
- }
58
+ prepare(options).writeSection(name)
59
+ prepare(options).writeSectionFactory(nameFormatted)
64
60
 
65
- console.log(`${pc.green('✔')} section ${nameFormatted} created`)
61
+ if (fs.existsSync(options.path.app.tempCache)) {
62
+ fse.removeSync(options.path.app.tempCache)
66
63
  }
64
+
65
+ console.log(`${styleText('green', '✔')} section ${nameFormatted} created`)
66
+ }
67
67
  }