Skip to content

Commit 8d63d26

Browse files
committed
#531 Improved the build process
1 parent c180bdd commit 8d63d26

File tree

5 files changed

+101
-67
lines changed

5 files changed

+101
-67
lines changed

Developer Tools/build.js

+6-58
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,12 @@
11
const shell = require('./src/shell-helper');
22
const sequencerFactory = require('./src/build-sequencer');
3-
const fileHelper = require('./src/file-helper');
4-
const glob = require('glob');
5-
const path = require('path');
6-
7-
const invokerCWD = process.cwd();
8-
9-
const buildInfos = {
10-
version: '2.0.0.0',
11-
buildProject: 'Tweetinvi'
12-
};
3+
const buildActions = require('./src/build-actions');
134

145
const sequencer = sequencerFactory.create();
15-
sequencer.addAction(updateProjectVersion);
16-
sequencer.addAction(buildDotNet);
17-
sequencer.execute();
18-
19-
function updateProjectVersion() {
20-
const projectFilePaths = glob.sync("../**/*.csproj");
21-
const assemblyInfosFilePaths = glob.sync('../**/AssemblyInfo.cs');
22-
const nuget = path.resolve('./TweetinviAPI/TweetinviAPI.nuspec');
23-
const clientHandler = path.resolve('../Tweetinvi.WebLogic/TwitterClientHandler.cs');
24-
25-
var allUpdates = [];
26-
27-
allUpdates = projectFilePaths.map(filepath => {
28-
return fileHelper.replace(filepath, /<VersionPrefix>([0-9\.]+[0-9])<\/VersionPrefix>/g, `<VersionPrefix>${buildInfos.version}</VersionPrefix>`).then(() => {
29-
console.log(filepath + ' version has been updated!');
30-
});
31-
}).concat(allUpdates);
32-
33-
allUpdates = assemblyInfosFilePaths.map(filepath => {
34-
return fileHelper.replace(filepath, /\[assembly: (AssemblyVersion|AssemblyFileVersion)\("([0-9\.]+[0-9])"\)\]/g, `[assembly: $1("${buildInfos.version}")]`).then(() => {
35-
console.log(filepath + ' version has been updated!');
36-
});
37-
}).concat(allUpdates);
38-
39-
allUpdates.push(fileHelper.replace(nuget, /<version>[0-9\.]+[0-9]<\/version>/g, `<version>${buildInfos.version}</version>`).then(() => {
40-
return fileHelper.replace(
41-
nuget,
42-
/<releaseNotes>https:\/\/github.com\/linvi\/tweetinvi\/releases\/tag\/[0-9\.]*<\/releaseNotes>/g,
43-
`<releaseNotes>https://github.com/linvi/tweetinvi/releases/tag/${buildInfos.version}</releaseNotes>`)
44-
}).then(() => {
45-
console.log('Nuget spec has been updated.')
46-
}));
47-
48-
allUpdates.push(fileHelper.replace(clientHandler, /"Tweetinvi\/(\d+(\.\d+)*)(.x)?"/, `"Tweetinvi/${buildInfos.version}"`).then(() => {
49-
console.log('User agent updated!');
50-
}));
516

52-
return Promise.all(allUpdates).then(() => {
53-
console.log('');
54-
console.log('******************************************');
55-
console.log('');
56-
});
57-
};
7+
sequencer.addAction(buildActions.updateProjectVersion);
8+
sequencer.addAction(buildActions.nugetRestore);
9+
sequencer.addAction(buildActions.buildDotNet);
10+
sequencer.addAction(buildActions.createNugetPackage);
5811

59-
function buildDotNet() {
60-
return shell.cd('../tweetinvi').then(() => {
61-
}).then(() => {
62-
return shell.spawn('dotnet build');
63-
});
64-
}
12+
sequencer.execute();

Developer Tools/src/build-actions.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const glob = require('glob');
2+
const path = require('path');
3+
4+
const shell = require('./shell-helper');
5+
const fileHelper = require('./file-helper');
6+
const buildInfos = require('./build-properties');
7+
8+
module.exports = {
9+
updateProjectVersion: () => {
10+
const projectFilePaths = glob.sync("../**/*.csproj");
11+
const assemblyInfosFilePaths = glob.sync('../**/AssemblyInfo.cs');
12+
const nuget = path.resolve('./TweetinviAPI/TweetinviAPI.nuspec');
13+
const clientHandler = path.resolve('../Tweetinvi.WebLogic/TwitterClientHandler.cs');
14+
15+
var allUpdates = [];
16+
17+
allUpdates = projectFilePaths.map(filepath => {
18+
return fileHelper.replace(filepath, /<VersionPrefix>([0-9\.]+[0-9])<\/VersionPrefix>/g, `<VersionPrefix>${buildInfos.version}</VersionPrefix>`).then(() => {
19+
console.log(filepath + ' version has been updated!');
20+
});
21+
}).concat(allUpdates);
22+
23+
allUpdates = assemblyInfosFilePaths.map(filepath => {
24+
return fileHelper.replace(filepath, /\[assembly: (AssemblyVersion|AssemblyFileVersion)\("([0-9\.]+[0-9])"\)\]/g, `[assembly: $1("${buildInfos.version}")]`).then(() => {
25+
console.log(filepath + ' version has been updated!');
26+
});
27+
}).concat(allUpdates);
28+
29+
allUpdates.push(fileHelper.replace(nuget, /<version>[0-9\.]+[0-9]<\/version>/g, `<version>${buildInfos.version}</version>`).then(() => {
30+
return fileHelper.replace(
31+
nuget,
32+
/<releaseNotes>https:\/\/github.com\/linvi\/tweetinvi\/releases\/tag\/[0-9\.]*<\/releaseNotes>/g,
33+
`<releaseNotes>https://github.com/linvi/tweetinvi/releases/tag/${buildInfos.version}</releaseNotes>`)
34+
}).then(() => {
35+
console.log('Nuget spec has been updated.')
36+
}));
37+
38+
allUpdates.push(fileHelper.replace(clientHandler, /"Tweetinvi\/(\d+(\.\d+)*)(.x)?"/, `"Tweetinvi/${buildInfos.version}"`).then(() => {
39+
console.log('User agent updated!');
40+
}));
41+
42+
return Promise.all(allUpdates).then(() => {
43+
console.log('');
44+
console.log('******************************************');
45+
console.log('');
46+
});
47+
},
48+
49+
nugetRestore: () => {
50+
return shell.cd('../tweetinvi').then(() => {
51+
}).then(() => {
52+
return shell.spawn('dotnet restore');
53+
});
54+
},
55+
56+
buildDotNet: () => {
57+
return shell.cd('../tweetinvi').then(() => {
58+
}).then(() => {
59+
return shell.spawn('dotnet build');
60+
});
61+
},
62+
63+
createNugetPackage: () => {
64+
return shell.cd('./TweetinviAPI').then(() => {
65+
return shell.spawn('rimraf *.nupkg');
66+
}).then(() => {
67+
return shell.spawn('ls');
68+
}).then(() => {
69+
return shell.cd('../');
70+
}).then(() => {
71+
return shell.spawn('nuget.exe pack ./TweetinviAPI/TweetinviAPI.nuspec -OutputDirectory TweetinviAPI');
72+
});
73+
}
74+
};
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
version: '2.0.0.0',
3+
buildProject: 'Tweetinvi'
4+
};

Developer Tools/src/build-sequencer.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ const shell = require('./shell-helper');
33
const createSequencer = () => {
44
const _actions = [];
55
const _execute = (buildActions) => {
6+
const cwd = process.cwd();
7+
68
if (buildActions.length === 0) {
79
return Promise.resolve();
810
}
911

1012
const currentAction = buildActions.shift();
11-
let promise = currentAction();
13+
let promise = currentAction().then(() => {
14+
return shell.cd(cwd, true); // Navigate back to source so that each action start with the same folder context
15+
});
1216

1317
if (promise == null) {
1418
promise = Promise.resolve();
1519
}
1620

1721
return promise.then(() => {
18-
return _execute(buildActions)
22+
return _execute(buildActions);
1923
});
2024
};
2125

2226
return {
2327
execute: () => {
24-
const cwd = process.cwd();
25-
26-
return _execute(_actions).then(() => {
27-
return shell.cd(cwd);
28-
});
28+
return _execute(_actions);
2929
},
3030
addAction(promiseAction) {
3131
_actions.push(promiseAction);

Developer Tools/src/shell-helper.js

+10-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ const nodeSpawn = require('child_process').spawn;
33

44
module.exports = {
55
exec: (cmd) => {
6-
console.log(cmd);
76

87
return new Promise((resolve, reject) => {
8+
console.log(`> ${cmd}`);
9+
910
const execution = nodeExec(cmd, {}, (error, stdout, stderr) => {
1011
if (error) { console.error(`exec error: ${error}`); reject(error); return; }
1112
// if (stdout) { console.log(stdout); }
@@ -20,17 +21,24 @@ module.exports = {
2021
},
2122
spawn: (cmd) => {
2223
return new Promise((resolve, reject) => {
24+
console.log(`> ${cmd}`);
25+
2326
const execution = nodeSpawn('cmd.exe', ['/s', '/c', cmd], {
2427
stdio: 'inherit'
2528
});
2629

2730
execution.on('exit', code => { resolve(code); });
2831
});
2932
},
30-
cd: (path) => {
33+
cd: (path, silent) => {
3134
return new Promise((resolve, reject) => {
3235
try {
3336
process.chdir(path);
37+
38+
if (!silent) {
39+
console.log(`cd ${process.cwd()}`);
40+
}
41+
3442
resolve();
3543
}
3644
catch (error) {

0 commit comments

Comments
 (0)