#!/usr/bin/env node
/*
 * Copyright 2018 The Closure Compiler Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/**
 * @fileoverview Create a nightly version of the package to publish to npm.
 * The compiler in this version will be a snapshot version.
 */

const {spawnSync} = require('child_process');

const today = new Date();
const month = (today.getMonth() < 9 ? '0' : '') + (today.getMonth() + 1).toString();
const day = (today.getDate() < 10 ? '0' : '') + today.getDate().toString();

// Version number is today's date with a -nightly prerelease suffix.
const nightlyVersion = `${today.getFullYear()}${month}${day}.0.0-nightly`;

// Lerna won't release packages on an already release tagged commit.
// Create a new empty commit for this nightly release.
spawnSync(
    'git',
    [
      'commit',
      '--allow-empty',
      '-m',
      `Create version for nightly release ${nightlyVersion}`
    ],
    {
      stdio: 'inherit',
    });

const glob = require('glob');

// Get the list of packages in this repo
const packages = glob.sync('packages/google-closure-compiler*')
    .map(packagePath => packagePath.replace('packages/', ''));

// Create a nightly version of all the packages
spawnSync(
    'node_modules/.bin/lerna',
    [
      'version',
      nightlyVersion,
      '--push=false', // prevent the version commit from being pushed back to the repo
      `--force-publish=${packages.join(',')}`, // publish every package even though no changes are detected
      '--yes', // don't prompt for confirmation
    ],
    {
      stdio: 'inherit',
    });

@@ -817,16 +817,46 @@
 ocess');
+%0Aconst glob = require('glob');
 %0A%0Aconst 
@@ -1253,64 +1253,238 @@
 mmit
-.
+ or
 %0A// 
-Create a new empty commit for this nightly release.
+on a disconnected HEAD. Create a branch then an empty commit for this nightly release.%0AspawnSync(%0A    'git',%0A    %5B%0A      'checkout',%0A      '-b',%0A      %60publish-$%7BnightlyVersion%7D%60%0A    %5D,%0A    %7B%0A      stdio: 'inherit',%0A    %7D);
 %0Aspa
@@ -1649,32 +1649,32 @@
 dio: 'inherit',%0A
+
     %7D);%0A%0Aconst g
@@ -1670,39 +1670,8 @@
 );%0A%0A
-const glob = require('glob');%0A%0A
 // G

Create a branch for the nightly release.