Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make {N} project structure configurable #3257

Closed
sis0k0 opened this issue Dec 11, 2017 · 10 comments
Closed

Make {N} project structure configurable #3257

sis0k0 opened this issue Dec 11, 2017 · 10 comments
Assignees
Labels
Milestone

Comments

@sis0k0
Copy link
Contributor

sis0k0 commented Dec 11, 2017

Currently, a {N} project has to follow a few conventions in order to be built with {N} CLI. For example, the source code should be in a folder named app, the application resources should be in app/App_Resources and so on.
The project structure should be configurable per project. For example, a project can have a .tns-cli.json file inside the project where the following can be specified:

  • app folder name (currently 'app')
  • app resources folder name
  • folders/files to be included in the app and to be watched during livesync (related to Ability to ignore files from build and livesync #887)
    • This is particularly important when building apps with Angular 5. The package @angular/common contains localization files (~17Mb) which will get deployed on the device even if they are not used.
@dolanmiu
Copy link

Agreed.

I like to have my projects under src/app, just like how @angular/cli does it

@KristianDD
Copy link
Contributor

Currently a file named "nsconfig.json" will be respected. The valid values inside it are as follows:

{
    "appPath": "test/src",
    "appResourcesPath": "resources"
}

Both paths must be relative to the project root(where the "package.json" file and "platforms" directory are located) in order everything to work as expected.

If appResourcesPath is omitted the CLI will assume that they are at their default location - folder called App_Resources inside the folder containing the rest of the app files.

If appPath is omitted CLI will assume the application files are located inside a folder called "app" inside the project folder.

Examples:
Lets say the project is located at "/d/work/myapplication".

1 "nsconfig.json" content:

{
    "appPath": "test/src"
}

Will result in app located at "/d/work/myapplication/test/src" and resources located at "/d/work/myapplication/test/src/App_Resources".

2 "nsconfig.json" content:

{
    "appResourcesPath": "resources"
}

Will result in app located at "/d/work/myapplication/app" and resources located at "/d/work/myapplication/resources".

3 "nsconfig.json" content:

{
    "appPath": "test/src",
    "appResourcesPath": "resources"
}

Will result in app located at "/d/work/myapplication/test/src" and resources located at "/d/work/myapplication/resources".

4 If no "nsconfig.json" file is present the app folder will be "/d/work/myapplication/app" and resources folder will be at "/d/work/myapplication/app/App_Resources"

The option folders/files to be included/excluded in the app and to be watched during livesync (related to #887) is still not implemented. Its discussion/implementation is moved in the separate issue.

@dolanmiu
Copy link

Still does not work for me. It seems like the nsconfig.json has no effect:

It seems like it still searches for the default app folder


Error: ENOENT: no such file or directory, lstat '/Volumes/Storage/Git/midday/apps/mobile/app'
    at Object.fs.lstatSync (fs.js:961:11)
    at Object.module.exports.parseDir (/Volumes/Storage/Git/midday/apps/mobile/node_modules/sass-graph/sass-graph.js:153:10)
    at Object.watcher.reset (/Volumes/Storage/Git/midday/apps/mobile/node_modules/node-sass/lib/watcher.js:17:21)
    at watch (/Volumes/Storage/Git/midday/apps/mobile/node_modules/node-sass/bin/node-sass:254:20)
    at run (/Volumes/Storage/Git/midday/apps/mobile/node_modules/node-sass/bin/node-sass:313:5)
    at Object.<anonymous> (/Volumes/Storage/Git/midday/apps/mobile/node_modules/node-sass/bin/node-sass:397:3)
    at Module._compile (module.js:660:30)
    at Object.Module._extensions..js (module.js:671:10)
    at Module.load (module.js:573:32)
    at tryModuleLoad (module.js:513:12)

My nsconfig.json is:

{
    "appPath": "src/app",
    "appResourcesPath": "app-resources"
}

@KristianDD
Copy link
Contributor

Hi @dolanmiu,

It seems that nativescript-dev-sass plugin is throwing an exception. Could you please verify that you are using the latest version of nativescript-dev-sass - 1.3.6. There were some modifications to the plugin to support projects with nsconfig.json. I apologize that I forgot to include this in the initial feature description.

You will also need the RC versions of NativeScript CLI and Android Runtime.

@dolanmiu
Copy link

dolanmiu commented Apr 3, 2018

I am using nativescript-dev-sass 1.3.2

I am using a mac and only got iOS setup at the moment, would that be a problem?

@KristianDD
Copy link
Contributor

KristianDD commented Apr 4, 2018

Hi @dolanmiu,

Having only iOS setup is a valid option and you should not have any problems.

Is your project working normally with nsconfig.json when you update nativescript-dev-sass to 1.3.6 and NativeScript CLI to rc tag?

@dolanmiu
Copy link

dolanmiu commented Apr 8, 2018

Thanks, setting nativescript-dev-sass to 1.3.6 and nativescript to rc seems to work

I had weird installation issues though, I had to delete node_modules and fully re-install

@KristianDD
Copy link
Contributor

Hi @dolanmiu,

I am glad that everything worked as expected. Most probably the full re-install was necessary for the recreation of the hooks of the plugins (they contain some changes for supporting nsconfig.json).

Thank you for trying this feature.

@slolam
Copy link

slolam commented May 10, 2018

Hi,

Not sure where I'm going wrong. I'm not well versed with NS-CLI. I have nsconfig.json that looks like this
{ "appPath": "build", "appResourcesPath": "build/App_Resources" }

when I to build it I get the following error

ERROR in app/vendor.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'application'. app/vendor.ts(4,7): error TS2451: Cannot redeclare block-scoped variable 'appCssContext'. build/vendor.ts(2,7): error TS2451: Cannot redeclare block-scoped variable 'application'. build/vendor.ts(4,7): error TS2451: Cannot redeclare block-scoped variable 'appCssContext'.
Not sure why CLI is using the app folder.

tns version: 4.0.0

Thanks in anticpation.

@dolanmiu
Copy link

dolanmiu commented Nov 20, 2018

Another request,

Is it possible to add buildPath to nsconfig.json?

So that, we can do: "buildPath": "dist", just like how @angular/cli does it?

Yes, a solution would be to hide the built files etc in VSCode, but it does not seem ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants