wp-advads 1.0.7 → 1.0.9
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 +1 -1
- package/src/app.js +16 -27
- package/src/commands/backup/index.js +11 -7
- package/src/commands/file/create-file.js +96 -0
- package/src/commands/file/index.js +29 -0
- package/src/commands/help/index.js +11 -4
- package/src/commands/index.js +5 -0
- package/src/commands/release/change-version.js +124 -0
- package/src/commands/release/changelog.js +259 -0
- package/src/commands/release/composer.js +37 -0
- package/src/commands/release/git.js +119 -0
- package/src/commands/release/github.js +62 -0
- package/src/commands/release/index.js +41 -45
- package/src/commands/release/prompts.js +59 -0
- package/src/commands/release/semver.js +198 -0
- package/src/commands/release/translations.js +66 -0
- package/src/commands/setup/create-plugin.js +213 -170
- package/src/commands/setup/index.js +2 -2
- package/src/commands/setup/prompts.js +15 -17
- package/src/utilities/cache.js +23 -0
- package/src/utilities/command.js +29 -0
- package/src/utilities/file.js +57 -0
- package/src/utilities/folder.js +64 -0
- package/src/utilities/formatting.js +97 -0
- package/src/utilities/index.js +6 -0
- package/src/utilities/shell.js +36 -0
- package/template/configs/.eslintignore +4 -1
- package/template/configs/.gitattributes +33 -0
- package/template/configs/{.phpcs.xml → .phpcs.xml.dist} +1 -0
- package/template/configs/.prettierignore +2 -0
- package/template/configs/.stylelintrc +19 -5
- package/template/configs/package.json +2 -2
- package/template/configs/webpack.mix.js +4 -3
- package/template/make/file-singleton.php +43 -0
- package/template/make/file.php +26 -0
- package/template/tools/laravel-mix/wp-pot.js +40 -28
- package/template/tools/wp-glotpress.js +125 -103
- package/src/helpers.js +0 -135
- package/template/.husky/pre-commit +0 -4
- package/template/configs/gitattributes +0 -25
- package/template/configs/gitignore +0 -38
- package/template/configs/webpack.mix.local.js +0 -3
- /package/template/{assets → plugin/assets/scss}/app.scss +0 -0
- /package/template/{assets → plugin/assets/src}/app.js +0 -0
|
@@ -4,181 +4,224 @@
|
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
import chalk from 'chalk'
|
|
6
6
|
import Handlebars from 'handlebars'
|
|
7
|
-
import {
|
|
7
|
+
import { eachSeries, waterfall } from 'async'
|
|
8
|
+
|
|
9
|
+
export const pluginData = {}
|
|
8
10
|
|
|
9
11
|
/**
|
|
10
12
|
* Internal dependencies
|
|
11
13
|
*/
|
|
12
|
-
import { getCurrentFolder,
|
|
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
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
14
|
+
import { getCurrentFolder, getTemplateFolder, heading, write, msgSuccessOnSameLine, execCommand } from '../../utilities/index.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Helper functions
|
|
18
|
+
*/
|
|
19
|
+
function prepareFile( src, dest, next ) {
|
|
20
|
+
const content = fs.readFileSync( src, 'utf8' )
|
|
21
|
+
const template = Handlebars.compile( content )
|
|
22
|
+
const rendered = template( pluginData.settings )
|
|
23
|
+
|
|
24
|
+
fs.outputFile( dest, rendered ).then( next )
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Flow functions
|
|
29
|
+
*/
|
|
30
|
+
function setPluginData(next) {
|
|
31
|
+
pluginData.folder = getCurrentFolder()
|
|
32
|
+
pluginData.template = getTemplateFolder()
|
|
33
|
+
|
|
34
|
+
pluginData.dirs = [
|
|
35
|
+
// Root
|
|
36
|
+
pluginData.folder,
|
|
37
|
+
pluginData.folder + '/languages',
|
|
38
|
+
pluginData.folder + '/templates',
|
|
39
|
+
|
|
40
|
+
// Assets
|
|
41
|
+
pluginData.folder + '/assets/css',
|
|
42
|
+
pluginData.folder + '/assets/scss',
|
|
43
|
+
pluginData.folder + '/assets/js',
|
|
44
|
+
pluginData.folder + '/assets/src',
|
|
45
|
+
pluginData.folder + '/assets/img',
|
|
46
|
+
pluginData.folder + '/assets/acf',
|
|
47
|
+
|
|
48
|
+
// Includes
|
|
49
|
+
pluginData.folder + '/includes',
|
|
50
|
+
pluginData.folder + '/includes/abstracts',
|
|
51
|
+
pluginData.folder + '/includes/admin',
|
|
52
|
+
pluginData.folder + '/includes/database',
|
|
53
|
+
pluginData.folder + '/includes/interfaces',
|
|
54
|
+
pluginData.folder + '/includes/models',
|
|
55
|
+
pluginData.folder + '/includes/traits',
|
|
56
|
+
pluginData.folder + '/includes/utilities',
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
next()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function createDirectories(next) {
|
|
63
|
+
const indexFile = pluginData.template + '/index.php'
|
|
64
|
+
|
|
65
|
+
write('Creating directory required for the plugin...')
|
|
66
|
+
|
|
67
|
+
eachSeries( pluginData.dirs, ( dir, nextDir ) => {
|
|
68
|
+
fs.ensureDir( dir ).then(() => {
|
|
69
|
+
fs.copy( indexFile, dir + '/index.php' ).then( nextDir )
|
|
70
|
+
})
|
|
71
|
+
}, () => {
|
|
72
|
+
msgSuccessOnSameLine(`${pluginData.dirs.length} directories created`)
|
|
73
|
+
next()
|
|
74
|
+
} )
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function copyToolFiles(next) {
|
|
78
|
+
write('Copying tools files...')
|
|
79
|
+
fs.copySync(
|
|
80
|
+
pluginData.template + '/tools',
|
|
81
|
+
pluginData.folder + '/tools',
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
msgSuccessOnSameLine('Tool files copied')
|
|
85
|
+
next()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function prepareConfigFiles(next) {
|
|
89
|
+
const template = pluginData.template + '/configs'
|
|
90
|
+
const files =[
|
|
91
|
+
'/.editorconfig',
|
|
92
|
+
'/.eslintignore',
|
|
93
|
+
'/.eslintrc.js',
|
|
94
|
+
'/.gitattributes',
|
|
95
|
+
'/.gitignore',
|
|
96
|
+
'/.phpcs.xml.dist',
|
|
97
|
+
'/.prettierignore',
|
|
98
|
+
'/.prettierrc.js',
|
|
99
|
+
'/.stylelintrc',
|
|
100
|
+
'/composer.json',
|
|
101
|
+
'/package.json',
|
|
102
|
+
'/webpack.mix.js',
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
write('Preparing configuration files...')
|
|
106
|
+
|
|
107
|
+
eachSeries( files, ( file, nextConfig ) => {
|
|
108
|
+
prepareFile( template + file, pluginData.folder + file, nextConfig )
|
|
109
|
+
}, () => {
|
|
110
|
+
msgSuccessOnSameLine(`${files.length} Configuration files prepared`)
|
|
111
|
+
next()
|
|
112
|
+
} )
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
function preparePluginFiles(next) {
|
|
116
|
+
const template = pluginData.template + '/plugin'
|
|
117
|
+
const files =[
|
|
118
|
+
'/assets/src/app.js',
|
|
119
|
+
'/assets/scss/app.scss',
|
|
120
|
+
// '/includes/admin/class-admin.php',
|
|
121
|
+
// '/includes/interfaces/interface-integration.php',
|
|
122
|
+
// '/includes/class-assets.php',
|
|
123
|
+
// '/includes/class-frontend.php',
|
|
124
|
+
// '/includes/class-plugin.php',
|
|
125
|
+
// '/plugin.php',
|
|
126
|
+
// '/uninstall.php',
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
write('Preparing plugin files...')
|
|
130
|
+
|
|
131
|
+
eachSeries( files, ( file, nextFile ) => {
|
|
132
|
+
prepareFile( template + file, pluginData.folder + file, nextFile )
|
|
133
|
+
}, () => {
|
|
134
|
+
msgSuccessOnSameLine(`${files.length} plugin files created with settings`)
|
|
135
|
+
next()
|
|
136
|
+
} )
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function prepareGitRepository(next) {
|
|
140
|
+
write( 'Checking GIT repo' )
|
|
141
|
+
execCommand('git rev-parse --is-inside-work-tree && echo "OK" || git init', function() {
|
|
142
|
+
msgSuccessOnSameLine('Git repository initiated successfully')
|
|
143
|
+
next()
|
|
144
|
+
})
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function installComposer(next) {
|
|
148
|
+
heading('Composer')
|
|
149
|
+
write('Installing Composer...')
|
|
150
|
+
execCommand('composer install -q', function() {
|
|
151
|
+
msgSuccessOnSameLine('Composer installed successfully')
|
|
152
|
+
next()
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function installNodePackages(next) {
|
|
157
|
+
const packages =[
|
|
158
|
+
'@wordpress/eslint-plugin',
|
|
159
|
+
'@wordpress/stylelint-config',
|
|
160
|
+
'async',
|
|
161
|
+
'browser-sync',
|
|
162
|
+
'browser-sync-webpack-plugin',
|
|
163
|
+
'chalk@4.1.2',
|
|
164
|
+
'eslint-plugin-prettier',
|
|
165
|
+
'husky',
|
|
166
|
+
'laravel-mix',
|
|
167
|
+
'lint-staged',
|
|
168
|
+
'prettier',
|
|
169
|
+
'resolve-url-loader',
|
|
170
|
+
'sass',
|
|
171
|
+
'sass-loader',
|
|
172
|
+
'shelljs',
|
|
173
|
+
'tailwindcss',
|
|
174
|
+
'webpack',
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
heading( 'Node Packages' )
|
|
178
|
+
|
|
179
|
+
eachSeries( packages, ( pkg, nextPackage ) => {
|
|
180
|
+
write( chalk.red( 'Installing ' + pkg ) )
|
|
181
|
+
execCommand(`npm install -D ${pkg}`, function() {
|
|
182
|
+
msgSuccessOnSameLine(`Package: ${pkg} installed successfully`)
|
|
183
|
+
nextPackage()
|
|
184
|
+
})
|
|
185
|
+
}, () => {
|
|
186
|
+
next()
|
|
187
|
+
} )
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function prepareNodePackages(next) {
|
|
191
|
+
write( 'Adding Pre-Commit' )
|
|
192
|
+
|
|
193
|
+
execCommand('npm run prepare', function() {
|
|
194
|
+
execCommand('npx husky add .husky/pre-commit "npx lint-staged"', function() {
|
|
195
|
+
msgSuccessOnSameLine('Pre-Commit hooks added successfully')
|
|
196
|
+
next()
|
|
197
|
+
})
|
|
198
|
+
})
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
export default ( settings, next ) => {
|
|
182
|
-
|
|
183
|
-
|
|
202
|
+
pluginData.settings = settings
|
|
203
|
+
|
|
204
|
+
console.log('');
|
|
205
|
+
heading('Scaffoling plugin...')
|
|
206
|
+
|
|
207
|
+
waterfall(
|
|
208
|
+
[
|
|
209
|
+
setPluginData,
|
|
210
|
+
createDirectories,
|
|
211
|
+
copyToolFiles,
|
|
212
|
+
prepareConfigFiles,
|
|
213
|
+
preparePluginFiles,
|
|
214
|
+
prepareGitRepository,
|
|
215
|
+
installComposer,
|
|
216
|
+
installNodePackages,
|
|
217
|
+
prepareNodePackages
|
|
218
|
+
],
|
|
219
|
+
(err) => {
|
|
220
|
+
if (err) {
|
|
221
|
+
return next(true)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
next()
|
|
225
|
+
}
|
|
226
|
+
)
|
|
184
227
|
}
|
|
@@ -8,11 +8,11 @@ import logSymbols from 'log-symbols'
|
|
|
8
8
|
/**
|
|
9
9
|
* Internal Dependencies
|
|
10
10
|
*/
|
|
11
|
-
import { heading } from "../../
|
|
11
|
+
import { heading } from "../../utilities/index.js"
|
|
12
12
|
import prompts from './prompts.js'
|
|
13
13
|
import createPlugin from './create-plugin.js'
|
|
14
14
|
|
|
15
|
-
export function
|
|
15
|
+
export default function() {
|
|
16
16
|
heading('Setting up...')
|
|
17
17
|
console.log('');
|
|
18
18
|
|
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import inquirer from 'inquirer'
|
|
5
4
|
import get from 'lodash/get.js'
|
|
5
|
+
import inquirer from 'inquirer'
|
|
6
6
|
import kebabCase from 'lodash/kebabCase.js'
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Node dependencies
|
|
10
10
|
*/
|
|
11
|
-
import { getCacheStore } from '../../
|
|
11
|
+
import { getCacheStore, getSettings, heading } from '../../utilities/index.js'
|
|
12
12
|
|
|
13
13
|
export default ( next ) => {
|
|
14
14
|
const cache = getCacheStore()
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const getCache = ( key, defaultVal = '' ) => get( saved, key, defaultVal )
|
|
15
|
+
const settings = getSettings()
|
|
16
|
+
const getAnswer = ( key, defaultVal = '' ) => get( settings, key, defaultVal )
|
|
19
17
|
|
|
20
18
|
const questions = [
|
|
21
19
|
// Company
|
|
@@ -23,13 +21,13 @@ export default ( next ) => {
|
|
|
23
21
|
type: 'input',
|
|
24
22
|
name: 'company.name',
|
|
25
23
|
message: 'Enter company name',
|
|
26
|
-
default:
|
|
24
|
+
default: getAnswer( 'company.name','Advanced Ads' ),
|
|
27
25
|
},
|
|
28
26
|
{
|
|
29
27
|
type: 'input',
|
|
30
28
|
name: 'company.url',
|
|
31
29
|
message: 'Enter company website url',
|
|
32
|
-
default:
|
|
30
|
+
default: getAnswer( 'company.url', 'https://wpadvancedads.com/' ),
|
|
33
31
|
filter: ( val ) => val.toLowerCase()
|
|
34
32
|
},
|
|
35
33
|
|
|
@@ -38,20 +36,20 @@ export default ( next ) => {
|
|
|
38
36
|
type: 'input',
|
|
39
37
|
name: 'author.name',
|
|
40
38
|
message: 'Enter author name',
|
|
41
|
-
default:
|
|
39
|
+
default: getAnswer( 'author.name', 'Advanced Ads' ),
|
|
42
40
|
},
|
|
43
41
|
{
|
|
44
42
|
type: 'input',
|
|
45
43
|
name: 'author.email',
|
|
46
44
|
message: 'Enter author email',
|
|
47
|
-
default:
|
|
45
|
+
default: getAnswer( 'author.email', 'info@wpadvancedads.com' ),
|
|
48
46
|
filter: ( val ) => val.toLowerCase()
|
|
49
47
|
},
|
|
50
48
|
{
|
|
51
49
|
type: 'input',
|
|
52
50
|
name: 'author.url',
|
|
53
51
|
message: 'Enter author website url',
|
|
54
|
-
default:
|
|
52
|
+
default: getAnswer( 'author.url', 'https://wpadvancedads.com' ),
|
|
55
53
|
filter: ( val ) => val.toLowerCase()
|
|
56
54
|
},
|
|
57
55
|
|
|
@@ -60,33 +58,33 @@ export default ( next ) => {
|
|
|
60
58
|
type: 'input',
|
|
61
59
|
name: 'wp.textDomain',
|
|
62
60
|
message: 'Enter text domain for i18n',
|
|
63
|
-
default:
|
|
61
|
+
default: getAnswer( 'wp.textDomain' ),
|
|
64
62
|
filter: ( val ) => val.toLowerCase()
|
|
65
63
|
},
|
|
66
64
|
{
|
|
67
65
|
type: 'input',
|
|
68
66
|
name: 'wp.version',
|
|
69
67
|
message: 'Enter plugin version',
|
|
70
|
-
default:
|
|
68
|
+
default: getAnswer( 'version', '1.0.0' ),
|
|
71
69
|
filter: ( val ) => val.toLowerCase()
|
|
72
70
|
},
|
|
73
71
|
{
|
|
74
72
|
type: 'input',
|
|
75
73
|
name: 'wp.name',
|
|
76
74
|
message: 'Enter plugin name',
|
|
77
|
-
default:
|
|
75
|
+
default: getAnswer( 'wp.name' ),
|
|
78
76
|
},
|
|
79
77
|
{
|
|
80
78
|
type: 'input',
|
|
81
79
|
name: 'wp.description',
|
|
82
80
|
message: 'Enter plugin description',
|
|
83
|
-
default:
|
|
81
|
+
default: getAnswer( 'wp.description' ),
|
|
84
82
|
},
|
|
85
83
|
{
|
|
86
84
|
type: 'input',
|
|
87
85
|
name: 'wp.proxy',
|
|
88
86
|
message: 'Enter wordpress installation url',
|
|
89
|
-
default:
|
|
87
|
+
default: getAnswer( 'wp.proxy' ),
|
|
90
88
|
},
|
|
91
89
|
|
|
92
90
|
// PHP
|
|
@@ -94,7 +92,7 @@ export default ( next ) => {
|
|
|
94
92
|
type: 'input',
|
|
95
93
|
name: 'php.package',
|
|
96
94
|
message: 'Enter php package attribute',
|
|
97
|
-
default:
|
|
95
|
+
default: getAnswer( 'php.package' ),
|
|
98
96
|
filter: ( val ) => val.replace( / /g, '' )
|
|
99
97
|
},
|
|
100
98
|
]
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import flatCache from 'flat-cache'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal Dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { getRootFolder } from './folder.js'
|
|
10
|
+
|
|
11
|
+
export const CACHE_FILE = 'adv-ads-scaffolding'
|
|
12
|
+
|
|
13
|
+
export function getCacheStore() {
|
|
14
|
+
return flatCache.load( CACHE_FILE, getRootFolder() )
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function getSettings() {
|
|
18
|
+
const cache = getCacheStore()
|
|
19
|
+
let saved = cache.all()
|
|
20
|
+
saved = saved ? saved.answers : {}
|
|
21
|
+
|
|
22
|
+
return saved
|
|
23
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Dependencies
|
|
3
|
+
*/
|
|
4
|
+
import argv from 'yargs-parser'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Get arguments
|
|
8
|
+
*
|
|
9
|
+
* @returns {Array} arguments
|
|
10
|
+
*/
|
|
11
|
+
export function getArguments() {
|
|
12
|
+
return argv( process.argv.slice( 2 ) )
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Get command with arguments
|
|
17
|
+
*
|
|
18
|
+
* @returns {Object} command and arguments
|
|
19
|
+
*/
|
|
20
|
+
export function getCommand() {
|
|
21
|
+
const args = getArguments()
|
|
22
|
+
const { _, ...rest } = args
|
|
23
|
+
const command = _[0] || 'help'
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
command,
|
|
27
|
+
args: rest || []
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import logSymbols from 'log-symbols'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Node dependencies
|
|
9
|
+
*/
|
|
10
|
+
import fs from 'fs'
|
|
11
|
+
import { onSameLine } from './formatting.js'
|
|
12
|
+
|
|
13
|
+
export function backupFile(name, file) {
|
|
14
|
+
if ( ! fs.existsSync(file) ) {
|
|
15
|
+
console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
|
|
16
|
+
return
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fs.renameSync(
|
|
20
|
+
file,
|
|
21
|
+
file + '.bak'
|
|
22
|
+
)
|
|
23
|
+
console.log( `${logSymbols.success} ${chalk.dim(`${name} backed up!`)}` )
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function deleteFile(name, file) {
|
|
27
|
+
if ( ! fs.existsSync(file) ) {
|
|
28
|
+
console.log( `${logSymbols.error} ${chalk.red(`${name} file not found!`)}` )
|
|
29
|
+
return
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fs.rmSync(file)
|
|
33
|
+
console.log( `${logSymbols.success} ${chalk.dim(`${name} deleted!`)}` )
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function updateFileContent(fileName, messages, next, callback) {
|
|
37
|
+
process.stdout.write(messages.updating)
|
|
38
|
+
|
|
39
|
+
fs.readFile(fileName, (err, buffer) => {
|
|
40
|
+
if ( null !== err ) {
|
|
41
|
+
onSameLine(`${logSymbols.error} ${messages.failed}`)
|
|
42
|
+
return next(true)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const content = callback(buffer.toString())
|
|
46
|
+
|
|
47
|
+
fs.writeFile(fileName, content, (err) => {
|
|
48
|
+
if ( null !== err ) {
|
|
49
|
+
onSameLine(`${logSymbols.error} ${messages.failed}`)
|
|
50
|
+
return next(true)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
onSameLine(`${logSymbols.success} ${messages.updated}`)
|
|
54
|
+
next()
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
}
|