// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const fs = require('fs');
const path = require('path');
const CleanCSS = require('clean-css');
const [, , isDebugString, targetName, srcDir, targetGenDir, files] = process.argv;

const filenames = files.split(',');
const configFiles = [];
const cleanCSS = new CleanCSS();
const isDebug = isDebugString === 'true';

for (const fileName of filenames) {
  let output = fs.readFileSync(path.join(srcDir, fileName), {encoding: 'utf8', flag: 'r'});
  output = output.replace(/\`/g, '\\\'');

  fs.writeFileSync(
      path.join(targetGenDir, fileName + '.js'),
      `// Copyright ${new Date().getFullYear()} The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const styles = new CSSStyleSheet();
styles.replaceSync(
\`${isDebug ? output : cleanCSS.minify(output).styles}
/*# sourceURL=${fileName} */
\`);
export default styles;
`);

  configFiles.push(`\"${fileName}\"`);
}

fs.writeFileSync(path.join(targetGenDir, `${targetName}-tsconfig.json`), `{
    "compilerOptions": {
        "composite": true,
        "outDir": "."
    },
    "files": [
        ${configFiles.join(',\n        ')}
    ]
}
`);

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const fs = require('fs');
const path = require('path');
const CleanCSS = require('clean-css');
const [, , isDebugString, targetName, srcDir, targetGenDir, files] = process.argv;

const filenames = files.split(',');
const configFiles = [];
const cleanCSS = new CleanCSS();
const isDebug = isDebugString === 'true';

for (const fileName of filenames) {
  let output = fs.readFileSync(path.join(srcDir, fileName), {encoding: 'utf8', flag: 'r'});
  output = output.replace(/\`/g, '\\\'');

  fs.writeFileSync(
      path.join(targetGenDir, fileName + '.js'),
      `// Copyright ${new Date().getFullYear()} The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const styles = new CSSStyleSheet();
styles.replaceSync(
\`${isDebug ? output : cleanCSS.minify(output).styles}
/*# sourceURL=${fileName} */
\`);
export default styles;
`);

  configFiles.push(`\"${fileName}.js\"`);
}

fs.writeFileSync(path.join(targetGenDir, `${targetName}-tsconfig.json`), `{
    "compilerOptions": {
        "composite": true,
        "outDir": "."
    },
    "files": [
        ${configFiles.join(',\n        ')}
    ]
}
`);

Fix filename in generated tsconfig
Fix filename in generated tsconfig

The generated JavaScript file ends with `.js` and therefore we
should list the full name in our tsconfig as well. We ran into
compilation issues on https://crrev.com/c/3073941 and they required
the full extension to be listed. It's not clear to me why we
didn't run into this before, but it doesn't seem to break
any of the existing CSS file inclusions either.

R=993fcadce4d04090da2fefd557a0995e7966c8d5@chromium.org
CC=alexrudenko@chromium.org,kritisapra@google.com

Bug: 1106746
Change-Id: I45d593f4aee56b783349c82ea91cbde9b2db7d66
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3075188
Commit-Queue: Tim van der Lippe <dba8716ee7f8d16236046f74d2167cb94410f6ed@chromium.org>
Commit-Queue: Jack Franklin <993fcadce4d04090da2fefd557a0995e7966c8d5@chromium.org>
Auto-Submit: Tim van der Lippe <dba8716ee7f8d16236046f74d2167cb94410f6ed@chromium.org>
Reviewed-by: Jack Franklin <993fcadce4d04090da2fefd557a0995e7966c8d5@chromium.org>
