const path = require('path');
const fs = require('fs');

/**
 * inject the registry to be included
 * @param entry
 * @returns {*}
 */
function injectRegistry(defaultApp, extraFiles, entry) {
  // build also the registry
  if (typeof entry === 'string') {
      return extraFiles.concat(entry);
  }
  const transformed = {};
  Object.keys(entry).forEach((key) => {
      transformed[key] = extraFiles.concat(`./${defaultApp}/` + entry[key]['js']);
  });
  return transformed;
}

function resolveScreenshot(appDirectory) {
  const f = path.join(appDirectory, './media/screenshot.png');
  if (!fs.existsSync(f)) {
    return null;
  }
  const buffer = Buffer.from(fs.readFileSync(f)).toString('base64');
  return `data:image/png;base64,${buffer}`;
}

function generateMetaDataFile(appDirectory, customProperties) {
  const pkg = require(path.join(appDirectory,'./package.json'));
  const manifest = Object.assign({
    name: pkg.name,
    displayName: pkg.displayName,
    version: pkg.version,
    repository: pkg.repository.url,
    homepage: pkg.homepage,
    description: pkg.description,
    screenshot: resolveScreenshot(appDirectory)
  }, customProperties);
  return JSON.stringify(manifest, null, 2);
}

module.exports = {
  generateMetaDataFile,
  injectRegistry
};

const path = require('path');
const fs = require('fs');

/**
 * inject the registry to be included
 * @param entry
 * @returns {*}
 */
function injectRegistry(defaultApp, extraFiles, entry) {
  // build also the registry
  if (typeof entry === 'string') {
      return extraFiles.concat(entry);
  }
  const transformed = {};
  Object.keys(entry).forEach((key) => {
    const workspacePath = path.join(__dirname, `..`);
    const defaultAppPath = path.join(workspacePath, defaultApp);
    const workspaceSCSS = entry[key]['scss'] ? path.join(defaultAppPath, entry[key]['scss']) : path.join(workspacePath, `workspace.scss`);
    const entryJS = path.join(defaultAppPath, entry[key]['js']);
    
    transformed[key] = extraFiles.concat(workspaceSCSS, entryJS);
  });
  return transformed;
}

function resolveScreenshot(appDirectory) {
  const f = path.join(appDirectory, './media/screenshot.png');
  if (!fs.existsSync(f)) {
    return null;
  }
  const buffer = Buffer.from(fs.readFileSync(f)).toString('base64');
  return `data:image/png;base64,${buffer}`;
}

function generateMetaDataFile(appDirectory, customProperties) {
  const pkg = require(path.join(appDirectory,'./package.json'));
  const manifest = Object.assign({
    name: pkg.name,
    displayName: pkg.displayName,
    version: pkg.version,
    repository: pkg.repository.url,
    homepage: pkg.homepage,
    description: pkg.description,
    screenshot: resolveScreenshot(appDirectory)
  }, customProperties);
  return JSON.stringify(manifest, null, 2);
}

module.exports = {
  generateMetaDataFile,
  injectRegistry
};

Add SCSS file per Webpack entry point
Add SCSS file per Webpack entry point

#450

The `scss` path can be added to the entry point configuration in the app's .yo-rc.json, e.g.:

```json
"entries": {
  "app": {
    "scss": "../workspace_custom.scss",
    "js": "dist/initialize.js",
    "template": "dist/index.template.ejs",
    "html": "index.html",
    "chunkName": "app"
  },
}
```

Note that the path is relative to the default app directory. If no path is set for `scss` the default `workspace.scss` in the workspace directory is used.