@leverege/build-tools 2.0.4 → 2.0.6

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/lib/server/pkgck DELETED
@@ -1,136 +0,0 @@
1
- #!/bin/bash
2
-
3
- C_off='\e[0m'
4
- C_yellow='\e[93m'
5
- C_red='\e[101m'
6
- C_green='\e[92m'
7
-
8
- good() {
9
- printf "\e[32m✔${C_off}"
10
- }
11
-
12
- bad() {
13
- printf "\e[31m✘${C_off}"
14
- }
15
-
16
- semver() {
17
- local version=$1
18
- local isSemver=`echo $version | egrep -e "^v\d+\.\d+\.\d+$"`
19
- if [ -z "$version" ];
20
- then
21
- printf "UNTAGGD"
22
- elif [ $isSemver ];
23
- then
24
- printf "$version"
25
- else
26
- printf "!SEMVER"
27
- fi
28
- }
29
-
30
- check_babel () {
31
- local C_stat=$(bad)
32
- [ -f .babelrc ] && grep --silent @babel/plugin-proposal-optional-chaining .babelrc
33
- [ $? -eq 0 ] && C_stat=$(good)
34
- printf $C_stat
35
- }
36
-
37
- check_circle () {
38
- local C_stat=$(bad)
39
- [ -f ".circleci/config.yml" ] && C_stat=$(good)
40
- printf $C_stat
41
- }
42
-
43
- check_eslint () {
44
- local C_stat=$(bad)
45
- [ -f .eslintrc ] && grep --silent @leverege/eslint-config-leverege .eslintrc
46
- [ $? -eq 0 ] && C_stat=$(good)
47
- printf $C_stat
48
- }
49
-
50
- check_license () {
51
- local C_stat=$(bad)
52
- local lic="`node -p \"require('./package.json').scripts.licenseCheck !== undefined\"`"
53
- [ $lic == true ] && C_stat=$(good)
54
- printf $C_stat
55
- }
56
-
57
- # Invoke as: version_ck $GITTAG $NPMVER
58
- #
59
- check_git_version() {
60
- local tag=$1
61
- local pkg=$2
62
- local clr=$C_green
63
-
64
- if [ "$tag" == 'UNTAGGD' ];
65
- then
66
- clr=$C_red
67
- elif [ "$tag" != "$pkg" ];
68
- then
69
- clr=$C_yellow
70
- fi
71
-
72
- printf "$clr$tag$C_off"
73
- }
74
-
75
- check_nodemon() {
76
- nodemon="`getjson --file ./package.json --key nodemon`"
77
- }
78
-
79
- check_scope() {
80
- private="`node -p \"require('./package.json').private == true\"`"
81
- scoped="`getjson --file ./package.json --key name --regex '^@\w{3}'`"
82
- result="${C_red}PUBL${C_off}"
83
- if [[ "$scoped" == "" ]] && [[ "$private" == "true" ]];
84
- then
85
- result="${C_yellow}PRVT"
86
- elif [[ "$scoped" != "" ]];
87
- then
88
- result="${C_green}${scoped}"
89
- elif [[ "$private" == "true" ]];
90
- then
91
- result="${C_green}prv"
92
- fi
93
- printf "${result}${C_off}"
94
- }
95
-
96
- repos=0
97
- check_repo() {
98
- local dir=$1
99
- [ ! -d $dir/.git ] || [ ! -f $dir/package.json ] && return
100
- cd $dir &> /dev/null
101
- local gperrs=0
102
- git pull -q &> /dev/null; [ $? -ne 0 ] && let "gperrs++"
103
- git pull -q --tags &> /dev/null; [ $? -ne 0 ] && let "gperrs++"
104
-
105
- # It is necessary to use the output from printf to set localmods in order
106
- # to get the ANSI escape codes expanded.
107
- local localmods=$(good)
108
- [ $gperrs -ne 0 ] && localmods=$(bad)
109
- pkgver=$(semver "v`node -p \"require('./package.json').version\"`")
110
- gitver=$(semver `git describe --abbrev=0 2>/dev/null`)
111
- [ $? -ne 0 ] && gitver='UNTAGGD'
112
- local needspush=
113
- if [ "$pkgver" == "$gitver" ];
114
- then
115
- git ls-remote --tags origin | grep $gitver &> /dev/null
116
- [ $? -ne 0 ] && needspush='!tags'
117
- fi
118
- local babel7=$(check_babel)
119
- local circle=$(check_circle)
120
- local eslint=$(check_eslint)
121
- local license=$(check_license)
122
- local scoped=$(check_scope)
123
- [ $(( $repos % 15)) -eq 0 ] && printf "\n%35s pkg git cln scop cir lic esl bl7\n"
124
- printf "%32s: %-8s %-16s %s %8s %s %s %s %s %s\n" $dir $pkgver $(check_git_version $gitver $pkgver) $localmods $scoped $circle $license $eslint $babel7 "$needspush"
125
- let "repos++"
126
- cd - &> /dev/null
127
- }
128
-
129
- clear
130
-
131
- pkgs="$@"
132
- for dir in $@; do
133
- check_repo $dir
134
- done
135
-
136
- printf "\ntotal repoitories checked: $repos\n\n"
@@ -1,35 +0,0 @@
1
- #!/bin/bash
2
-
3
- C_off='\e[0m'
4
- C_yellow='\e[93m'
5
-
6
- good() {
7
- printf "\e[32m✔${C_off}"
8
- }
9
-
10
- bad() {
11
- printf "\e[31m✘${C_off}"
12
- }
13
-
14
- check_file() {
15
- local C_stat=$(bad)
16
- local filename=$1
17
-
18
- if [ -f $filename ]; then
19
- C_stat=$(good)
20
- printf "$C_stat $filename\n"
21
- else
22
- printf "$C_stat $filename is missing\n\n"
23
- printf "${C_yellow} Please create $filename before pushing to prod\n\n"
24
- exit 1
25
- fi
26
- }
27
-
28
- printf "\nChecking repo for markdown files\n\n"
29
-
30
- files=( README.md LICENSE.md )
31
- for file in ${files[@]}; do
32
- check_file $file
33
- done
34
-
35
- printf "\nAll required files exist\n\n"
@@ -1,4 +0,0 @@
1
- {
2
- "name": "@leverege/packagename",
3
- "main": "lib/index.js"
4
- }
@@ -1,99 +0,0 @@
1
- const ora = require( 'ora' )
2
- const fs = require( 'fs' )
3
- const path = require( 'path' )
4
- const { promisify } = require( 'util' )
5
-
6
- class CloudflareAPI {
7
- constructor( options ) {
8
- const { args } = options
9
- const { url, proxy, ipaddress, account } = args
10
-
11
- this.url = url
12
- this.proxy = proxy
13
- this.ipaddress = ipaddress
14
- this.spinner = ora( { text : 'Creating DNS record...', spinner : 'monkey' } )
15
- this.account = account
16
- }
17
-
18
- async decrypt(
19
- projectId = 'leverege-docker-images',
20
- keyRingId = 'build-tools',
21
- cryptoKeyId = 'circle-ci',
22
- ciphertextFileName = './accounts.json.enc',
23
- plaintextFileName = './accounts.json'
24
- ) {
25
-
26
- // Import the library and create a client
27
- const kms = require( '@google-cloud/kms' )
28
- const client = new kms.KeyManagementServiceClient()
29
-
30
- // The location of the crypto key's key ring, e.g. "global"
31
- const locationId = 'us-east4'
32
-
33
- // Reads the file to be decrypted
34
- const readFile = promisify( fs.readFile );
35
- const contentsBuffer = await readFile( path.resolve( __dirname, ciphertextFileName ) )
36
- const name = client.cryptoKeyPath(
37
- projectId,
38
- locationId,
39
- keyRingId,
40
- cryptoKeyId
41
- );
42
- const ciphertext = contentsBuffer.toString( 'base64' )
43
-
44
- // Decrypts the file using the specified crypto key
45
- const [ result ] = await client.decrypt( { name, ciphertext } )
46
-
47
- // Writes the decrypted file to disk
48
- const writeFile = promisify( fs.writeFile )
49
- await writeFile( path.resolve( __dirname, plaintextFileName ), Buffer.from( result.plaintext, 'base64' ) )
50
- }
51
-
52
- setAccountValues() {
53
- const accountJson = require( path.resolve( __dirname, './accounts.json' ) )
54
- const accountInfo = accountJson[this.account]
55
- const { email, key, zone } = accountInfo
56
-
57
- this.cf = require( 'cloudflare' )( {
58
- email,
59
- key
60
- } )
61
- this.zone = zone
62
- }
63
-
64
- async deleteSecrets() {
65
- const deleteFile = promisify( fs.unlink )
66
- await deleteFile( path.resolve( __dirname, './accounts.json' ) )
67
- }
68
-
69
- async createDNSRecord() {
70
- try {
71
- this.spinner.start()
72
-
73
- this.spinner.text = 'Decrypting Cloudflare secrets...'
74
- await this.decrypt()
75
-
76
- this.spinner.text = 'Initializing Cloudflare API...'
77
- this.setAccountValues()
78
-
79
- this.spinner.text = 'Adding A name record...'
80
- await this.cf.dnsRecords.add( this.zone,
81
- { type : 'A',
82
- name : this.url,
83
- content : this.ipaddress,
84
- proxied : this.proxy
85
- } )
86
-
87
- this.spinner.text = 'Removing secrets...'
88
- await this.deleteSecrets()
89
-
90
- this.spinner.stop()
91
- } catch ( ex ) {
92
- this.spinner.stop()
93
- console.log( ex )
94
- throw ex
95
- }
96
- }
97
- }
98
-
99
- module.exports = CloudflareAPI
Binary file
@@ -1,82 +0,0 @@
1
- #!/usr/bin/env node
2
- const commandLineArgs = require( 'command-line-args' )
3
- const commandLineUsage = require( 'command-line-usage' )
4
- const Cloudflare = require( './CloudflareAPI' )
5
-
6
- const defaultConfig = {
7
- account : 'leverege',
8
- proxy : true
9
- }
10
-
11
- const sections = [
12
- {
13
- content : 'Wraps Cloudflare to modify DNS configs for new UI/Servers'
14
- },
15
- {
16
- header : 'Options',
17
- optionList : [
18
- {
19
- name : 'account',
20
- alias : 'a',
21
- description : 'Cloudflare account to use'
22
- },
23
- {
24
- name : 'ipaddress',
25
- alias : 'i',
26
- description : 'IP address to point DNS account to (e.g. 35.178.29.10)'
27
- },
28
- {
29
- name : 'url',
30
- alias : 'u',
31
- description : 'URL name (e.g. myserver)'
32
- },
33
- {
34
- name : 'proxy',
35
- alias : 'p',
36
- description : 'Turn on Cloudflare proxy (optional)'
37
- },
38
- {
39
- name : 'help',
40
- description : 'Print this usage guide.'
41
- }
42
- ]
43
- }
44
- ]
45
-
46
- const usage = commandLineUsage( sections )
47
-
48
- const optionDefinitions = [
49
- { name : 'account', alias : 'a', type : String, defaultValue : defaultConfig.account },
50
- { name : 'ipaddress', alias : 'i', type : String },
51
- { name : 'url', alias : 'u', type : String },
52
- { name : 'proxy', alias : 'p', type : Boolean, defaultValue : defaultConfig.proxy },
53
- { name : 'help', alias : 'h', type : Boolean }
54
- ]
55
-
56
- const args = commandLineArgs( optionDefinitions )
57
-
58
- async function main() {
59
- if ( args.help ) {
60
- console.log( usage )
61
- }
62
-
63
- if ( !args.url || !args.ipaddress ) {
64
- console.log( '\n*******************************************' )
65
- console.log( '** **' )
66
- console.log( '** Need to specify URL and/or IP address **' )
67
- console.log( '** **' )
68
- console.log( '*******************************************' )
69
- console.log( usage )
70
- } else {
71
- const CF = new Cloudflare( { ...defaultConfig, args } )
72
- try {
73
- await CF.createDNSRecord()
74
- console.log( 'Successfully created a new DNS record' )
75
- console.log( 'It may take a few minutes for DNS to propagate' )
76
- } catch ( ex ) {
77
- console.error( ex.message )
78
- }
79
- }
80
- }
81
-
82
- main()
@@ -1,281 +0,0 @@
1
- const exec = require( 'child_process' ).exec
2
- const fs = require( 'fs-extra' )
3
- const path = require( 'path' )
4
- const async = require( 'async' )
5
- const copy = require( 'recursive-copy' )
6
- const ora = require( 'ora' )
7
- const tar = require( 'tar' )
8
- const semver = require( 'semver' )
9
-
10
-
11
- class Packleator {
12
-
13
- static PRIVATE_PACKAGES_DIRECTORY = 'private_packages'
14
-
15
- constructor( options ) {
16
- const { args } = options
17
- this.privatePackages = new Set()
18
-
19
- this.args = args ? {
20
- ...args,
21
- output : args.output.substr( -1 ) === '/' ? args.output.substr( 0, args.output.length ) : args.output
22
- } : {} // args || {}
23
- this.spinner = ora( { text : 'Installing NPM dependencies...', spinner : 'monkey' } )
24
- this.stderr = ''
25
-
26
- this.tarredVersions = {}
27
-
28
- this.outputPackageJson = {}
29
- this.outputPackageLockJson = {}
30
- }
31
-
32
- async run() {
33
- try {
34
- this.spinner.start()
35
- await this.npmInstall()
36
-
37
- this.spinner.text = 'Copying files...'
38
- await this.copyFiles()
39
-
40
- process.chdir( this.args.output )
41
-
42
- this.outputPackageJson = await this.getPackageJson()
43
- this.outputPackageLockJson = await this.getPackageJson( undefined, true )
44
-
45
- this.spinner.text = 'Parsing private dependencies...'
46
- const deps = await this.getPrivateDeps()
47
-
48
- this.spinner.text = 'Packaging modules...'
49
- async.eachOfSeries( deps, ( item, key, callback ) => {
50
-
51
- if( this.args.verbose ) {
52
- console.log( item )
53
- }
54
- this.getPackageJson( item ).then((packageJson) => {
55
- const { name, version } = packageJson
56
-
57
- this.pack( name, version, item ).then(() => {
58
- callback()
59
- })
60
- })
61
- }, async ( err ) => {
62
- await this.rebuildPackageJson()
63
- await this.rebuildPackageLockJson()
64
-
65
- await fs.writeFile( 'package.json', JSON.stringify( this.outputPackageJson, null, 2 ) )
66
- await fs.writeFile( 'package-lock.json', JSON.stringify( this.outputPackageLockJson, null, 2 ) )
67
-
68
- await fs.remove( 'node_modules' )
69
-
70
- const { name, version } = this.outputPackageJson
71
- const fileName = `${name.replace( '@', '' ).replace( '/', '-' )}-${version}.tgz`
72
-
73
- process.chdir( '..' )
74
-
75
- this.spinner.text = 'Packaging results...'
76
- await tar.c( {
77
- file : fileName,
78
- strict : true,
79
- prefix : 'package/',
80
- C : this.args.output
81
- }, [ '.' ] )
82
-
83
- this.spinner.text = 'Cleaning up...'
84
- await this.cleanup()
85
-
86
- this.spinner.stop()
87
- } )
88
- } catch ( ex ) {
89
- this.spinner.stop()
90
- throw ex
91
- }
92
- }
93
-
94
- async rebuildPackageJson() {
95
- const packageJson = this.outputPackageJson
96
- const tarredPackages = Object.keys( this.tarredVersions )
97
- const { dependencies = {}, devDependencies = {} } = packageJson
98
-
99
- tarredPackages.forEach( ( tarredPackage ) => {
100
- if ( dependencies[tarredPackage] ) {
101
- const version = semver.maxSatisfying( this.tarredVersions[tarredPackage], dependencies[tarredPackage] )
102
-
103
- if ( version != null ) {
104
- packageJson.dependencies[tarredPackage] = `file:${Packleator.PRIVATE_PACKAGES_DIRECTORY}${path.sep}${tarredPackage.replace( '@', '' ).replace( '/', '-' )}-${version}.tgz`
105
- }
106
- }
107
-
108
- if ( devDependencies[tarredPackage] ) {
109
- const version = semver.maxSatisfying( this.tarredVersions[tarredPackage], devDependencies[tarredPackage] )
110
-
111
- if ( version != null ) {
112
- packageJson.devDependencies[tarredPackage] = `file:${Packleator.PRIVATE_PACKAGES_DIRECTORY}${path.sep}${tarredPackage.replace( '@', '' ).replace( '/', '-' )}-${version}.tgz`
113
- }
114
- }
115
- } )
116
-
117
- }
118
-
119
- async rebuildPackageLockJson() {
120
- const packageLockJson = this.outputPackageLockJson
121
- const tarredPackages = Object.keys( this.tarredVersions )
122
-
123
- const recurseDeps = ( deps ) => {
124
- Object
125
- .keys( deps )
126
- .forEach( ( key ) => {
127
- const dep = deps[key]
128
-
129
- tarredPackages.forEach( ( tarredPackage ) => {
130
- if ( key === tarredPackage ) {
131
- dep.version = `file:${Packleator.PRIVATE_PACKAGES_DIRECTORY}${path.sep}${key.replace( '@', '' ).replace( '/', '-' )}-${dep.version}.tgz`
132
- delete dep.resolved
133
- delete dep.integrity
134
- }
135
-
136
- if ( dep.requires && dep.requires[tarredPackage] ) {
137
- delete dep.requires[tarredPackage]
138
- }
139
- } )
140
-
141
- if ( dep.dependencies ) {
142
- recurseDeps( dep.dependencies )
143
- }
144
- } )
145
- }
146
-
147
- recurseDeps( packageLockJson.dependencies )
148
- }
149
-
150
- async copyFiles() {
151
- const startsWith = new RegExp( `^(dist|lib|image|package|${this.args.output})` )
152
- const endsWith = /\.tgz$/
153
- await fs.remove( this.args.output )
154
- await fs.mkdirp( this.args.output )
155
- await copy( '.', this.args.output, {
156
- overwrite : true,
157
- dot : true,
158
- filter : ( item ) => {
159
- if ( item === 'package.json' || item === 'package-lock.json' ) {
160
- return true
161
- }
162
-
163
- if ( startsWith.test( item ) || endsWith.test( item ) ) {
164
- return false
165
- }
166
-
167
- if ( item.startsWith( '.' ) && item.indexOf( '.babelrc' ) === -1 ) {
168
- return false
169
- }
170
-
171
- if ( this.args.ignore.length > 0 ) {
172
- return this.args.ignore.indexOf( item ) === -1
173
- }
174
-
175
- return true
176
- }
177
- } )
178
- }
179
-
180
- async pack( name, version, dir ) {
181
- const fileName = `${name.replace( '@', '' ).replace( '/', '-' )}-${version}.tgz`
182
-
183
- await tar.c( {
184
- file : fileName,
185
- C : dir,
186
- strict : true,
187
- prefix : 'package/'
188
- }, [ '.' ] )
189
-
190
- await fs.move( path.join( process.cwd(), fileName ), path.join( process.cwd(), Packleator.PRIVATE_PACKAGES_DIRECTORY, fileName ), { overwrite : true } )
191
-
192
- if ( this.tarredVersions[name] ) {
193
- this.tarredVersions[name].push( version )
194
- } else {
195
- this.tarredVersions[name] = [ version ]
196
- }
197
-
198
- if( this.args.verbose ) {
199
- console.log( fileName )
200
- }
201
- return fileName
202
- }
203
-
204
- async cleanup() {
205
- await copy( this.args.output, process.cwd(), {
206
- overwrite : true,
207
- filter : '*.tgz'
208
- } )
209
- await fs.remove( this.args.output )
210
- }
211
-
212
- async npmInstall( dir = process.cwd() ) {
213
- const currentDir = process.cwd()
214
-
215
- return new Promise( ( resolve, reject ) => {
216
- if ( currentDir !== dir ) {
217
- process.chdir( dir )
218
- }
219
-
220
- const npmInstall = exec( 'npm install' )
221
-
222
- npmInstall
223
- .stderr
224
- .on( 'data', ( data ) => {
225
- this.stderr += data.toString()
226
- } )
227
-
228
- npmInstall.on( 'exit', ( code ) => {
229
- if ( currentDir !== dir ) {
230
- process.chdir( currentDir )
231
- }
232
- resolve()
233
- } )
234
-
235
- npmInstall.on( 'error', ( err ) => {
236
- if ( currentDir !== dir ) {
237
- process.chdir( currentDir )
238
- }
239
- reject( err )
240
- } )
241
- } )
242
- }
243
-
244
- async getPrivateDeps( depth ) {
245
- return new Promise( ( resolve, reject ) => {
246
-
247
- const depthArg = depth != null ? ` --depth ${depth}` : ''
248
- exec( `npm ls --parseable --silent${depthArg}`, ( err, stdout, stderr ) => {
249
- if ( err && !stdout ) {
250
- reject( err )
251
- return
252
- }
253
-
254
- const dependencies = stdout.split( '\n' )
255
-
256
- if ( dependencies ) {
257
- resolve( dependencies.filter( ( item ) => {
258
- const parts = item.split( path.sep )
259
- return this.args.namespaces.indexOf( parts[parts.length - 2] ) !== -1
260
- } ) )
261
- } else {
262
- reject( new Error( 'Unable to resolve package.json dependencies' ) )
263
- }
264
- } )
265
- } )
266
- }
267
-
268
- async getPackageJson( dir = process.cwd(), lock = false ) {
269
- const lockModifier = lock ? '-lock' : ''
270
- try {
271
- const file = await fs.readFile( path.join( dir, `package${lockModifier}.json` ), 'utf-8' )
272
- const json = JSON.parse( file )
273
-
274
- return json
275
- } catch ( ex ) {
276
- throw new Error( 'Error getting package.json. Make sure the current directory contains a valid package.json file' )
277
- }
278
- }
279
- }
280
-
281
- module.exports = Packleator