-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support SDK-style projects with a Version
- Loading branch information
Showing
7 changed files
with
199 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
|
||
const path = require('path') | ||
|
||
const kRoot = Symbol('kRoot') | ||
const kRelative = Symbol('kRelative') | ||
|
||
class AbstractFile { | ||
constructor (path) { | ||
this.path = path | ||
this[kRoot] = null | ||
this[kRelative] = null | ||
} | ||
|
||
set root (root) { | ||
this[kRoot] = root | ||
this[kRelative] = path.relative(root, this.path) | ||
} | ||
|
||
get root () { | ||
return this[kRoot] | ||
} | ||
|
||
get relative () { | ||
return this[kRelative] | ||
} | ||
|
||
read (callback) { | ||
this[AbstractFile.read](callback) | ||
} | ||
|
||
write (callback) { | ||
this[AbstractFile.write](callback) | ||
} | ||
|
||
get version () { | ||
return this[AbstractFile.getVersion]() | ||
} | ||
|
||
set version (version) { | ||
this[AbstractFile.setVersion](version) | ||
} | ||
} | ||
|
||
AbstractFile.read = Symbol('read') | ||
AbstractFile.write = Symbol('write') | ||
AbstractFile.getVersion = Symbol('getVersion') | ||
AbstractFile.setVersion = Symbol('setVersion') | ||
|
||
module.exports = AbstractFile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
'use strict' | ||
|
||
const Assembly = require('assembly-source') | ||
const fs = require('fs') | ||
const AbstractFile = require('./abstract-file') | ||
const kAssembly = Symbol('kAssembly') | ||
|
||
module.exports = class AssemblyFile extends AbstractFile { | ||
constructor (path, language) { | ||
super(path) | ||
|
||
this[kAssembly] = null | ||
} | ||
|
||
[AbstractFile.read] (callback) { | ||
this[kAssembly] = null | ||
|
||
fs.readFile(this.path, 'utf8', (err, source) => { | ||
if (err) return callback(err) | ||
|
||
this[kAssembly] = Assembly(source) | ||
callback() | ||
}) | ||
} | ||
|
||
[AbstractFile.write] (callback) { | ||
fs.writeFile(this.path, this[kAssembly].toSource(), callback) | ||
} | ||
|
||
[AbstractFile.getVersion] () { | ||
return this[kAssembly].get('AssemblyVersion') | ||
} | ||
|
||
[AbstractFile.setVersion] (version) { | ||
this[kAssembly].set('AssemblyVersion', version) | ||
|
||
for (const additional of ['AssemblyFileVersion', 'AssemblyInformationalVersion']) { | ||
if (this[kAssembly].get(additional) != null) { | ||
this[kAssembly].set(additional, version) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.