Skip to content

Commit 86fb400

Browse files
author
Dimitar Tachev
authored
Merge pull request #63 from NativeScript/tachev/fix-plugin-development
fix plugin development using npm link
2 parents adb90a4 + 9419ed7 commit 86fb400

14 files changed

+82
-8
lines changed

demo/app/App_Resources/Android/app.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
android {
99
defaultConfig {
1010
generatedDensities = []
11-
applicationId = "__PACKAGE__"
11+
applicationId = "org.nativescript.demo"
1212
}
1313
aaptOptions {
1414
additionalParameters "--no-version-vectors"

demo/package.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,20 @@
77
"id": "org.nativescript.demo",
88
"tns-ios": {
99
"version": "3.0.0"
10+
},
11+
"tns-android": {
12+
"version": "3.4.1"
1013
}
1114
},
1215
"dependencies": {
1316
"nativescript-theme-core": "^1.0.4",
1417
"tns-core-modules": "^3.0.0"
1518
},
1619
"devDependencies": {
17-
"nativescript-dev-sass": "file:.."
20+
"babel-traverse": "6.26.0",
21+
"babel-types": "6.26.0",
22+
"babylon": "6.18.0",
23+
"lazy": "1.0.11",
24+
"nativescript-dev-sass": "file:../src"
1825
}
1926
}

publish/pack.sh

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
3+
SOURCE_DIR=../src;
4+
TO_SOURCE_DIR=src;
5+
PACK_DIR=package;
6+
ROOT_DIR=..;
7+
PUBLISH=--publish
8+
9+
install(){
10+
npm i
11+
}
12+
13+
pack() {
14+
15+
echo 'Clearing /src and /package...'
16+
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
17+
node_modules/.bin/rimraf "$PACK_DIR"
18+
19+
# copy src
20+
echo 'Copying src...'
21+
node_modules/.bin/ncp "$SOURCE_DIR" "$TO_SOURCE_DIR"
22+
23+
# copy README & LICENSE to src
24+
echo 'Copying README and LICENSE to /src...'
25+
node_modules/.bin/ncp "$ROOT_DIR"/LICENSE "$TO_SOURCE_DIR"/LICENSE
26+
node_modules/.bin/ncp "$ROOT_DIR"/README.md "$TO_SOURCE_DIR"/README.md
27+
28+
# compile package and copy files required by npm
29+
echo 'Building /src...'
30+
cd "$TO_SOURCE_DIR"
31+
node_modules/.bin/tsc
32+
cd ..
33+
34+
echo 'Creating package...'
35+
# create package dir
36+
mkdir "$PACK_DIR"
37+
38+
# create the package
39+
cd "$PACK_DIR"
40+
npm pack ../"$TO_SOURCE_DIR"
41+
42+
# delete source directory used to create the package
43+
cd ..
44+
node_modules/.bin/rimraf "$TO_SOURCE_DIR"
45+
}
46+
47+
install && pack

publish/package.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "nativescript-publish",
3+
"version": "1.0.0",
4+
"description": "Publish helper",
5+
"devDependencies": {
6+
"ncp": "^2.0.0",
7+
"rimraf": "^2.5.0"
8+
}
9+
}

publish/publish.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
PACK_DIR=package;
4+
5+
publish() {
6+
cd $PACK_DIR
7+
echo 'Publishing to npm...'
8+
npm publish *.tgz
9+
}
10+
11+
./pack.sh && publish
File renamed without changes.
File renamed without changes.
File renamed without changes.

lib/converter.js renamed to src/lib/converter.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ var currentSassProcess = null;
99
function convert(logger, projectDir, options) {
1010
return new Promise(function (resolve, reject) {
1111
options = options || {};
12-
13-
var peerSassPath = path.join(__dirname, '../../node-sass');
14-
var sassPath = path.join(peerSassPath, 'bin/node-sass');
12+
var sassPath = require.resolve('node-sass/bin/node-sass');
1513
var appDir = path.join(projectDir, "app");
1614
var importerPath = path.join(__dirname, "importer.js");
1715

@@ -36,7 +34,9 @@ function convert(logger, projectDir, options) {
3634
}
3735

3836
logger.trace(process.execPath, nodeArgs.join(' '));
39-
currentSassProcess = spawn(process.execPath, nodeArgs);
37+
var env = Object.create( process.env );
38+
env.PROJECT_DIR = projectDir;
39+
currentSassProcess = spawn(process.execPath, nodeArgs, { env: env });
4040

4141
var isResolved = false;
4242
var watchResolveTimeout;

lib/importer.js renamed to src/lib/importer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ var path = require("path");
33
module.exports = function(url, prev, done) {
44
if (url[0] === '~' && url[1] !== '/') {
55
// Resolve "~" paths to node_modules
6-
url = path.resolve(__dirname, "../../../node_modules", url.substr(1));
6+
url = path.resolve(process.env.PROJECT_DIR, "node_modules", url.substr(1));
77
} else if (url[0] === '~' && url[1] === '/') {
88
// Resolve "~/" paths to the app root
9-
url = path.resolve(__dirname, "../../../app/"+ url.substr(2));
9+
url = path.resolve(process.env.PROJECT_DIR, "app/"+ url.substr(2));
1010
}
1111

1212
return { file: url };
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)