How to change path that #schematics/angular uses to generate component - angular-console

When trying to generate a component via angular console using #schematics/angular:component, this is the path it attempts to use:
/apps/client/src/app/modules/app/app.module.ts.
I used modules/app/app.module.ts as the value for declaring NgModule so it could find the right one.
It basically took this path and added it to /apps/client/src/app, which is not correct. I rearranged my project structure a bit so that this is now the correct path:
/apps/client/src/modules/app/app.module.ts.
I.e., I removed app after src.
Is there a way to adjust the path somewhere? Or is this just the schematic and it cannot be changed without a fork? The intent is to remove the first app in the path.

Related

How to make a path from a string in starlark?

I'm writing some validation code for a bazel build rule and I need to do some path validation. I need to check that a certain file exists in the same directory as the BUILD file. I notice that there's a context attribute build_file_path which points to the BUILD file. I'd like to extract the parent directory from this.
It looks like I can't create a new path object - I don't see a constructor/initializer. It also seems like Starlark doesn't support os.path like python because imports aren't supported.
What's the canonical way to get the parent directory of a string object representing a path in Starlark?
I can't answer your final question, but hopefully the following will help with the initial problem:
You could use the Label of the target for which this instance of the rule is being built and find its package. This will give you a string representing the parent directory of the BUILD file.
i.e. ctx.label.package
load("#bazel_skylib//lib:paths.bzl", "paths")
paths.dirname(path_str)
See https://github.com/bazelbuild/bazel-skylib/blob/main/docs/paths_doc.md

How to check object class type in Dart

In my code, there is a place where I need to take different actions based on the input class type.
So I write two lines to check an input object's class type.
debugPrint("Let me know the next action: $action");
debugPrint((action is LoadPomodorosAction).toString());
And the output is
I/flutter (24128): Let me know the next action: Instance of 'LoadPomodorosAction'
I/flutter (24128): false
What does this mean?
The object 'action' is "Instance of 'LoadPomodorosAction'" and at the same time its class type is not LoadPomodorosAction .
how do I adjust my code so that I can know the class type of action?
I was suspecting that maybe there is something wrong with runtimetype. But how do I get to know the runtimetype?
I've tried replicating your issue and I'm not able to reproduce it. But to explain your inquiry, here is a complete details about the difference between the relative path and absolute path when used in imports as discussed in this SO post:
package imports
'package:... imports work from everywhere to import files from
lib/*.
relative imports
Relative imports are always relative to the importing file. If
lib/model/test.dart imports 'example.dart', it imports
lib/model/example.dart.
If you want to import test/model_tests/fixture.dart from any file
within test/*, you can only use relative imports because package
imports always assume lib/.
This also applies for all other non-lib/ top-level directories like
drive_test/, example/, tool/, ...
lib/main.dart
There is currently a known issue with entry-point files in lib/*
like lib/main.dart in Flutter.
https://github.com/dart-lang/sdk/issues/33076
Dart always assumed entry-point files to be in other top-level
directories then lib/ (like bin/, web/, tool/, example/,
...). Flutter broke this assumption. Therefore you currently must not
use relative imports in entry-point files inside lib/
See also
How to reference another file in Dart?
Previously, this bug was posted in GitHub as an issue between relative and absolute path. It seems that this was resolved per this GitHub post.

Sublime Text 3 - Set syntax for filetype in package/plugin

I am busy making a sublime text plugin/package that will ease development of lua scripts in my workplace.
We have several lua files with different extensions depending on their purpose. I want ST3 to give the proper lua syntax to these files.
I know you can set ST3 to remember syntax for a specific file extension and this is saved as a (in my case) Lua.sublime-settings file in AppData\Roaming\Sublime Text 3\Packages\User
However, if I put this file in my new plugin's folder, it's ignored.
Am I doing something wrong or is what I want not possible?
This doesn't work because syntax specific settings are only loaded from the package that defines the syntax and from the User package (so the user can customize them).
The following is a quote from the official documentation on settings:
Settings files are consulted in this order:
1. Packages/Default/Preferences.sublime-settings
2. Packages/Default/Preferences (<platform>).sublime-settings
3. Packages/User/Preferences.sublime-settings
4. <Project Settings>
5. Packages/<syntax>/<syntax>.sublime-settings
6. Packages/User/<syntax>.sublime-settings
7. <Buffer Specific Settings>
The only places where <syntax> is referenced is from the package itself and from the user package.
If I had to guess, I would say that this is because outside of the original package author that defined the syntax, all other settings would be considered user customizations, and those settings need to be in the User package (specifically in the root of it) to ensure that they're loaded last.
A simple (but undesirable) solution would be to document for the user that they have to take this step manually.
Another approach would be to add some plugin code that extends the settings when your plugin is loaded:
def plugin_loaded():
settings = sublime.load_settings("Lua.sublime-settings")
extensions = settings.get("extensions", [])
if "blarb" not in extensions:
extensions.append("blarb")
settings.set("extensions", extensions)
sublime.save_settings("Lua.sublime-settings")
If you go this route you may want to include an extra sentinel setting somewhere (in settings specific to your package or some such) that says if you did this or not instead of just forcing the setting in as the example above does.
In practice you would then check if you've set that sentinel or not instead of forcing the extension in, so that if the user decides to use some other syntax for your files you're not forcing them into the Lua syntax.
It's also possible to define your own syntax that just embeds the standard Lua syntax, which allows this to Just Work™ without having to write any code or have the user do anything:
%YAML 1.2
---
name: Blarb
scope: source.lua
file_extensions:
- blarb
contexts:
main:
- include: scope:source.lua
When you do this, the scope in the file will still be source.lua because that's what the scope in the syntax file says. and the status line will set the syntax name to Blarb. You could modify either of those to change the top level scope or displayed name, if desired.
An example would be to change the scope to source.blarb so that you could create key bindings/snippets that only apply to Lua files of your specific variant.
A potential downside/feature of this is that since the name of the syntax specific settings comes from the name of the file that provides the syntax, if the user has any Lua specific settings, they won't apply to your Blarb files by default.
Similarly anything that's specific to Lua by checking for a scope of source.lua won't work in Blarb files for same reasons, which may or may not be an issue.

Generate URL of resources that are handled by Grails AssetPipeline

I need to access a local JSON file. Since Grails 2.4 implements the AssetPipeline plugin by default, I saved my local JSON file at:
/grails-app/assets/javascript/vendor/me/json/local.json
Now what I need is to generate a URL to this JSON file, to be used as a function parameter on my JavaScript's $.getJSON() . I've tried using:
var URL.local = ""${ raw(asset.assetPath(src: "local.json")) }";
but it generates an invalid link:
console.log(URL.local);
// prints /project/assets/local.json
// instead of /project/assets/vendor/me/json/local.json
I also encountered the same scenario with images that are handled by AssetPipeline1.9.9— that are supposed to be inserted dynamically on the page. How can I generate the URL pointing this resource? I know, I can always provide a static String for the URL, but it seems there would be a more proper solution.
EDIT
I was asked if I could move the local JSON file directly under the assets/javascript root directory instead of placing it under a subdirectory to for an easier solution. I prefer not to, for organization purposes.
Have you tried asset.assetPath(src: "/me/json/local.json")
The assets plugin looks in all of the immediate children of assets/. Your local.json file would need to be placed in /project/assets/foo/ for your current code to pick it up.
Check out the relevant documentation here which contains an example.
The first level deep within the assets folder is simply used for organization purposes and can contain folders of any name you wish. File types also don't need to be in any specific folder. These folders are omitted from the URL mappings and relative path calculations.

How to use sc_static() while programming

I am trying to display some Images which are in my local folder. I am getting the image name from a server through JSON. Based on that, I am constructing the Image path dynamically. However, the final image path will be changed by SC build tools. I know that we can use sc_static() in css or view's specifications to map it to the final path. How can I achieve that mapping (to final path from local path) while programmatically constructing my url.
Any ideas, suggestions and thoughts?
sc_static is not a javascript function, but rather a convention used to tell Abbot (Sproutcore's build tool, written in ruby) to replace it at runtime with a path pointing to the resource passed as first argument to sc_static.
Note that this substitution is done by Abbot when the page is refreshed (in dev mode) or when the app is built (in prod mode). It is not a js function at all (use Chrome inspector to see it by yourself).
If you want to use sc_static in JS you can define all resource references as such:
YourApp.loadingIcon=sc_static('loading.png');
YourApp.greenIcon=sc_static('green.png');
and then reference the
YourApp.loadingIcon , YourApp.greenIcon
variables in your code.
Finally I found the answer with the help of my friends. sc_static is not javascript function it is a function targeted for build tools(Abbot) of Sproutcore to replace the actual production path after build. Hence we can not use sc_static in programming.
If we want similar function we have develop our own.

Resources