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

Allow ng build to be run from any subfolder #4422

Merged
merged 1 commit into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/frontend/packages/devkit/src/build/extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class ExtensionsHandler {
public apply(webpackConfig: any, config: StratosConfig, options: any) {

// Generate the module file to import the appropriate extensions
const dir = path.dirname(options.main);
const dir = path.join(config.rootDir, path.dirname(options.main));
const overrideFile = path.resolve(path.join(dir, './_custom-import.module.ts'));

fs.writeFileSync(overrideFile, '// This file is auto-generated - DO NOT EDIT\n\n');
Expand Down
15 changes: 9 additions & 6 deletions src/frontend/packages/devkit/src/lib/stratos.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class StratosConfig implements Logger {
public nodeModulesFile: string;
public angularJsonFile: string;

public rootDir: string;

// angular.json contents
public angularJson: any;

Expand All @@ -44,6 +46,9 @@ export class StratosConfig implements Logger {
this.angularJson = JSON.parse(fs.readFileSync(this.angularJsonFile, 'utf8').toString());
this.loggingEnabled = loggingEnabled;

// Top-level folder
this.rootDir = path.dirname(this.angularJsonFile);

// The Stratos config file is optional - allows overriding default behaviour
this.stratosConfig = {};
if (this.angularJsonFile) {
Expand All @@ -65,22 +70,20 @@ export class StratosConfig implements Logger {
// Exclude the default packages... unless explicity `include`d
this.excludeExamples()

const mainDir = options ? path.dirname(options.main) : dir;

this.packageJsonFile = this.findFileOrFolderInChain(mainDir, 'package.json');
this.packageJsonFile = this.findFileOrFolderInChain(this.rootDir, 'package.json');
if (this.packageJsonFile !== null) {
this.packageJson = JSON.parse(fs.readFileSync(this.packageJsonFile, 'utf8').toString());
}

this.nodeModulesFile = this.findFileOrFolderInChain(mainDir, 'node_modules');
this.nodeModulesFile = this.findFileOrFolderInChain(this.rootDir, 'node_modules');

this.gitMetadata = new GitMetadata(path.dirname(this.angularJsonFile));
this.gitMetadata = new GitMetadata(this.rootDir);
// this.log(this.gitMetadata);
if (this.gitMetadata.exists) {
this.log('Read git metadata file');
}

this.newProjectRoot = this.angularJson.newProjectRoot;
this.newProjectRoot = path.join(this.rootDir, this.angularJson.newProjectRoot);

// Discover all packages

Expand Down