Skip to content
This repository was archived by the owner on Mar 1, 2019. It is now read-only.

Commit

Permalink
fix(runtime-error): Resolve TypeError: require(...) is not a function
Browse files Browse the repository at this point in the history
  • Loading branch information
hypery2k committed Jul 6, 2017
1 parent be14ba8 commit 936387e
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 21 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ target/
*.log
*.tgz
*.iml
lib/*.js
lib/*.js.map
lib/**/*.js
lib/**/*.js.map
test/**/*.js
test/**/*.js.map
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ before_script:
- sleep 3 # give xvfb some time to start
script:
# - npm run test
# - npm run e2e
- npm run e2e
5 changes: 3 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ node {
}

stage('Test') {
//sh "npm run test && npm run e2e"
//sh "npm run test"
//junit 'target/test-reports/TEST*.xml'
//junit 'target/e2e-reports/TEST*.xml'
sh "npm run e2e"
junit 'target/e2e-reports/TEST*.xml'
}

stage('Publish NPM snapshot') {
Expand Down
44 changes: 29 additions & 15 deletions lib/buildnumbering.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,40 @@ const ARGS = process.argv.slice(2);

let xmlParser = new xml2js.Parser(),
builder = new xml2js.Builder(),
manifestPath = path.resolve('.', 'app/App_Resources/Android/AndroidManifest.xml'),
manifestPath = 'app/App_Resources/Android/AndroidManifest.xml',
plistPath = 'app/App_Resources/iOS/Info.plist',
buildNo = ARGS[0] || process.env['BUILD_NUMBER'] || 1,
packageJSON = require(path.resolve('.', 'package.json')),
manifestXML = fs.readFileSync(manifestPath);

packageJSON = require(path.resolve('.', 'package.json'));

console.log('Updating with build number: ' + buildNo);

xmlParser.parseString(manifestXML, function (err, manifestData) {
let appId = packageJSON.nativescript.id,
version = packageJSON.version;
manifestData.manifest.$['android:versionCode'] = buildNo;
manifestData.manifest.$['android:versionName'] = version;
fs.writeFile(manifestPath, builder.buildObject(manifestData), function (err) {
if (err) throw err;
});
fs.stat(manifestPath, (error) => {
if (!error) {
let manifestXML = fs.readFileSync(manifestPath);
xmlParser.parseString(path.resolve('.', manifestPath), function (err, manifestData) {
let appId = packageJSON.nativescript.id,
version = packageJSON.version;
manifestData.manifest.$['android:versionCode'] = buildNo;
manifestData.manifest.$['android:versionName'] = version;
fs.writeFile(manifestPath, builder.buildObject(manifestData), function (err) {
if (err) throw err;
});
});
} else {
console.log('Skipping platform Android');
}
});

exec('/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ' + buildNo + '" ' + __dirname + '"/../app/App_Resources/iOS/Info.plist"', function (err) {
if (err) {
throw err;
fs.stat(plistPath, (error) => {
if (!error) {
exec('/usr/libexec/PlistBuddy -c "Set :CFBundleVersion ' + buildNo + '" ' + path.resolve('.', plistPath), function (err) {
if (err) {
throw err;
}
});
} else {
console.log('Skipping platform iOS');
}
});


Empty file added lib/release.ts
Empty file.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"build": "npm run tsc",
"tsc": "tsc",
"postclean": "",
"e2e": "jasmine-node test/e2e/*.spec.js --junitreport --output target/e2e-reports/ --verbose --color",
"jsdoc": "jsdoc -c ./jsdoc.json -t ./node_modules/ink-docstrap/template -R README.md ./etc",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
"changelog:add": "git add CHANGELOG.md && git commit -m 'updated CHANGELOG.md'",
Expand All @@ -27,6 +28,8 @@
"xml2js": "0.4.16"
},
"devDependencies": {
"@types/core-js": "0.9.37",
"@types/jasmine": "2.5.46",
"@types/node": "8.0.7",
"conventional-changelog-cli": "1.2.0",
"fs": "0.0.2",
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/execution.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import { exec } from 'child_process';

declare var fail;

describe('execute command line binaries', () => {

it('buildnumbering', (done) => {
exec('node tns-buildnumbering.js ', (err) => {
if (err) {
fail();
} else {
done();
}
}, (err: any) => {
throw new Error(err);
});
});

});
2 changes: 1 addition & 1 deletion tns-buildnumbering.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
// Adds the build number to app versioning
// e.g. tns-buildnumbering 42 -> uses 42 as build number

require('./lib/buildnumbering')();
require('./lib/buildnumbering');
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dom"
],
"types": [
"jasmine",
"node"
]
},
Expand Down

0 comments on commit 936387e

Please sign in to comment.