@cplace/cli
Advanced tools
Comparing version 0.8.1 to 0.8.2-beta.0
@@ -11,2 +11,4 @@ /** | ||
protected static readonly PARAMETER_FORCE: string; | ||
protected static readonly NODE_MODULES: string; | ||
protected static readonly __NODE_MODULES_COPY: string; | ||
protected parentRepos: IReposDescriptor; | ||
@@ -17,4 +19,5 @@ protected force: boolean; | ||
protected doPrepareAndMayExecute(params: ICommandParameters): boolean; | ||
protected removeFolderInRepo(repo: Repository, folderName: string): void; | ||
protected checkRepoClean(repo: Repository, status: IGitStatus): Promise<IGitStatus>; | ||
protected writeNewParentRepos(newParentRepos: IReposDescriptor): Promise<void>; | ||
} |
@@ -8,4 +8,6 @@ "use strict"; | ||
const Global_1 = require("../../Global"); | ||
const fs_1 = require("../../p/fs"); | ||
const fs = require("fs"); | ||
const util_1 = require("../../util"); | ||
const path = require("path"); | ||
const rimraf = require("rimraf"); | ||
class AbstractReposCommand { | ||
@@ -18,3 +20,3 @@ prepareAndMayExecute(params) { | ||
} | ||
if (!fs_1.fs.existsSync(AbstractReposCommand.PARENT_REPOS_FILE_NAME)) { | ||
if (!fs.existsSync(AbstractReposCommand.PARENT_REPOS_FILE_NAME)) { | ||
console.error('Cannot find repo description', AbstractReposCommand.PARENT_REPOS_FILE_NAME); | ||
@@ -24,3 +26,3 @@ return false; | ||
try { | ||
this.parentRepos = JSON.parse(fs_1.fs.readFileSync(AbstractReposCommand.PARENT_REPOS_FILE_NAME, 'utf8')); | ||
this.parentRepos = JSON.parse(fs.readFileSync(AbstractReposCommand.PARENT_REPOS_FILE_NAME, 'utf8')); | ||
} | ||
@@ -37,2 +39,8 @@ catch (e) { | ||
} | ||
removeFolderInRepo(repo, folderName) { | ||
if (fs.existsSync(path.join(repo.baseDir, folderName))) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: Removing ${folderName} folder`); | ||
rimraf.sync(path.join(repo.baseDir, folderName)); | ||
} | ||
} | ||
checkRepoClean(repo, status) { | ||
@@ -57,3 +65,3 @@ const isRepoClean = status.not_added.length === 0 && | ||
Global_1.Global.isVerbose() && console.log('new repo description', newParentReposContent); | ||
return fs_1.fs | ||
return fs | ||
.writeFileAsync(AbstractReposCommand.PARENT_REPOS_FILE_NAME, newParentReposContent, 'utf8') | ||
@@ -67,3 +75,5 @@ .then(() => { | ||
AbstractReposCommand.PARAMETER_FORCE = 'force'; | ||
AbstractReposCommand.NODE_MODULES = 'node_modules'; | ||
AbstractReposCommand.__NODE_MODULES_COPY = '__node_modules'; | ||
exports.AbstractReposCommand = AbstractReposCommand; | ||
//# sourceMappingURL=AbstractReposCommand.js.map |
@@ -14,3 +14,7 @@ /** | ||
protected doPrepareAndMayExecute(params: ICommandParameters): boolean; | ||
private moveNodeModules; | ||
private restoreNodeModules; | ||
private areNodeModulesCheckedIn; | ||
private handleNodeModules; | ||
private handleRepo; | ||
} |
@@ -10,2 +10,4 @@ "use strict"; | ||
const Global_1 = require("../../Global"); | ||
const path = require("path"); | ||
const fs = require("fs"); | ||
class UpdateRepos extends AbstractReposCommand_1.AbstractReposCommand { | ||
@@ -28,2 +30,50 @@ execute() { | ||
} | ||
moveNodeModules(repo) { | ||
if (!fs.existsSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES))) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: No ${AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES} folder`); | ||
} | ||
else { | ||
if (fs.existsSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY))) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: ${AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY} folder already exists`); | ||
this.removeFolderInRepo(repo, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY); | ||
} | ||
console.log(`[${repo.repoName.toUpperCase()}]: Moving ${AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES} to ${AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY}`); | ||
fs.renameSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES), path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY)); | ||
} | ||
} | ||
restoreNodeModules(repo) { | ||
if (!fs.existsSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY))) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: No ${AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY} folder`); | ||
} | ||
else { | ||
if (fs.existsSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES))) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: ${AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES} folder already exists`); | ||
this.removeFolderInRepo(repo, AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES); | ||
} | ||
console.log(`[${repo.repoName.toUpperCase()}]: Restoring ${AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES} from ${AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY}`); | ||
fs.renameSync(path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY), path.join(repo.baseDir, AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES)); | ||
} | ||
} | ||
areNodeModulesCheckedIn(repo) { | ||
const packageJsonPath = path.join(repo.baseDir, 'package.json'); | ||
if (!fs.existsSync(packageJsonPath)) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: package.json is not provided`); | ||
return false; | ||
} | ||
else { | ||
const packageJsonString = fs.readFileSync(packageJsonPath, 'utf8'); | ||
const packageJson = JSON.parse(packageJsonString); | ||
console.log(`[${repo.repoName.toUpperCase()}]: package.json version is ${packageJson.version}`); | ||
return packageJson.version === '1.0.0'; | ||
} | ||
} | ||
handleNodeModules(repo) { | ||
if (this.areNodeModulesCheckedIn(repo)) { | ||
console.log(`[${repo.repoName.toUpperCase()}]: No need to restore ${AbstractReposCommand_1.AbstractReposCommand.NODE_MODULES}`); | ||
this.removeFolderInRepo(repo, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY); | ||
} | ||
else { | ||
this.restoreNodeModules(repo); | ||
} | ||
} | ||
handleRepo(repoName) { | ||
@@ -40,4 +90,6 @@ Global_1.Global.isVerbose() && console.log('repo', repoName); | ||
return p | ||
.then(() => this.removeFolderInRepo(repo, AbstractReposCommand_1.AbstractReposCommand.__NODE_MODULES_COPY)) | ||
.then(() => repo.status()) | ||
.then((status) => this.checkRepoClean(repo, status)) | ||
.then(() => this.moveNodeModules(repo)) | ||
.then(() => repo.checkoutBranch(branch)) | ||
@@ -56,2 +108,3 @@ .then(() => repo.resetHard()) | ||
}) | ||
.then(() => this.handleNodeModules(repo)) | ||
.then(() => { | ||
@@ -58,0 +111,0 @@ Global_1.Global.isVerbose() && console.log('successfully updated', repoName); |
@@ -7,9 +7,11 @@ "use strict"; | ||
function enforceNewline(text) { | ||
return text.replace(/[\n\r]/g, '\n'); | ||
return text.replace(/\r\n?/g, '\n'); | ||
} | ||
exports.enforceNewline = enforceNewline; | ||
function makeSingleLine(text) { | ||
return enforceNewline(text).replace(/\s*\n\s*/g, ' '); | ||
return enforceNewline(text) | ||
.trim() | ||
.replace(/\s*\n\s*/g, ' '); | ||
} | ||
exports.makeSingleLine = makeSingleLine; | ||
//# sourceMappingURL=util.js.map |
{ | ||
"name": "@cplace/cli", | ||
"version": "0.8.1", | ||
"version": "0.8.2-beta.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
235952
3269
6