-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPackagePublishCommand.imba
More file actions
87 lines (61 loc) · 2.51 KB
/
PackagePublishCommand.imba
File metadata and controls
87 lines (61 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
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
import { Command } from '../Command'
import { copySync } from 'fs-extra'
import { existsSync } from 'fs-extra'
import { isString } from '../../../Support/Helpers'
import { join } from 'path'
import { Prop } from '@formidablejs/console'
import { readFileSync } from 'fs-extra'
export class PackagePublishCommand < Command
get signature
'package:publish {--package} {--tag} {?--force}'
get description
'Install Formidable package'
get props
{
package: Prop.string!.description 'Package name'
tag: Prop.string!.description 'Assets you want to publish'
force: Prop.boolean!.default(false).description 'Overwrite any existing files'
}
get package
join process.cwd!, 'node_modules', self.option('package')
get basePackage
join(process.cwd!, 'package.json')
get language
if existsSync(self.basePackage)
return require(self.basePackage).language || 'imba'
else
'imba'
get definition
const npmFile = join self.package, 'package.json'
if !existsSync npmFile then return self.message('error', 'Package is not installed.')
JSON.parse readFileSync(npmFile, 'utf8').toString!
get publisherPath
self.definition['publisher']
get publisher
if !self.publisherPath
return self.message 'error', 'This package is not publishable.'
const publisherModule = join(package, self.publisherPath)
if !existsSync(publisherModule)
return self.message 'error', 'Publisher does not exist.'
let publisher = require(publisherModule).Package
publisher = new publisher
if typeof publisher.publish !== 'function'
return self.message 'error', 'Publish function missing.'
publisher.publish(self.language.toLowerCase!)
def handle
let tags\string[] = self.option('tag').split(',')
for optTag in tags
self.persist optTag
self.exit!
def persist optTag\string
if !self.publisher[optTag] || (self.publisher[optTag] && self.publisher[optTag].paths === undefined || self.publisher[optTag].paths === null)
return self.write "<fg:red>{optTag} is missing.</fg:red>"
if typeof self.publisher[optTag] !== 'object'
return self.write "<fg:red>{optTag} is missing paths.</fg:red>"
for entry in Object.keys(self.publisher[optTag].paths)
const file = join self.package, self.publisher[optTag].paths[entry]
if existsSync(entry) && !self.option('force', false)
self.write "<fg:red>{entry} already exists. Skipping.</fg:red>"
else
copySync file, entry, { overwrite: true }
self.write existsSync(entry) ? "<fg:green>Published</fg:green> {entry}" : "<fg:red>{entry} not published.</fg:red>"