How to use the shelljs.sed function in shelljs

To help you get started, we’ve selected a few shelljs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github flow-typed / flow-typed / definitions / npm / shelljs_v0.7.x / test_shelljs_v0.7.x.js View on Github external
(sh.rm('/tmp/tmp0', '/tmp/tmp1'): ShellString);

// $ExpectError
sh.sed();
// $ExpectError
sh.sed(0);
// $ExpectError
sh.sed('foo');
// $ExpectError
sh.sed('foo', 'bar');
// $ExpectError
sh.sed({ '-x': true }, 'foo', 'bar', '/tmp/tmp0');
// Success
(sh.sed({ '-i': true }, 'foo', 'bar', '/tmp/tmp0'): ShellString);
// Success
(sh.sed('foo', 'bar', '/tmp/tmp0'): ShellString);
// Success
(sh.sed(/foo/, 'bar', '/tmp/tmp0'): ShellString);

// $ExpectError
sh.set();
// $ExpectError
sh.set(0);
// $ExpectError
sh.set('-x');
// Success
(sh.set('-e'): void);
// Success
(sh.set('+e'): void);

// $ExpectError
sh.sort();
github sourcegraph / sourcegraph-basic-code-intel / generator / src / main.ts View on Github external
console.log('Skipping', languageID)
            continue
        }
        console.log('Updating', languageID)

        // Delete everything but node_modules
        shell.exec(
            `find . -mindepth 1 -maxdepth 1 ! -name 'node_modules' -exec rm -rf '{}' ';'`
        )
        // Copy from ../template/ everything but node_modules
        shell.exec(
            `find ../template -mindepth 1 -maxdepth 1 ! -name 'node_modules' -exec cp -R '{}' . ';'`
        )

        shell.sed('-i', /LANGNAME\b/g, languageID, 'package.json')
        shell.sed('-i', /LANGID\b/g, sourcegraphID(languageID), 'package.json')
        shell.sed('-i', /LANG\b/g, stylized, 'package.json')
        shell.sed(
            '-i',
            /"name": ".*"/,
            `"name": "${languageID}"`,
            'package.json'
        )
        shell.sed(
            '-i',
            /"\*"/,
            `"onLanguage:${sourcegraphID(languageID)}"`,
            'package.json'
        )
        shell.sed(
            '-i',
            /"title": ".*"/,
github qualintitative / egoweb / app / node_modules / cordova-android / bin / lib / create.js View on Github external
shell.cp(path.join(project_template_dir, 'gitignore'), path.join(project_path, '.gitignore'));

            // Manually create directories that would be empty within the template (since git doesn't track directories).
            shell.mkdir(path.join(project_path, 'libs'));

            // copy cordova.js, cordova.jar
            copyJsAndLibrary(project_path, options.link, safe_activity_name);

            // interpolate the activity name and package
            var packagePath = package_name.replace(/\./g, path.sep);
            var activity_dir = path.join(project_path, 'src', packagePath);
            var activity_path = path.join(activity_dir, safe_activity_name + '.java');
            shell.mkdir('-p', activity_dir);
            shell.cp('-f', path.join(project_template_dir, 'Activity.java'), activity_path);
            shell.sed('-i', /__ACTIVITY__/, safe_activity_name, activity_path);
            shell.sed('-i', /__NAME__/, project_name, path.join(project_path, 'res', 'values', 'strings.xml'));
            shell.sed('-i', /__ID__/, package_name, activity_path);

            var manifest = new AndroidManifest(path.join(project_template_dir, 'AndroidManifest.xml'));
            manifest.setPackageId(package_name)
                .setTargetSdkVersion(target_api.split('-')[1])
                .getActivity().setName(safe_activity_name);

            var manifest_path = path.join(project_path, 'AndroidManifest.xml');
            manifest.write(manifest_path);

            copyScripts(project_path);
            copyBuildRules(project_path);
        });
        // Link it to local android install.
github apache / cordova-android / bin / templates / cordova / lib / builders / ProjectBuilder.js View on Github external
}).then(function () {
                // If the gradle distribution URL is set, make sure it points to version we want.
                // If it's not set, do nothing, assuming that we're using a future version of gradle that we don't want to mess with.
                // For some reason, using ^ and $ don't work.  This does the job, though.
                var distributionUrlRegex = /distributionUrl.*zip/;
                var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'https\\://services.gradle.org/distributions/gradle-4.10.3-all.zip';
                var gradleWrapperPropertiesPath = path.join(self.root, 'gradle', 'wrapper', 'gradle-wrapper.properties');
                shell.chmod('u+w', gradleWrapperPropertiesPath);
                shell.sed('-i', distributionUrlRegex, 'distributionUrl=' + distributionUrl, gradleWrapperPropertiesPath);

                var propertiesFile = opts.buildType + SIGNING_PROPERTIES;
                var propertiesFilePath = path.join(self.root, propertiesFile);
                if (opts.packageInfo) {
                    fs.writeFileSync(propertiesFilePath, TEMPLATE + opts.packageInfo.toProperties());
                } else if (isAutoGenerated(propertiesFilePath)) {
                    shell.rm('-f', propertiesFilePath);
                }
            });
    }
github apigee / api-platform-samples / sample-proxies / oauth-advanced / app / index.js View on Github external
install: function(){

    // configure login-app and provisioning
    shell.sed('-i','ENVNAME', this.envname, 'login-app/apiproxy/resources/node/config/config.js');
    shell.sed('-i','ORGNAME', this.orgname, 'login-app/apiproxy/resources/node/config/config.js');

    shell.sed('-i','CALLBACKURL', this.callbackurl, 'provisioning/webserver-app.xml');

    // deploy user-mgmt-v1
    shell.cd('user-mgmt-v1');
	shell.exec('apigeetool deployproxy -u '+this.uname+' -p \''+this.password+'\' -o '+this.orgname+' -e '+this.envname+ ' -n user-mgmt-v1 -d .');

    // deploy oauth2
    shell.cd('../oauth2');
    shell.exec('apigeetool deployproxy -u '+this.uname+' -p \''+this.password+'\' -o '+this.orgname+' -e '+this.envname+ ' -n oauth2 -d .');

    // provision login-app
    shell.cd('../provisioning');
    shell.exec('./provision-login-app.sh '+this.uname+' \''+this.password+'\' '+this.orgname+' '+this.envname+' '+this.mgmtapiurl);
github imaxue / progress / liao / 创建项目脚本.js View on Github external
async function creatRouter(name) {
  let { routerPath } = await creatRouterPath();
  let { routerName } = await creatRouterName();
  // let routerPath = name.toLocaleLowerCase()
  let routerTemp = `{
			path: BathHost + '/${routerPath}',
			component: () => import('@/pages/${name}'),
			meta: {
				title: '${routerName}'
			},
		},
		// replace此行为自动创建脚本替换用,请不要随意做改动`;

  shell.sed(
    "-i",
    /\/\/ replace此行为自动创建脚本替换用,请不要随意做改动/,
    routerTemp,
    "./src/router/index.js"
  );
}
// 创建路由地址
github pixelcollective / gardener / gardener.js View on Github external
function configureStaging() {
  console.log(pad(colors.blue('Configuring Staging')));
  var code = false;

  if(shell.rm(site.trellis +'/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/wordpress_sites.staging.yml', site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ GITHUB_USER }}', github_username, site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_URL }}',    site.url,        site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_DOMAIN }}', domain,          site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_TLD }}',    tld,             site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;

  if(shell.rm(site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/vault.staging.yml', site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;

  if(shell.sed('-i', '{{ SITE_URL }}',        site.url,                            site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ MYSQL_ROOT_PASS }}', shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ VAULT_PASS }}',      shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ VAULT_SALT }}',      '"' + shell.exec('pwgen -Bs 20 1').stdout + '"', site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ DB_PASSWORD }}',     shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;

  if(shell.rm(site.trellis + '/group_vars/staging/main.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/main.staging.yml', site.trellis + '/group_vars/staging/main.yml').code !== 0) code = true;

  return code;
}
github pixelcollective / gardener / gardener.js View on Github external
function configureStaging() {
  console.log(pad(colors.blue('Configuring Staging')));
  var code = false;

  if(shell.rm(site.trellis +'/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/wordpress_sites.staging.yml', site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ GITHUB_USER }}', github_username, site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_URL }}',    site.url,        site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_DOMAIN }}', domain,          site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ SITE_TLD }}',    tld,             site.trellis + '/group_vars/staging/wordpress_sites.yml').code !== 0) code = true;

  if(shell.rm(site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/vault.staging.yml', site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;

  if(shell.sed('-i', '{{ SITE_URL }}',        site.url,                            site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ MYSQL_ROOT_PASS }}', shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ VAULT_PASS }}',      shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ VAULT_SALT }}',      '"' + shell.exec('pwgen -Bs 20 1').stdout + '"', site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;
  if(shell.sed('-i', '{{ DB_PASSWORD }}',     shell.exec('pwgen -Bs 20 1').stdout, site.trellis + '/group_vars/staging/vault.yml').code !== 0) code = true;

  if(shell.rm(site.trellis + '/group_vars/staging/main.yml').code !== 0) code = true;
  if(shell.cp(gardener +'/configs/trellis/main.staging.yml', site.trellis + '/group_vars/staging/main.yml').code !== 0) code = true;

  return code;
}
github vuegg / vuegg / server / api / generator / project / refactor.js View on Github external
if (typeof packImport === 'string') {
        if (packImport.indexOf('//') !== -1){
          packImport.indexOf('css')
            ? indexStyleImports += '\n' + S(' ').times(4).s + ''
            : indexScriptImports += '\n' + S(' ').times(4).s + ''
        } else {
          packagesImports += "import '" + packImport + "'\n"
        }
      } else {
        packagesImports += "import " + packImport[0] + " from '" + packImport[1] + "'\n"
        packagesUse += "Vue.use(" + packImport[0] + ")\n"
      }
    }
  }

  shell.sed('-i', '{{STYLE_IMPORTS}}', indexStyleImports, indexFile)
  shell.sed('-i', '{{SCRIPT_IMPORTS}}', indexScriptImports, indexFile)
  shell.sed('-i', '{{DEPENDENCIES}}', dependencies, packageFile)
  shell.sed('-i', '{{PACKAGES_IMPORTS}}', packagesImports, mainFile)
  shell.sed('-i', '{{PACKAGES_USE}}', packagesUse, mainFile)

  try {
    await shell.rm('-rf', path.resolve(targetDir, '.git'))
  } catch (e) {
    log.error('\n > Could not remove ' + path.resolve(targetDir, '.git'))
  }

  try {
    await shell.rm('-rf', path.resolve(targetDir,'templates'))
  } catch (e) {
    log.error('\n > Could not remove ' + path.resolve(targetDir,'templates'))
  }
github sourcegraph / sourcegraph-basic-code-intel / generator / src / main.ts View on Github external
`"onLanguage:${sourcegraphID(languageID)}"`,
            'package.json'
        )
        shell.sed(
            '-i',
            /"title": ".*"/,
            `"title": "${stylized} code intelligence"`,
            'package.json'
        )
        shell.sed(
            '-i',
            /^  "description": ".*"/,
            `"description": "Provides basic code intelligence for ${stylized} using the Sourcegraph search API"`,
            'package.json'
        )
        shell.sed(
            '-i',
            /"Results come from text search and heuristics.*"/,
            `"Results come from text search and heuristics."`,
            'package.json'
        )
        shell.sed('-i', /LANGNAME\b/g, languageID, 'README.md')
        shell.sed('-i', /LANG\b/g, stylized, 'README.md')

        shell.sed(
            '-i',
            /const languageID = 'all'/,
            `const languageID = '${languageID}'`,
            'src/extension.ts'
        )

        const pkg = JSON.parse(fs.readFileSync('package.json').toString())